From 352715bd0802e2df041f86e1a82669574183ec04 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Apr 2011 17:46:15 -0400 Subject: [PATCH 1/7] Use explicit "new jQuery.Event" to avoid double-function-call overhead. --- src/event.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index b8a2e37e..5e2baf0d 100644 --- a/src/event.js +++ b/src/event.js @@ -314,9 +314,9 @@ jQuery.event = { // jQuery.Event object event[ jQuery.expando ] ? event : // Object literal - jQuery.extend( jQuery.Event(type), event ) : + jQuery.extend( new jQuery.Event(type), event ) : // Just the event type (string) - jQuery.Event(type); + new jQuery.Event(type); event.namespace = namespaces.join("."); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); event.exclusive = exclusive; @@ -989,7 +989,7 @@ jQuery.fn.extend({ triggerHandler: function( type, data ) { if ( this[0] ) { - var event = jQuery.Event( type ); + var event = new jQuery.Event( type ); event.preventDefault(); event.stopPropagation(); jQuery.event.trigger( event, data, this[0] ); From 73f9ab67058d2dc14ab81c62bd9b228b0e1cad93 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 12 Apr 2011 18:30:21 -0400 Subject: [PATCH 2/7] JSLint failed due to function created within for loop --- src/manipulation.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 52d59d83..711cb5e8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -553,6 +553,8 @@ jQuery.extend({ }, clean: function( elems, context, fragment, scripts ) { + var checkScriptType; + context = context || document; // !context.createElement fails in IE with an error but returns typeof 'object' @@ -630,15 +632,16 @@ jQuery.extend({ } if ( fragment ) { + checkScriptType = function( elem ) { + return !elem.type || rscriptType.test( elem.type ); + }; for ( i = 0; ret[i]; i++ ) { if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); } else { if ( ret[i].nodeType === 1 ) { - var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), function( elem ) { - return !elem.type || rscriptType.test( elem.type ); - }); + var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType ); ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) ); } From 9e71ad1b120e2b20c7430c017629877ba277f667 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Apr 2011 18:32:23 -0400 Subject: [PATCH 3/7] Explicitly set event.type in case we chopped out a namespace or exclusive flag. --- src/event.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/event.js b/src/event.js index 5e2baf0d..f6cd97cc 100644 --- a/src/event.js +++ b/src/event.js @@ -317,6 +317,7 @@ jQuery.event = { jQuery.extend( new jQuery.Event(type), event ) : // Just the event type (string) new jQuery.Event(type); + event.type = type; event.namespace = namespaces.join("."); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); event.exclusive = exclusive; From bebd8bc01e63dcb053412f8b247e4fa611867c55 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Apr 2011 19:29:09 -0400 Subject: [PATCH 4/7] Followup to #8753. Modify new Event constructor signature to jQuery.event(type, props), which can be exploited by jQuery.event.trigger as well. --- src/event.js | 24 +++++++++--------------- test/unit/event.js | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/event.js b/src/event.js index f005f728..dd48e7f7 100644 --- a/src/event.js +++ b/src/event.js @@ -304,9 +304,9 @@ jQuery.event = { // jQuery.Event object event[ jQuery.expando ] ? event : // Object literal - jQuery.extend( new jQuery.Event(type), event ) : + new jQuery.Event( type, event ) : // Just the event type (string) - new jQuery.Event(type); + new jQuery.Event( type ); event.type = type; event.namespace = namespaces.join("."); @@ -563,26 +563,15 @@ jQuery.removeEvent = document.removeEventListener ? } }; -jQuery.Event = function( src ) { +jQuery.Event = function( src, props ) { // Allow instantiation without the 'new' keyword if ( !this.preventDefault ) { - return new jQuery.Event( src ); + return new jQuery.Event( src, props ); } // Event object if ( src && src.type ) { this.originalEvent = src; - - // Push explicitly provided properties onto the event object - for ( var prop in src ) { - // Ensure we don't clobber jQuery.Event prototype - // with own properties. - if ( hasOwn.call( src, prop ) ) { - this[ prop ] = src[ prop ]; - } - } - - // Always ensure a type has been explicitly set this.type = src.type; // Events bubbling up the document may have been marked as prevented @@ -595,6 +584,11 @@ jQuery.Event = function( src ) { this.type = src; } + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + // timeStamp is buggy for some events on Firefox(#3843) // So we won't rely on the native value this.timeStamp = jQuery.now(); diff --git a/test/unit/event.js b/test/unit/event.js index 491396f9..d4e3994e 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -978,11 +978,11 @@ test("trigger(eventObject, [data], [fn])", function() { $parent.unbind().remove(); }); -test("jQuery.Event({ /* props */ })", function() { +test("jQuery.Event( type, props )", function() { expect(4); - var event = jQuery.Event({ type: "keydown", keyCode: 64 }), + var event = jQuery.Event( "keydown", { keyCode: 64 }), handler = function( event ) { ok( "keyCode" in event, "Special property 'keyCode' exists" ); equal( event.keyCode, 64, "event.keyCode has explicit value '64'" ); From 69866fd2e5ba2456c2ae84a5ba711a1db2a25091 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 12 Apr 2011 19:32:18 -0400 Subject: [PATCH 5/7] VML.type test was causing multiple test suite fails, fix attributes.js fail in IE6 where the val(String/Number) tests were interfering with the val(Function) tests --- test/data/testsuite.css | 3 +++ test/index.html | 5 ----- test/unit/attributes.js | 16 +++++++++------- test/unit/event.js | 2 ++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/data/testsuite.css b/test/data/testsuite.css index 02900681..a9dd97ba 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -109,3 +109,6 @@ div#show-tests * { display: none; } #nothiddendiv { font-size: 16px; } #nothiddendivchild.em { font-size: 2em; } #nothiddendivchild.prct { font-size: 150%; } + +/* For testing type on vml in IE #7071 */ +v\:oval { behavior:url(#default#VML); display:inline-block; } \ No newline at end of file diff --git a/test/index.html b/test/index.html index bf7dc798..a1065508 100644 --- a/test/index.html +++ b/test/index.html @@ -45,10 +45,6 @@ - - - - @@ -151,7 +147,6 @@ test element - Float test. diff --git a/test/unit/attributes.js b/test/unit/attributes.js index c78a2961..2bcc5046 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -492,6 +492,7 @@ test("val()", function() { var testVal = function(valueObj) { expect(8); + QUnit.reset(); jQuery("#text1").val(valueObj( "test" )); equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); @@ -504,15 +505,16 @@ var testVal = function(valueObj) { jQuery("#text1").val(valueObj( null )); equals( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" ); - jQuery("#select1").val(valueObj( "3" )); - equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); + var $select1 = jQuery("#select1"); + $select1.val(valueObj( "3" )); + equals( $select1.val(), "3", "Check for modified (via val(String)) value of select element" ); - jQuery("#select1").val(valueObj( 2 )); - equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); + $select1.val(valueObj( 2 )); + equals( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" ); - jQuery("#select1").append(""); - jQuery("#select1").val(valueObj( 4 )); - equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); + $select1.append(""); + $select1.val(valueObj( 4 )); + equals( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); diff --git a/test/unit/event.js b/test/unit/event.js index 491396f9..8ffbcd5b 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -778,6 +778,8 @@ test("trigger() shortcuts", function() { elem.remove(); // test that special handlers do not blow up with VML elements (#7071) + jQuery('').appendTo('head'); + jQuery(' ').appendTo('#form'); jQuery("#oval").click().keydown(); }); From 4344d0841756f8572c56490f12739ac204f40966 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 13 Apr 2011 18:35:38 +0200 Subject: [PATCH 6/7] Fixes #8635 again (fix was lost in rewrite). Also removes unnecessary "manual" garbage collection. --- src/support.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/support.js b/src/support.js index 6b19c083..1bd35cab 100644 --- a/src/support.js +++ b/src/support.js @@ -73,7 +73,7 @@ jQuery.support = (function() { // Make sure that a selected-by-default option has a working selected property. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, - + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", @@ -196,7 +196,7 @@ jQuery.support = (function() { marginDiv.style.marginRight = "0"; div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( document.defaultView.getComputedStyle( marginDiv ).marginRight, 10 ) || 0 ) === 0; + ( parseInt( document.defaultView.getComputedStyle( marginDiv, null ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added @@ -224,9 +224,6 @@ jQuery.support = (function() { } } - // release memory in IE - body = div = all = a = tds = undefined; - return support; })(); From 4ad9b44deada9da9639f53b1ca3cc4cf2ebf2df2 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 13 Apr 2011 19:27:19 +0200 Subject: [PATCH 7/7] Ensures callback placeholders are tested for and eventually replaced in data only when contentType is application/x-www-form-urlencoded and data is a string. Removes json to jsonp promotion when jsonp or jsonpCallback options are present. Uses new Deferred.always method to bind cleanUp function. --- src/ajax/jsonp.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index 4fb09401..6b0f95d5 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -14,13 +14,12 @@ jQuery.ajaxSetup({ // Detect, normalize options and install callbacks for jsonp requests jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { - var dataIsString = ( typeof s.data === "string" ); + var inspectData = s.contentType === "application/x-www-form-urlencoded" && + ( typeof s.data === "string" ); if ( s.dataTypes[ 0 ] === "jsonp" || - originalSettings.jsonpCallback || - originalSettings.jsonp != null || s.jsonp !== false && ( jsre.test( s.url ) || - dataIsString && jsre.test( s.data ) ) ) { + inspectData && jsre.test( s.data ) ) ) { var responseContainer, jsonpCallback = s.jsonpCallback = @@ -28,20 +27,12 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { previous = window[ jsonpCallback ], url = s.url, data = s.data, - replace = "$1" + jsonpCallback + "$2", - cleanUp = function() { - // Set callback back to previous value - window[ jsonpCallback ] = previous; - // Call if it was a function and we have a response - if ( responseContainer && jQuery.isFunction( previous ) ) { - window[ jsonpCallback ]( responseContainer[ 0 ] ); - } - }; + replace = "$1" + jsonpCallback + "$2"; if ( s.jsonp !== false ) { url = url.replace( jsre, replace ); if ( s.url === url ) { - if ( dataIsString ) { + if ( inspectData ) { data = data.replace( jsre, replace ); } if ( s.data === data ) { @@ -59,8 +50,15 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { responseContainer = [ response ]; }; - // Install cleanUp function - jqXHR.then( cleanUp, cleanUp ); + // Clean-up function + jqXHR.always(function() { + // Set callback back to previous value + window[ jsonpCallback ] = previous; + // Call if it was a function and we have a response + if ( responseContainer && jQuery.isFunction( previous ) ) { + window[ jsonpCallback ]( responseContainer[ 0 ] ); + } + }); // Use data converter to retrieve json after script execution s.converters["script json"] = function() {