Skip to content

Commit 473d2db

Browse files
committed
Event: Remove an internal argument to the on method
(cherry-picked from 04a2969) Refs gh-2301
1 parent 2fa3bac commit 473d2db

File tree

1 file changed

+55
-51
lines changed

1 file changed

+55
-51
lines changed

src/event.js

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,58 @@ function safeActiveElement() {
3232
} catch ( err ) { }
3333
}
3434

35+
function on( elem, types, selector, data, fn, one ) {
36+
var type, origFn;
37+
38+
// Types can be a map of types/handlers
39+
if ( typeof types === "object" ) {
40+
// ( types-Object, selector, data )
41+
if ( typeof selector !== "string" ) {
42+
// ( types-Object, data )
43+
data = data || selector;
44+
selector = undefined;
45+
}
46+
for ( type in types ) {
47+
on( elem, type, selector, data, types[ type ], one );
48+
}
49+
return elem;
50+
}
51+
52+
if ( data == null && fn == null ) {
53+
// ( types, fn )
54+
fn = selector;
55+
data = selector = undefined;
56+
} else if ( fn == null ) {
57+
if ( typeof selector === "string" ) {
58+
// ( types, selector, fn )
59+
fn = data;
60+
data = undefined;
61+
} else {
62+
// ( types, data, fn )
63+
fn = data;
64+
data = selector;
65+
selector = undefined;
66+
}
67+
}
68+
if ( fn === false ) {
69+
fn = returnFalse;
70+
}
71+
72+
if ( one === 1 ) {
73+
origFn = fn;
74+
fn = function( event ) {
75+
// Can use an empty set, since event contains the info
76+
jQuery().off( event );
77+
return origFn.apply( this, arguments );
78+
};
79+
// Use same guid so caller can remove using origFn
80+
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
81+
}
82+
return elem.each( function() {
83+
jQuery.event.add( this, types, fn, data, selector );
84+
});
85+
}
86+
3587
/*
3688
* Helper functions for managing events -- not part of the public interface.
3789
* Props to Dean Edwards' addEvent library for many of the ideas.
@@ -985,59 +1037,11 @@ if ( !support.focusin ) {
9851037

9861038
jQuery.fn.extend({
9871039

988-
on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
989-
var type, origFn;
990-
991-
// Types can be a map of types/handlers
992-
if ( typeof types === "object" ) {
993-
// ( types-Object, selector, data )
994-
if ( typeof selector !== "string" ) {
995-
// ( types-Object, data )
996-
data = data || selector;
997-
selector = undefined;
998-
}
999-
for ( type in types ) {
1000-
this.on( type, selector, data, types[ type ], one );
1001-
}
1002-
return this;
1003-
}
1004-
1005-
if ( data == null && fn == null ) {
1006-
// ( types, fn )
1007-
fn = selector;
1008-
data = selector = undefined;
1009-
} else if ( fn == null ) {
1010-
if ( typeof selector === "string" ) {
1011-
// ( types, selector, fn )
1012-
fn = data;
1013-
data = undefined;
1014-
} else {
1015-
// ( types, data, fn )
1016-
fn = data;
1017-
data = selector;
1018-
selector = undefined;
1019-
}
1020-
}
1021-
if ( fn === false ) {
1022-
fn = returnFalse;
1023-
}
1024-
1025-
if ( one === 1 ) {
1026-
origFn = fn;
1027-
fn = function( event ) {
1028-
// Can use an empty set, since event contains the info
1029-
jQuery().off( event );
1030-
return origFn.apply( this, arguments );
1031-
};
1032-
// Use same guid so caller can remove using origFn
1033-
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
1034-
}
1035-
return this.each( function() {
1036-
jQuery.event.add( this, types, fn, data, selector );
1037-
});
1040+
on: function( types, selector, data, fn ) {
1041+
return on( this, types, selector, data, fn );
10381042
},
10391043
one: function( types, selector, data, fn ) {
1040-
return this.on( types, selector, data, fn, 1 );
1044+
return on( this, types, selector, data, fn, 1 );
10411045
},
10421046
off: function( types, selector, fn ) {
10431047
var handleObj, type;

0 commit comments

Comments
 (0)