Merge branch 'animate-nonblock' of http://github.com/csnover/jquery into csnover...
authorJohn Resig <jeresig@gmail.com>
Sat, 9 Oct 2010 20:21:02 +0000 (16:21 -0400)
committerJohn Resig <jeresig@gmail.com>
Sat, 9 Oct 2010 20:21:02 +0000 (16:21 -0400)
src/ajax.js
src/css.js
src/data.js
test/unit/css.js
test/unit/manipulation.js

index e615480..95e40ec 100644 (file)
@@ -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) {}
        };
 }
 
index 8751860..d0e55db 100644 (file)
@@ -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 {
index 66d24c4..732e923 100644 (file)
@@ -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);
index 02a7b08..8a49096 100644 (file)
@@ -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) {
index 7b4f4d1..d4c4348 100644 (file)
@@ -680,7 +680,7 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
 });
 
 var testReplaceWith = function(val) {
-       expect(17);
+       expect(20);
        jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' ));
        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) {
                //"</script>");
        equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');
        jQuery('.replacewith').remove();
+
+       QUnit.reset();
+
+       jQuery("#main").append("<div id='replaceWith'></div>");
+       equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
+
+       jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
+       equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
+
+       jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") );
+       equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." );
 }
 
 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@@ -757,7 +768,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
 test("replaceWith(Function)", function() {
        testReplaceWith(functionReturningObj);
 
-       expect(18);
+       expect(21);
 
        var y = jQuery("#yahoo")[0];