mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Remove an internal argument to the on method
(cherry-picked from 04a29696e5
)
Refs gh-2301
This commit is contained in:
parent
2fa3bac7eb
commit
473d2db9fd
106
src/event.js
106
src/event.js
@ -32,6 +32,58 @@ function safeActiveElement() {
|
|||||||
} catch ( err ) { }
|
} 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.
|
* Helper functions for managing events -- not part of the public interface.
|
||||||
* Props to Dean Edwards' addEvent library for many of the ideas.
|
* Props to Dean Edwards' addEvent library for many of the ideas.
|
||||||
@ -985,59 +1037,11 @@ if ( !support.focusin ) {
|
|||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
|
|
||||||
on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
|
on: function( types, selector, data, fn ) {
|
||||||
var type, origFn;
|
return on( this, types, selector, data, fn );
|
||||||
|
|
||||||
// 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 );
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
one: function( 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 ) {
|
off: function( types, selector, fn ) {
|
||||||
var handleObj, type;
|
var handleObj, type;
|
||||||
|
Loading…
Reference in New Issue
Block a user