From: Colin Snover Date: Mon, 11 Oct 2010 20:22:43 +0000 (-0500) Subject: Fix olddisplay was inappropriately set when calling hide on an already hidden element... X-Git-Tag: 1.4.3rc2~11^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F49%2Fhead;p=jquery.git Fix olddisplay was inappropriately set when calling hide on an already hidden element. Fixes #7141. --- diff --git a/src/effects.js b/src/effects.js index 241dbd036..8662df5b9 100644 --- a/src/effects.js +++ b/src/effects.js @@ -49,9 +49,10 @@ jQuery.fn.extend({ } else { for ( var i = 0, j = this.length; i < j; i++ ) { - var old = jQuery.data(this[i], "olddisplay"); - if ( !old ) { - jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) ); + var display = jQuery.css( this[i], "display" ); + + if ( display !== "none" ) { + jQuery.data( this[i], "olddisplay", display ); } } diff --git a/test/unit/effects.js b/test/unit/effects.js index 3c4015aff..2dfe834b2 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -770,3 +770,33 @@ test("animate with per-property easing", function(){ }); }); + +test("hide hidden elements (bug #7141)", function() { + expect(3); + QUnit.reset(); + + var div = jQuery("
").appendTo("#main"); + equals( div.css("display"), "none", "Element is hidden by default" ); + div.hide(); + ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); + div.show(); + equals( div.css("display"), "block", "Show a double-hidden element" ); + + div.remove(); +}); + +test("hide hidden elements, with animation (bug #7141)", function() { + expect(3); + QUnit.reset(); + stop(); + + var div = jQuery("
").appendTo("#main"); + equals( div.css("display"), "none", "Element is hidden by default" ); + div.hide(1, function () { + ok( !div.data("olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); + div.show(1, function () { + equals( div.css("display"), "block", "Show a double-hidden element" ); + start(); + }); + }); +});