]> source.dussan.org Git - jquery.git/commitdiff
Event: Remove an internal argument to the on method
authorMichał Gołębiowski <m.goleb@gmail.com>
Mon, 1 Jun 2015 19:34:57 +0000 (21:34 +0200)
committerMichał Gołębiowski <m.goleb@gmail.com>
Sat, 13 Jun 2015 22:06:51 +0000 (00:06 +0200)
Refs gh-2301

src/event.js

index 1e954513abf9b42940bbed8e7936427afc4b85eb..04ee403d5d8e52958432ebe217edf7204dc109f4 100644 (file)
@@ -34,6 +34,58 @@ function safeActiveElement() {
        } catch ( err ) { }
 }
 
+function on( elem, types, selector, data, fn, one ) {
+       var origFn, type;
+
+       // Types can be a map of types/handlers
+       if ( typeof types === "object" ) {
+               // ( types-Object, selector, data )
+               if ( typeof selector !== "string" ) {
+                       // ( types-Object, data )
+                       data = data || selector;
+                       selector = undefined;
+               }
+               for ( type in types ) {
+                       on( elem, type, selector, data, types[ type ], one );
+               }
+               return elem;
+       }
+
+       if ( data == null && fn == null ) {
+               // ( types, fn )
+               fn = selector;
+               data = selector = undefined;
+       } else if ( fn == null ) {
+               if ( typeof selector === "string" ) {
+                       // ( types, selector, fn )
+                       fn = data;
+                       data = undefined;
+               } else {
+                       // ( types, data, fn )
+                       fn = data;
+                       data = selector;
+                       selector = undefined;
+               }
+       }
+       if ( fn === false ) {
+               fn = returnFalse;
+       }
+
+       if ( one === 1 ) {
+               origFn = fn;
+               fn = function( event ) {
+                       // Can use an empty set, since event contains the info
+                       jQuery().off( event );
+                       return origFn.apply( this, arguments );
+               };
+               // Use same guid so caller can remove using origFn
+               fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
+       }
+       return elem.each( function() {
+               jQuery.event.add( this, types, fn, data, selector );
+       });
+}
+
 /*
  * Helper functions for managing events -- not part of the public interface.
  * Props to Dean Edwards' addEvent library for many of the ideas.
@@ -799,59 +851,11 @@ if ( !support.focusin ) {
 
 jQuery.fn.extend({
 
-       on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
-               var origFn, type;
-
-               // Types can be a map of types/handlers
-               if ( typeof types === "object" ) {
-                       // ( types-Object, selector, data )
-                       if ( typeof selector !== "string" ) {
-                               // ( types-Object, data )
-                               data = data || selector;
-                               selector = undefined;
-                       }
-                       for ( type in types ) {
-                               this.on( type, selector, data, types[ type ], one );
-                       }
-                       return this;
-               }
-
-               if ( data == null && fn == null ) {
-                       // ( types, fn )
-                       fn = selector;
-                       data = selector = undefined;
-               } else if ( fn == null ) {
-                       if ( typeof selector === "string" ) {
-                               // ( types, selector, fn )
-                               fn = data;
-                               data = undefined;
-                       } else {
-                               // ( types, data, fn )
-                               fn = data;
-                               data = selector;
-                               selector = undefined;
-                       }
-               }
-               if ( fn === false ) {
-                       fn = returnFalse;
-               }
-
-               if ( one === 1 ) {
-                       origFn = fn;
-                       fn = function( event ) {
-                               // Can use an empty set, since event contains the info
-                               jQuery().off( event );
-                               return origFn.apply( this, arguments );
-                       };
-                       // Use same guid so caller can remove using origFn
-                       fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
-               }
-               return this.each( function() {
-                       jQuery.event.add( this, types, fn, data, selector );
-               });
+       on: function( types, selector, data, fn ) {
+               return on( this, types, selector, data, fn );
        },
        one: function( types, selector, data, fn ) {
-               return this.on( types, selector, data, fn, 1 );
+               return on( this, types, selector, data, fn, 1 );
        },
        off: function( types, selector, fn ) {
                var handleObj, type;