Merge branch '8099' of https://github.com/rwldrn/jquery into rwldrn-8099
authorjeresig <jeresig@gmail.com>
Mon, 14 Feb 2011 17:36:49 +0000 (12:36 -0500)
committerjeresig <jeresig@gmail.com>
Mon, 14 Feb 2011 17:36:49 +0000 (12:36 -0500)
1  2 
src/effects.js
test/unit/effects.js

diff --combined src/effects.js
@@@ -189,7 -189,7 +189,7 @@@ jQuery.fn.extend(
  
                                        if ( parts ) {
                                                var end = parseFloat( parts[2] ),
 -                                                      unit = parts[3] || "px";
 +                                                      unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
  
                                                // We need to compute starting value
                                                if ( unit !== "px" ) {
@@@ -348,7 -348,7 +348,7 @@@ jQuery.fx.prototype = 
                this.startTime = jQuery.now();
                this.start = from;
                this.end = to;
 -              this.unit = unit || this.unit || "px";
 +              this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
                this.now = this.start;
                this.pos = this.state = 0;
  
@@@ -505,17 -505,42 +505,42 @@@ if ( jQuery.expr && jQuery.expr.filter
  }
  
  function defaultDisplay( nodeName ) {
+       var stylesheets = document.styleSheets,
+                       disabled = [],
+                       elem, display, style, idx;
        if ( !elemdisplay[ nodeName ] ) {
-               var elem = jQuery("<" + nodeName + ">").appendTo("body"),
-                       display = elem.css("display");
  
+               // #8099 - If the end-dev has globally changed a default
+               // display, we can temporarily disable their styles to check
+               // for the correct default value
+               for ( idx = 0; idx < stylesheets.length; ++idx  ) {
+                       style = stylesheets[ idx ];
+                       disabled[ idx ] = style.disabled;
+                       style.disabled = true;
+               }
+               
+               // To accurately check an element's default display value, 
+               // create a temp element and check it's default display, this
+               // will ensure that the value returned is not a user-tampered
+               // value.
+               elem = jQuery("<" + nodeName + ">").appendTo("body"),
+               display = elem.css("display");
+               
+               // Remove temp element
                elem.remove();
  
                if ( display === "none" || display === "" ) {
                        display = "block";
                }
+               
+               // Store the correct default display
                elemdisplay[ nodeName ] = display;
+               // Restore stylesheets
+               for ( idx = 0; idx < stylesheets.length; ++idx  ) {
+                       stylesheets[ idx ].disabled = disabled[ idx ];
+               }
        }
  
        return elemdisplay[ nodeName ];
diff --combined test/unit/effects.js
@@@ -39,23 -39,24 +39,23 @@@ test("show()", function() 
        ok( pass, "Show" );
  
        var speeds = {
 -        "null speed": null,
 -        "undefined speed": undefined,
 -        "empty string speed": "",
 -        "false speed": false
 +              "null speed": null,
 +              "undefined speed": undefined,
 +              "empty string speed": "",
 +              "false speed": false
        };
  
        jQuery.each(speeds, function(name, speed) {
 -    pass = true;
 -      div.hide().show(speed).each(function() {
 -              if ( this.style.display == "none" ) pass = false;
 -      });
 -      ok( pass, "Show with " + name);
 -  });
 -
 +              pass = true;
 +              div.hide().show(speed).each(function() {
 +                      if ( this.style.display == "none" ) pass = false;
 +              });
 +              ok( pass, "Show with " + name);
 +      });
  
        jQuery.each(speeds, function(name, speed) {
 -    pass = true;
 -      div.hide().show(speed, function() {
 +      pass = true;
 +      div.hide().show(speed, function() {
                        pass = false;
                });
                ok( pass, "Show with " + name + " does not call animate callback" );
@@@ -131,9 -132,9 +131,9 @@@ test("show(Number) - other displays", f
  
  
  
 -//  Supports #7397
 +// Supports #7397
  test("Persist correct display value", function() {
 -  expect(3);
 +      expect(3);
        QUnit.reset();
        stop();
  
        jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>');
  
        var $span = jQuery("#show-tests span"),
 -        displayNone = $span.css("display"),
 -        display = '', num = 0;
 -
 -  $span.show();
 -
 -  display = $span.css("display");
 +              displayNone = $span.css("display"),
 +              display = '', num = 0;
  
 -  $span.hide();
 +      $span.show();
  
 -  $span.fadeIn(100, function() {
 +      display = $span.css("display");
  
 -    equals($span.css("display"), display, "Expecting display: " + display);
 +      $span.hide();
  
 -    $span.fadeOut(100, function () {
 -
 -      equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
 -
 -      $span.fadeIn(100, function() {
 -
 -        equals($span.css("display"), display, "Expecting display: " + display);
 -
 -        start();
 -      });
 -    });
 -  });
 +      $span.fadeIn(100, function() {
 +              equals($span.css("display"), display, "Expecting display: " + display);
 +              $span.fadeOut(100, function () {
 +                      equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
 +                      $span.fadeIn(100, function() {
 +                              equals($span.css("display"), display, "Expecting display: " + display);
 +                              start();
 +                      });
 +              });
 +      });
  });
  
+ test("show() resolves correct default display #8099", function() {
+       expect(3);
+       var bug8099 = jQuery("<tt/>").appendTo("#main");
+       equals( bug8099.css("display"), "none", "default display override for all tt" );
+       equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+       bug8099.remove();
+       equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
+ });
  test("animate(Hash, Object, Function)", function() {
        expect(1);
        stop();
@@@ -567,7 -586,7 +579,7 @@@ test("support negative values < -10000 
                        equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
                        delete jQuery.fx.step.marginBottom;
                }
 -    });
 +      });
  
        jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
                duration: 1,
@@@ -796,7 -815,7 +808,7 @@@ test("Chain toggle out", function() 
        jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
  });
  test("Chain toggle out with easing and callback", function() {
 - jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
 +      jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
  });
  test("Chain slideDown slideUp", function() {
        jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
@@@ -843,16 -862,16 +855,16 @@@ jQuery.makeTest.id = 1
  
  test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
        expect(4);
 -  stop();
 +      stop();
  
        var $checkedtest = jQuery("#checkedtest");
        // IE6 was clearing "checked" in jQuery(elem).show("fast");
        $checkedtest.hide().show("fast", function() {
 -      ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
 -      ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
 -      ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
 -      ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
 -      start();
 +              ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
 +              ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
 +              ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
 +              ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
 +              start();
        });
  });
  
@@@ -919,13 -938,3 +931,13 @@@ test("hide hidden elements, with animat
                });
        });
  });
 +
 +test("animate unit-less properties (#4966)", 2, function() {
 +      stop();
 +      var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#main" );
 +      equal( div.css( "z-index" ), "0", "z-index is 0" );
 +      div.animate({ zIndex: 2 }, function() {
 +              equal( div.css( "z-index" ), "2", "z-index is 2" );
 +              start();
 +      });
 +});