Skip to content

Commit 6ab402d

Browse files
kswedbergjeresig
authored andcommitted
For .show() with no arguments, only set display of elements in the second loop if they don't have style.display already set or if style.display isn't none. Fixes #7315.
1 parent 7066bb3 commit 6ab402d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/effects.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,39 @@ var elemdisplay = {},
1515

1616
jQuery.fn.extend({
1717
show: function( speed, easing, callback ) {
18+
var elem, display;
19+
1820
if ( speed || speed === 0 ) {
1921
return this.animate( genFx("show", 3), speed, easing, callback);
22+
2023
} else {
2124
for ( var i = 0, j = this.length; i < j; i++ ) {
25+
elem = this[i];
26+
display = elem.style.display;
27+
2228
// Reset the inline display of this element to learn if it is
2329
// being hidden by cascaded rules or not
24-
if ( !jQuery.data(this[i], "olddisplay") && this[i].style.display === "none" ) {
25-
this[i].style.display = "";
30+
if ( !jQuery.data(elem, "olddisplay") && display === "none" ) {
31+
elem.style.display = "";
2632
}
2733

2834
// Set elements which have been overridden with display: none
2935
// in a stylesheet to whatever the default browser style is
3036
// for such an element
31-
if ( this[i].style.display === "" && jQuery.css( this[i], "display" ) === "none" ) {
32-
jQuery.data(this[i], "olddisplay", defaultDisplay(this[i].nodeName));
37+
if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
38+
jQuery.data(elem, "olddisplay", defaultDisplay(elem.nodeName));
3339
}
3440
}
3541

3642
// Set the display of most of the elements in a second loop
3743
// to avoid the constant reflow
3844
for ( i = 0; i < j; i++ ) {
39-
this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
45+
elem = this[i];
46+
display = elem.style.display;
47+
48+
if ( display === "" || display === "none" ) {
49+
elem.style.display = jQuery.data(elem, "olddisplay") || "";
50+
}
4051
}
4152

4253
return this;

test/unit/effects.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ test("sanity check", function() {
66
});
77

88
test("show()", function() {
9-
expect(23);
9+
expect(26);
10+
11+
var hiddendiv = jQuery("div.hidden");
12+
13+
equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
14+
15+
hiddendiv.css("display", "block");
16+
equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
17+
18+
hiddendiv.show();
19+
equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
20+
21+
hiddendiv.css("display","");
22+
1023
var pass = true, div = jQuery("#main div");
1124
div.show().each(function(){
1225
if ( this.style.display == "none" ) pass = false;

0 commit comments

Comments
 (0)