Skip to content

Commit 299bc65

Browse files
rwaldrontimmywil
authored andcommitted
Landing pull request 581. Updates original patch by Orkel. Fixes #10006.
More Details: - jquery#581 - http://bugs.jquery.com/ticket/10006
1 parent 65d3dc6 commit 299bc65

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/effects.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jQuery.fn.extend({
3838
// Set elements which have been overridden with display: none
3939
// in a stylesheet to whatever the default browser style is
4040
// for such an element
41-
if ( display === "" && jQuery.css(elem, "display") === "none" ) {
41+
if ( (display === "" && jQuery.css(elem, "display") === "none") ||
42+
!jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
4243
jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
4344
}
4445
}

test/unit/effects.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ test("Persist correct display value", function() {
167167
});
168168
});
169169

170-
test("show() resolves correct default display #8099", function() {
170+
test("show() resolves correct default display (#8099)", function() {
171171
expect(7);
172172
var tt8099 = jQuery("<tt/>").appendTo("body"),
173173
dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
@@ -185,7 +185,60 @@ test("show() resolves correct default display #8099", function() {
185185

186186
tt8099.remove();
187187
dfn8099.remove();
188+
});
189+
190+
test( "show() resolves correct default display, detached nodes (#10006)", function(){
191+
// Tests originally contributed by Orkel in
192+
// https://github.com/jquery/jquery/pull/458
193+
expect( 11 );
194+
195+
var div, span;
196+
197+
div = jQuery("<div class='hidden'>");
198+
div.show().appendTo("#qunit-fixture");
199+
equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
200+
201+
div = jQuery("<div style='display: none'>");
202+
div.show().appendTo("#qunit-fixture");
203+
equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
204+
205+
span = jQuery("<span class='hidden'/>");
206+
span.show().appendTo("#qunit-fixture");
207+
equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
208+
209+
span = jQuery("<span style='display: inline'/>");
210+
span.show().appendTo("#qunit-fixture");
211+
equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
212+
213+
div = jQuery("<div><div class='hidden'></div></div>").children("div");
214+
div.show().appendTo("#qunit-fixture");
215+
equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
216+
217+
div = jQuery("<div><div style='display: none'></div></div>").children("div");
218+
div.show().appendTo("#qunit-fixture");
219+
equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
220+
221+
div = jQuery("div.hidden");
222+
div.detach().show();
223+
equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
224+
div.remove();
225+
226+
span = jQuery("<span>");
227+
span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
228+
equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
229+
span.remove();
230+
231+
div = jQuery("<div>");
232+
div.show().appendTo("#qunit-fixture");
233+
ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
234+
235+
div = jQuery( document.createElement("div") );
236+
div.show().appendTo("#qunit-fixture");
237+
equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
188238

239+
div = jQuery("<div style='display: inline'/>");
240+
div.show().appendTo("#qunit-fixture");
241+
equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
189242
});
190243

191244

0 commit comments

Comments
 (0)