aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg <markelog@gmail.com>2012-01-12 19:40:41 -0500
committerDave Methvin <dave.methvin@gmail.com>2012-01-12 19:57:04 -0500
commitcc5e8e3866e5dac7eacda5927679573c8da79492 (patch)
treea39a30c6c2c1cad35c90fcaa44d200945745a9fc
parentd07116a9525f039d7a2a2e080f468d8ddbc283a7 (diff)
downloadjquery-cc5e8e3866e5dac7eacda5927679573c8da79492.tar.gz
jquery-cc5e8e3866e5dac7eacda5927679573c8da79492.zip
Fix #10006: Allow .show() to work on detached elements.
-rw-r--r--src/effects.js3
-rw-r--r--test/unit/effects.js54
-rw-r--r--test/unit/queue.js1
3 files changed, 57 insertions, 1 deletions
diff --git a/src/effects.js b/src/effects.js
index 926b40b54..6716e616a 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -38,7 +38,8 @@ jQuery.fn.extend({
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
- if ( display === "" && jQuery.css(elem, "display") === "none" ) {
+ if ( (display === "" && jQuery.css(elem, "display") === "none") ||
+ !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
}
}
diff --git a/test/unit/effects.js b/test/unit/effects.js
index 1728cf8f9..49fa33d42 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -188,6 +188,60 @@ test("show() resolves correct default display #8099", function() {
});
+test( "show() resolves correct default display, detached nodes (#10006)", function(){
+ // Tests originally contributed by Orkel in
+ // https://github.com/jquery/jquery/pull/458
+ expect( 11 );
+
+ var div, span;
+
+ div = jQuery("<div class='hidden'>");
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
+
+ div = jQuery("<div style='display: none'>");
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
+
+ span = jQuery("<span class='hidden'/>");
+ span.show().appendTo("#qunit-fixture");
+ equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
+
+ span = jQuery("<span style='display: inline'/>");
+ span.show().appendTo("#qunit-fixture");
+ equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
+
+ div = jQuery("<div><div class='hidden'></div></div>").children("div");
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
+
+ div = jQuery("<div><div style='display: none'></div></div>").children("div");
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
+
+ div = jQuery("div.hidden");
+ div.detach().show();
+ equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
+ div.remove();
+
+ span = jQuery("<span>");
+ span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
+ equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
+ span.remove();
+
+ div = jQuery("<div>");
+ div.show().appendTo("#qunit-fixture");
+ ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
+
+ div = jQuery( document.createElement("div") );
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
+
+ div = jQuery("<div style='display: inline'/>");
+ div.show().appendTo("#qunit-fixture");
+ equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
+});
+
test("animate(Hash, Object, Function)", function() {
expect(1);
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 701956050..bb2d6ba9e 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -113,6 +113,7 @@ test("callbacks keep their place in the queue", function() {
div.promise("fx").done(function() {
equal(counter, 4, "Deferreds resolved");
+ jQuery.removeData( div[0], "olddisplay", true );
start();
});
});