]> 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:24:50 +0000 (00:24 +0200)
(cherry-picked from 04a29696e5b176ac66401120e433d52425222f0f)

Refs gh-2301

src/event.js

index 843ea4b77e5e69efddda7e56c6a4dcc54df38550..b17d8c54a92b59ef72f7bf90895f79e81fe125c9 100644 (file)
@@ -32,6 +32,58 @@ function safeActiveElement() {
        } catch ( err ) { }
 }
 
+function on( elem, types, selector, data, fn, one ) {
+       var type, origFn;
+
+       // 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.
@@ -985,59 +1037,11 @@ if ( !support.focusin ) {
 
 jQuery.fn.extend({
 
-       on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
-               var type, origFn;
-
-               // 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;