From: John Resig Date: Mon, 25 Oct 2010 20:06:23 +0000 (-0700) Subject: Merge branch '6897' of http://github.com/SlexAxton/jquery into SlexAxton-6897 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=7e4f88e20639ee7b4c360b0b4636ece0c0984bd2;hp=086822e6419c89c33b322bacbbc891148a4b3647;p=jquery.git Merge branch '6897' of github.com/SlexAxton/jquery into SlexAxton-6897 --- diff --git a/src/ajax.js b/src/ajax.js index a40e223..6a757eb 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -4,7 +4,7 @@ var jsc = jQuery.now(), rscript = /)<[^<]*)*<\/script>/gi, rselectTextarea = /^(?:select|textarea)/i, rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, - rnoContent = /^(?:GET|HEAD|DELETE)$/, + rnoContent = /^(?:GET|HEAD)$/, rbracket = /\[\]$/, jsre = /\=\?(&|$)/, rquery = /\?/, @@ -208,6 +208,12 @@ jQuery.extend({ s.data = jQuery.param( s.data, s.traditional ); } + // If the jsonpCallback has been set, we can assume that dataType is jsonp + // Ticket #5803 + if ( s.jsonpCallback ) { + s.dataType = "jsonp"; + } + // Handle JSONP Parameter Callbacks if ( s.dataType === "jsonp" ) { if ( type === "GET" ) { @@ -265,7 +271,7 @@ jQuery.extend({ s.cache = false; } - if ( s.cache === false && type === "GET" ) { + if ( s.cache === false && noContent ) { var ts = jQuery.now(); // try replacing _= if it is there @@ -275,8 +281,8 @@ jQuery.extend({ s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : ""); } - // If data is available, append data to url for get requests - if ( s.data && type === "GET" ) { + // If data is available, append data to url for GET/HEAD requests + if ( s.data && noContent ) { s.url += (rquery.test(s.url) ? "&" : "?") + s.data; } diff --git a/src/effects.js b/src/effects.js index d7896c0..44a7942 100644 --- a/src/effects.js +++ b/src/effects.js @@ -174,7 +174,7 @@ jQuery.fn.extend({ } else { var parts = rfxnum.exec(val), - start = e.cur(true) || 0; + start = e.cur() || 0; if ( parts ) { var end = parseFloat( parts[2] ), @@ -183,7 +183,7 @@ jQuery.fn.extend({ // We need to compute starting value if ( unit !== "px" ) { jQuery.style( self, name, (end || 1) + unit); - start = ((end || 1) / e.cur(true)) * start; + start = ((end || 1) / e.cur()) * start; jQuery.style( self, name, start + unit); } diff --git a/src/event.js b/src/event.js index fb5a3ef..959e89c 100644 --- a/src/event.js +++ b/src/event.js @@ -32,6 +32,9 @@ jQuery.event = { if ( handler === false ) { handler = returnFalse; + } else if ( !handler ) { + // Fixes bug #7229. Fix recommended by jdalton + return; } var handleObjIn, handleObj; @@ -1129,6 +1132,9 @@ function liveHandler( event ) { if ( ret === false ) { stop = false; } + if ( event.isImmediatePropagationStopped() ) { + break; + } } } diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 5704d73..7344659 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -289,6 +289,32 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun }); }); +test("jQuery.ajax - HEAD requests", function() { + expect(2); + + stop(); + jQuery.ajax({ + url: url("data/name.html"), + type: "HEAD", + success: function(data, status, xhr){ + var h = xhr.getAllResponseHeaders(); + ok( /Date/i.test(h), 'No Date in HEAD response' ); + + jQuery.ajax({ + url: url("data/name.html"), + data: { whip_it: "good" }, + type: "HEAD", + success: function(data, status, xhr){ + var h = xhr.getAllResponseHeaders(); + ok( /Date/i.test(h), 'No Date in HEAD response with data' ); + start(); + } + }); + } + }); + +}); + test("jQuery.ajax - beforeSend", function() { expect(1); stop(); @@ -799,6 +825,21 @@ test("jQuery.ajax() - JSONP, Local", function() { plus(); } }); + + // Supports Ticket #5803 + jQuery.ajax({ + url: "data/jsonp.php", + jsonpCallback: "jsonpResults", + success: function(data){ + ok( data.data, "JSON results returned without dataType:jsonp when jsonpCallback is defined" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, custom callback name)" ); + plus(); + } + }); + }); test("JSONP - Custom JSONP Callback", function() { diff --git a/test/unit/event.js b/test/unit/event.js index f3d3148..54431dd 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1,5 +1,25 @@ module("event"); +test("null or undefined handler", function() { + expect(2); + // Supports Fixes bug #7229 + try { + + jQuery("#firstp").click(null); + + ok(true, "Passing a null handler will not throw an exception"); + + } catch (e) {} + + try { + + jQuery("#firstp").click(undefined); + + ok(true, "Passing an undefined handler will not throw an exception"); + + } catch (e) {} +}); + test("bind(), with data", function() { expect(3); var handler = function(event) { @@ -245,6 +265,36 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() { equals( mouseoverCounter, 4, "die" ); }); +test("live/delegate immediate propagation", function() { + expect(2); + + var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick; + + lastClick = ""; + $a.live( "click", function(e) { + lastClick = "click1"; + e.stopImmediatePropagation(); + }); + $a.live( "click", function(e) { + lastClick = "click2"; + }); + $a.trigger( "click" ); + equals( lastClick, "click1", "live stopImmediatePropagation" ); + $a.die( "click" ); + + lastClick = ""; + $p.delegate( "a", "click", function(e) { + lastClick = "click1"; + e.stopImmediatePropagation(); + }); + $p.delegate( "a", "click", function(e) { + lastClick = "click2"; + }); + $a.trigger( "click" ); + equals( lastClick, "click1", "delegate stopImmediatePropagation" ); + $p.undelegate( "click" ); +}); + test("bind(), iframes", function() { // events don't work with iframes, see #939 - this test fails in IE because of contentDocument var doc = jQuery("#loadediframe").contents();