From: jeresig Date: Sat, 27 Feb 2010 14:02:18 +0000 (-0500) Subject: Merge branch 'master' of github.com:jquery/jquery X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=42568db4c414d4435f2f7e89be87d66645c42e1c;hp=7d5da0ee030b1962ff1ff57b0221a02dfdc2886a;p=jquery.git Merge branch 'master' of github.com:jquery/jquery --- diff --git a/src/ajax.js b/src/ajax.js index 7b15a1d..08fa08b 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -13,8 +13,8 @@ var jsc = now(), jQuery.fn.extend({ load: function( url, params, callback ) { - if ( typeof url !== "string" ) { - return _load.call( this, url ); + if ( typeof url !== "string" && _load ) { + return _load.apply( this, arguments ); // Don't do a request if no elements are being requested } else if ( !this.length ) { diff --git a/src/event.js b/src/event.js index 5369b85..42655c9 100644 --- a/src/event.js +++ b/src/event.js @@ -25,6 +25,10 @@ jQuery.event = { elem = window; } + if ( handler === false ) { + handler = returnFalse; + } + var handleObjIn, handleObj; if ( handler.handler ) { @@ -138,6 +142,10 @@ jQuery.event = { return; } + if ( handler === false ) { + handler = returnFalse; + } + var ret, type, fn, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType, elemData = jQuery.data( elem ), events = elemData && elemData.events; @@ -831,7 +839,7 @@ jQuery.each(["bind", "one"], function( i, name ) { return this; } - if ( jQuery.isFunction( data ) ) { + if ( jQuery.isFunction( data ) || data === false ) { fn = data; data = undefined; } @@ -1072,8 +1080,15 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl "change select submit keydown keypress keyup error").split(" "), function( i, name ) { // Handle event binding - jQuery.fn[ name ] = function( fn ) { - return fn ? this.bind( name, fn ) : this.trigger( name ); + jQuery.fn[ name ] = function( data, fn ) { + if ( fn == undefined ) { + fn = data; + data = null; + } + + return arguments.length > 0 ? + this.bind( name, data, fn ) : + this.trigger( name ); }; if ( jQuery.attrFn ) { diff --git a/test/unit/event.js b/test/unit/event.js index a220ebf..a9c8815 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -11,6 +11,17 @@ test("bind(), with data", function() { ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); }); +test("click(), with data", function() { + expect(3); + var handler = function(event) { + ok( event.data, "bind() with data, check passed data exists" ); + equals( event.data.foo, "bar", "bind() with data, Check value of passed data" ); + }; + jQuery("#firstp").click({foo: "bar"}, handler).click().unbind("click", handler); + + ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); +}); + test("bind(), with data, trigger with data", function() { expect(4); var handler = function(event, data) { @@ -373,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." ); }); +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() { expect( 2 );