From 118c8c4600b62d6de2b0248ae27626da74dcf5b2 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 9 Nov 2010 18:06:33 -0500 Subject: [PATCH 1/7] Fixes #7397; 4 supporting unit tests --- src/effects.js | 11 ++++++----- test/unit/effects.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/effects.js b/src/effects.js index 51ce0c577..f9c682c9f 100644 --- a/src/effects.js +++ b/src/effects.js @@ -60,11 +60,12 @@ jQuery.fn.extend({ } else { for ( var i = 0, j = this.length; i < j; i++ ) { - var display = jQuery.css( this[i], "display" ); - - if ( display !== "none" ) { - jQuery.data( this[i], "olddisplay", display ); - } + var display = jQuery.css( this[i], "display" ), + old = jQuery.data( this[i], "olddisplay" ); + + if ( !old && display !== "none" ) { + jQuery.data( this[i], "olddisplay", display ); + } } // Set the display of the elements in a second loop diff --git a/test/unit/effects.js b/test/unit/effects.js index 74b336f1f..aca926384 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -130,6 +130,41 @@ test("show(Number) - other displays", function() { }); }); + + +// Supports #7397 +test("Persist correct display value", function() { + expect(4); + QUnit.reset(); + stop(); + + // #show-tests * is set display: none in CSS + jQuery("#main").append('
'); + + var $span = jQuery("#show-tests span"), + orig = $span.css("display"), + num = 0; + + equal(orig, "none", "Expecting to start at display: none"); + + $span.text('Saving...').fadeIn(100, function() { + + equal($span.css("display"), "block", "Expecting display: block"); + + $span.text('Saved!').fadeOut(100, function () { + + equal($span.css("display"), "none", "Expecting display: none"); + + $span.text('Saving...').fadeIn(100, function() { + + equal($span.css("display"), "block", "Expecting display: block"); + + start(); + }); + }); + }); +}); + test("animate(Hash, Object, Function)", function() { expect(1); stop(); From 8f2667f4c09d14de413cac1e3c5fc5783521b0e0 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 9 Nov 2010 18:20:27 -0500 Subject: [PATCH 2/7] Clean #7397; Removed unnec. var declaration --- src/effects.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/effects.js b/src/effects.js index f9c682c9f..bac2e1d51 100644 --- a/src/effects.js +++ b/src/effects.js @@ -60,10 +60,9 @@ jQuery.fn.extend({ } else { for ( var i = 0, j = this.length; i < j; i++ ) { - var display = jQuery.css( this[i], "display" ), - old = jQuery.data( this[i], "olddisplay" ); + var display = jQuery.css( this[i], "display" ); - if ( !old && display !== "none" ) { + if ( !jQuery.data( this[i], "olddisplay" ) && display !== "none" ) { jQuery.data( this[i], "olddisplay", display ); } } From 2a23650a19ed4db2d031697638bdd71c06f44492 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 10 Nov 2010 10:23:48 -0500 Subject: [PATCH 3/7] Updating #7397 unit tests to correctly test for a persisted display value --- test/unit/effects.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/unit/effects.js b/test/unit/effects.js index aca926384..969079683 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -134,30 +134,34 @@ test("show(Number) - other displays", function() { // Supports #7397 test("Persist correct display value", function() { - expect(4); + expect(3); QUnit.reset(); stop(); // #show-tests * is set display: none in CSS - jQuery("#main").append('
'); + jQuery("#main").append('
foo
'); var $span = jQuery("#show-tests span"), - orig = $span.css("display"), - num = 0; + displayNone = $span.css("display"), + display = '', num = 0; - equal(orig, "none", "Expecting to start at display: none"); - - $span.text('Saving...').fadeIn(100, function() { - - equal($span.css("display"), "block", "Expecting display: block"); - - $span.text('Saved!').fadeOut(100, function () { + $span.show(); - equal($span.css("display"), "none", "Expecting display: none"); + display = $span.css("display"); + + $span.hide(); + + $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.text('Saving...').fadeIn(100, function() { + $span.fadeIn(100, function() { - equal($span.css("display"), "block", "Expecting display: block"); + equals($span.css("display"), display, "Expecting display: " + display); start(); }); From 00f1dfdd57fd8478688f9d201e539e0bf3946be2 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 9 Dec 2010 12:44:52 -0500 Subject: [PATCH 4/7] Reorders condition at L65 for efficiency --- src/effects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/effects.js b/src/effects.js index bac2e1d51..feaf02b5d 100644 --- a/src/effects.js +++ b/src/effects.js @@ -62,8 +62,8 @@ jQuery.fn.extend({ for ( var i = 0, j = this.length; i < j; i++ ) { var display = jQuery.css( this[i], "display" ); - if ( !jQuery.data( this[i], "olddisplay" ) && display !== "none" ) { - jQuery.data( this[i], "olddisplay", display ); + if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { + jQuery.data( this[i], "olddisplay", display ); } } From 5b2408147b9cf9b7f49a07ebe97b20c398568e22 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 9 Dec 2010 12:47:53 -0500 Subject: [PATCH 5/7] Whitespace correction --- src/effects.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/effects.js b/src/effects.js index feaf02b5d..f976c41a5 100644 --- a/src/effects.js +++ b/src/effects.js @@ -62,9 +62,9 @@ jQuery.fn.extend({ for ( var i = 0, j = this.length; i < j; i++ ) { var display = jQuery.css( this[i], "display" ); - if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { - jQuery.data( this[i], "olddisplay", display ); - } + if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { + jQuery.data( this[i], "olddisplay", display ); + } } // Set the display of the elements in a second loop From 1cdd9f8cab5b86d76ea20e996a9c636dd6f5ca6e Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 9 Dec 2010 12:48:52 -0500 Subject: [PATCH 6/7] Whitespace correction --- src/effects.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/effects.js b/src/effects.js index f976c41a5..482c44d5a 100644 --- a/src/effects.js +++ b/src/effects.js @@ -62,9 +62,9 @@ jQuery.fn.extend({ for ( var i = 0, j = this.length; i < j; i++ ) { var display = jQuery.css( this[i], "display" ); - if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { - jQuery.data( this[i], "olddisplay", display ); - } + if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { + jQuery.data( this[i], "olddisplay", display ); + } } // Set the display of the elements in a second loop From a59bb30d0a5ea0d3d73285c6fed0fbe00b23321f Mon Sep 17 00:00:00 2001 From: rwldrn Date: Thu, 9 Dec 2010 12:50:01 -0500 Subject: [PATCH 7/7] Whitespace correction --- src/effects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/effects.js b/src/effects.js index 482c44d5a..98f969f0f 100644 --- a/src/effects.js +++ b/src/effects.js @@ -63,7 +63,7 @@ jQuery.fn.extend({ var display = jQuery.css( this[i], "display" ); if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { - jQuery.data( this[i], "olddisplay", display ); + jQuery.data( this[i], "olddisplay", display ); } }