From: John Resig Date: Sat, 9 Oct 2010 20:21:02 +0000 (-0400) Subject: Merge branch 'animate-nonblock' of http://github.com/csnover/jquery into csnover... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=b0dcc1746f58f5aca17a12794dd928c0deaaa6a0;hp=543db64412b37b5fa1f3d7fea19f62d6db993fb0;p=jquery.git Merge branch 'animate-nonblock' of github.com/csnover/jquery into csnover-animate-nonblock --- diff --git a/src/ajax.js b/src/ajax.js index e615480..95e40ec 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -698,12 +698,12 @@ if ( window.ActiveXObject ) { if ( window.location.protocol !== "file:" ) { try { return new window.XMLHttpRequest(); - } catch(e) {} + } catch(xhrError) {} } try { return new window.ActiveXObject("Microsoft.XMLHTTP"); - } catch(e) {} + } catch(activeError) {} }; } diff --git a/src/css.js b/src/css.js index 8751860..d0e55db 100644 --- a/src/css.js +++ b/src/css.js @@ -70,7 +70,7 @@ jQuery.extend({ style: function( elem, name, value, extra ) { // Don't set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { - return undefined; + return; } // Make sure that we're working with the right name @@ -81,6 +81,11 @@ jQuery.extend({ // Check if we're setting a value if ( value !== undefined ) { + // Make sure that NaN and null values aren't set. See: #7116 + if ( typeof value === "number" && isNaN( value ) || value == null ) { + return; + } + // If a number was passed in, add 'px' to the (except for certain CSS properties) if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) { value += "px"; @@ -88,7 +93,11 @@ jQuery.extend({ // If a hook was provided, use that value, otherwise just set the specified value if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) { - style[ name ] = value; + // Wrapped to prevent IE from throwing errors when 'invalid' values are provided + // Fixes bug #5509 + try { + style[ name ] = value; + } catch(e) {} } } else { diff --git a/src/data.js b/src/data.js index 66d24c4..732e923 100644 --- a/src/data.js +++ b/src/data.js @@ -121,7 +121,7 @@ jQuery.extend({ // A method for determining if a DOM node can handle the data expando acceptData: function( elem ) { if ( elem.nodeName ) { - match = jQuery.noData[ elem.nodeName.toLowerCase() ]; + var match = jQuery.noData[ elem.nodeName.toLowerCase() ]; if ( match ) { return !(match === true || elem.getAttribute("classid") !== match); diff --git a/test/unit/css.js b/test/unit/css.js index 02a7b08..8a49096 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css"); test("css(String|Hash)", function() { - expect(29); + expect(33); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -61,10 +61,30 @@ test("css(String|Hash)", function() { equals( prctval, checkval, "Verify fontSize % set." ); equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." ); + + var old = child[0].style.height; + + // Test NaN + child.css("height", parseFloat("zoo")); + equals( child[0].style.height, old, "Make sure height isn't changed on NaN." ); + + // Test null + child.css("height", null); + equals( child[0].style.height, old, "Make sure height isn't changed on null." ); + + old = child[0].style.fontSize; + + // Test NaN + child.css("font-size", parseFloat("zoo")); + equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." ); + + // Test null + child.css("font-size", null); + equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." ); }); test("css(String, Object)", function() { - expect(21); + expect(22); ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible'); jQuery('#nothiddendiv').css("display", 'none'); @@ -104,6 +124,16 @@ test("css(String, Object)", function() { equals( ret, div, "Make sure setting undefined returns the original set." ); equals( div.css("display"), display, "Make sure that the display wasn't changed." ); + + // Test for Bug #5509 + var success = true; + try { + jQuery('#foo').css("backgroundColor", "rgba(0, 0, 0, 0.1)"); + } + catch (e) { + success = false; + } + ok( success, "Setting RGBA values does not throw Error" ); }); if(jQuery.browser.msie) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 7b4f4d1..d4c4348 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -680,7 +680,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { }); var testReplaceWith = function(val) { - expect(17); + expect(20); jQuery('#yahoo').replaceWith(val( 'buga' )); ok( jQuery("#replace")[0], 'Replace element with string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); @@ -748,6 +748,17 @@ var testReplaceWith = function(val) { //""); equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.'); jQuery('.replacewith').remove(); + + QUnit.reset(); + + jQuery("#main").append("
"); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("
") ); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + + jQuery("#replaceWith").replaceWith( val("
") ); + equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); } test("replaceWith(String|Element|Array<Element>|jQuery)", function() { @@ -757,7 +768,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() { test("replaceWith(Function)", function() { testReplaceWith(functionReturningObj); - expect(18); + expect(21); var y = jQuery("#yahoo")[0];