32
32
* - [after()](http://api.jquery.com/after/)
33
33
* - [append()](http://api.jquery.com/append/)
34
34
* - [attr()](http://api.jquery.com/attr/)
35
- * - [bind()](http://api.jquery.com/bind /) - Does not support namespaces
35
+ * - [bind()](http://api.jquery.com/on /) - Does not support namespaces, selectors or eventData
36
36
* - [children()](http://api.jquery.com/children/) - Does not support selectors
37
37
* - [clone()](http://api.jquery.com/clone/)
38
38
* - [contents()](http://api.jquery.com/contents/)
43
43
* - [hasClass()](http://api.jquery.com/hasClass/)
44
44
* - [html()](http://api.jquery.com/html/)
45
45
* - [next()](http://api.jquery.com/next/) - Does not support selectors
46
+ * - [on()](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
47
+ * - [off()](http://api.jquery.com/off/) - Does not support namespaces or selectors
46
48
* - [parent()](http://api.jquery.com/parent/) - Does not support selectors
47
49
* - [prepend()](http://api.jquery.com/prepend/)
48
50
* - [prop()](http://api.jquery.com/prop/)
55
57
* - [text()](http://api.jquery.com/text/)
56
58
* - [toggleClass()](http://api.jquery.com/toggleClass/)
57
59
* - [triggerHandler()](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers.
58
- * - [unbind()](http://api.jquery.com/unbind /) - Does not support namespaces
60
+ * - [unbind()](http://api.jquery.com/off /) - Does not support namespaces
59
61
* - [val()](http://api.jquery.com/val/)
60
62
* - [wrap()](http://api.jquery.com/wrap/)
61
63
*
@@ -90,6 +92,7 @@ function jqNextId() { return ++jqId; }
90
92
91
93
var SPECIAL_CHARS_REGEXP = / ( [ \: \- \_ ] + ( .) ) / g;
92
94
var MOZ_HACK_REGEXP = / ^ m o z ( [ A - Z ] ) / ;
95
+ var jqLiteError = minErr ( 'jqLite' ) ;
93
96
94
97
/**
95
98
* Converts snake_case to camelCase.
@@ -153,7 +156,7 @@ function JQLite(element) {
153
156
}
154
157
if ( ! ( this instanceof JQLite ) ) {
155
158
if ( isString ( element ) && element . charAt ( 0 ) != '<' ) {
156
- throw minErr ( 'jqLite' ) ( 'nosel' , 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element' ) ;
159
+ throw jqLiteError ( 'nosel' , 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element' ) ;
157
160
}
158
161
return new JQLite ( element ) ;
159
162
}
@@ -183,7 +186,9 @@ function JQLiteDealoc(element){
183
186
}
184
187
}
185
188
186
- function JQLiteUnbind ( element , type , fn ) {
189
+ function JQLiteOff ( element , type , fn ) {
190
+ if ( arguments . length > 4 ) throw jqLiteError ( 'off_args' , 'jqLite#off() does not support the `selector` parameter' ) ;
191
+
187
192
var events = JQLiteExpandoStore ( element , 'events' ) ,
188
193
handle = JQLiteExpandoStore ( element , 'handle' ) ;
189
194
@@ -216,7 +221,7 @@ function JQLiteRemoveData(element, name) {
216
221
217
222
if ( expandoStore . handle ) {
218
223
expandoStore . events . $destroy && expandoStore . handle ( { } , '$destroy' ) ;
219
- JQLiteUnbind ( element ) ;
224
+ JQLiteOff ( element ) ;
220
225
}
221
226
delete jqCache [ expandoId ] ;
222
227
element [ jqName ] = undefined ; // ie does not allow deletion of attributes on elements.
@@ -338,9 +343,9 @@ var JQLitePrototype = JQLite.prototype = {
338
343
if ( document . readyState === 'complete' ) {
339
344
setTimeout ( trigger ) ;
340
345
} else {
341
- this . bind ( 'DOMContentLoaded' , trigger ) ; // works for modern browsers and IE9
346
+ this . on ( 'DOMContentLoaded' , trigger ) ; // works for modern browsers and IE9
342
347
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
343
- JQLite ( window ) . bind ( 'load' , trigger ) ; // fallback to window.onload for others
348
+ JQLite ( window ) . on ( 'load' , trigger ) ; // fallback to window.onload for others
344
349
}
345
350
} ,
346
351
toString : function ( ) {
@@ -609,7 +614,9 @@ forEach({
609
614
610
615
dealoc : JQLiteDealoc ,
611
616
612
- bind : function bindFn ( element , type , fn ) {
617
+ on : function onFn ( element , type , fn , other1 ) {
618
+ if ( isDefined ( other1 ) ) throw jqLiteError ( 'on_args' , 'jqLite#on() does not support the `selector` or `eventData` parameters' ) ;
619
+
613
620
var events = JQLiteExpandoStore ( element , 'events' ) ,
614
621
handle = JQLiteExpandoStore ( element , 'handle' ) ;
615
622
@@ -649,8 +656,8 @@ forEach({
649
656
// http://www.quirksmode.org/js/events_mouse.html#link8
650
657
var eventmap = { mouseleave : "mouseout" , mouseenter : "mouseover" } ;
651
658
652
- bindFn ( element , eventmap [ type ] , function ( event ) {
653
- var ret , target = this , related = event . relatedTarget ;
659
+ onFn ( element , eventmap [ type ] , function ( event ) {
660
+ var target = this , related = event . relatedTarget ;
654
661
// For mousenter/leave call the handler if related is outside the target.
655
662
// NB: No relatedTarget if the mouse left/entered the browser window
656
663
if ( ! related || ( related !== target && ! contains ( target , related ) ) ) {
@@ -668,7 +675,7 @@ forEach({
668
675
} ) ;
669
676
} ,
670
677
671
- unbind : JQLiteUnbind ,
678
+ off : JQLiteOff ,
672
679
673
680
replaceWith : function ( element , replaceNode ) {
674
681
var index , parent = element . parentNode ;
@@ -790,19 +797,23 @@ forEach({
790
797
/**
791
798
* chaining functions
792
799
*/
793
- JQLite . prototype [ name ] = function ( arg1 , arg2 ) {
800
+ JQLite . prototype [ name ] = function ( arg1 , arg2 , arg3 ) {
794
801
var value ;
795
802
for ( var i = 0 ; i < this . length ; i ++ ) {
796
803
if ( value == undefined ) {
797
- value = fn ( this [ i ] , arg1 , arg2 ) ;
804
+ value = fn ( this [ i ] , arg1 , arg2 , arg3 ) ;
798
805
if ( value !== undefined ) {
799
806
// any function which returns a value needs to be wrapped
800
807
value = jqLite ( value ) ;
801
808
}
802
809
} else {
803
- JQLiteAddNodes ( value , fn ( this [ i ] , arg1 , arg2 ) ) ;
810
+ JQLiteAddNodes ( value , fn ( this [ i ] , arg1 , arg2 , arg3 ) ) ;
804
811
}
805
812
}
806
813
return value == undefined ? this : value ;
807
814
} ;
815
+
816
+ // bind legacy bind/unbind to on/off
817
+ JQLite . prototype . bind = JQLite . prototype . on ;
818
+ JQLite . prototype . unbind = JQLite . prototype . off ;
808
819
} ) ;
0 commit comments