Adding in .bind(name, false), .unbind(name, false) support - an easy way to just stop bubbling and the default action on an element. Fixes #6188.
This commit is contained in:
parent
ba7195e3f9
commit
a45372a4c5
3 changed files with 37 additions and 5 deletions
|
@ -13,8 +13,8 @@ var jsc = now(),
|
||||||
|
|
||||||
jQuery.fn.extend({
|
jQuery.fn.extend({
|
||||||
load: function( url, params, callback ) {
|
load: function( url, params, callback ) {
|
||||||
if ( typeof url !== "string" ) {
|
if ( typeof url !== "string" && _load ) {
|
||||||
return _load.call( this, url );
|
return _load.apply( this, arguments );
|
||||||
|
|
||||||
// Don't do a request if no elements are being requested
|
// Don't do a request if no elements are being requested
|
||||||
} else if ( !this.length ) {
|
} else if ( !this.length ) {
|
||||||
|
|
19
src/event.js
19
src/event.js
|
@ -25,6 +25,10 @@ jQuery.event = {
|
||||||
elem = window;
|
elem = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( handler === false ) {
|
||||||
|
handler = returnFalse;
|
||||||
|
}
|
||||||
|
|
||||||
var handleObjIn, handleObj;
|
var handleObjIn, handleObj;
|
||||||
|
|
||||||
if ( handler.handler ) {
|
if ( handler.handler ) {
|
||||||
|
@ -138,6 +142,10 @@ jQuery.event = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( handler === false ) {
|
||||||
|
handler = returnFalse;
|
||||||
|
}
|
||||||
|
|
||||||
var ret, type, fn, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
|
var ret, type, fn, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
|
||||||
elemData = jQuery.data( elem ),
|
elemData = jQuery.data( elem ),
|
||||||
events = elemData && elemData.events;
|
events = elemData && elemData.events;
|
||||||
|
@ -830,7 +838,7 @@ jQuery.each(["bind", "one"], function( i, name ) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( jQuery.isFunction( data ) ) {
|
if ( jQuery.isFunction( data ) || data === false ) {
|
||||||
fn = data;
|
fn = data;
|
||||||
data = undefined;
|
data = undefined;
|
||||||
}
|
}
|
||||||
|
@ -1072,8 +1080,13 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
|
||||||
|
|
||||||
// Handle event binding
|
// Handle event binding
|
||||||
jQuery.fn[ name ] = function( data, fn ) {
|
jQuery.fn[ name ] = function( data, fn ) {
|
||||||
return data || fn ?
|
if ( fn == undefined ) {
|
||||||
this.bind( name, fn ? data : null, fn || data ) :
|
fn = data;
|
||||||
|
data = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return arguments.length > 0 ?
|
||||||
|
this.bind( name, data, fn ) :
|
||||||
this.trigger( name );
|
this.trigger( name );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -384,6 +384,25 @@ test("bind(), with different this object", function() {
|
||||||
ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
|
ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("bind(name, false), unbind(name, false)", function() {
|
||||||
|
expect(3);
|
||||||
|
|
||||||
|
var main = 0;
|
||||||
|
jQuery("#main").bind("click", function(e){ main++; });
|
||||||
|
jQuery("#ap").trigger("click");
|
||||||
|
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||||
|
|
||||||
|
main = 0;
|
||||||
|
jQuery("#ap").bind("click", false);
|
||||||
|
jQuery("#ap").trigger("click");
|
||||||
|
equals( main, 0, "Verify that no bubble happened." );
|
||||||
|
|
||||||
|
main = 0;
|
||||||
|
jQuery("#ap").unbind("click", false);
|
||||||
|
jQuery("#ap").trigger("click");
|
||||||
|
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||||
|
});
|
||||||
|
|
||||||
test("bind()/trigger()/unbind() on plain object", function() {
|
test("bind()/trigger()/unbind() on plain object", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue