aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2016-01-11 02:26:55 -0500
committerTimmy Willison <timmywillisn@gmail.com>2016-01-13 16:05:09 -0500
commitdba93f79c405373ec3a492fd0a4bf89b3136a6e6 (patch)
tree49aca78a21bb34ebb7d834a270c090b9de91522a /src
parenta268f5225cad9ab380494e61a10105cc9eb107e7 (diff)
downloadjquery-dba93f79c405373ec3a492fd0a4bf89b3136a6e6.tar.gz
jquery-dba93f79c405373ec3a492fd0a4bf89b3136a6e6.zip
CSS: Restore cascade-override behavior in .show
Fixes gh-2654 Fixes gh-2308 Close gh-2810 Ref 86419b10bfa5e3b71a7d416288ab806d47a31d1f
Diffstat (limited to 'src')
-rw-r--r--src/css/showHide.js44
-rw-r--r--src/effects.js13
2 files changed, 48 insertions, 9 deletions
diff --git a/src/css/showHide.js b/src/css/showHide.js
index 29e2d8bc8..9c62d5564 100644
--- a/src/css/showHide.js
+++ b/src/css/showHide.js
@@ -4,6 +4,31 @@ define( [
"../css/var/isHidden"
], function( jQuery, dataPriv, isHidden ) {
+var defaultDisplayMap = {};
+
+function getDefaultDisplay( elem ) {
+ var temp,
+ doc = elem.ownerDocument,
+ nodeName = elem.nodeName,
+ display = defaultDisplayMap[ nodeName ];
+
+ if ( display ) {
+ return display;
+ }
+
+ temp = doc.body.appendChild( doc.createElement( nodeName ) ),
+ display = jQuery.css( temp, "display" );
+
+ temp.parentNode.removeChild( temp );
+
+ if ( display === "none" ) {
+ display = "block";
+ }
+ defaultDisplayMap[ nodeName ] = display;
+
+ return display;
+}
+
function showHide( elements, show ) {
var display, elem,
values = [],
@@ -19,23 +44,30 @@ function showHide( elements, show ) {
display = elem.style.display;
if ( show ) {
- if ( display === "none" ) {
- // Restore a pre-hide() value if we have one
- values[ index ] = dataPriv.get( elem, "display" ) || "";
+ // Since we force visibility upon cascade-hidden elements, an immediate (and slow)
+ // check is required in this first loop unless we have a nonempty display value (either
+ // inline or about-to-be-restored)
+ if ( display === "none" ) {
+ values[ index ] = dataPriv.get( elem, "display" ) || null;
+ if ( !values[ index ] ) {
+ elem.style.display = "";
+ }
+ }
+ if ( elem.style.display === "" && jQuery.css( elem, "display" ) === "none" ) {
+ values[ index ] = getDefaultDisplay( elem );
}
} else {
if ( display !== "none" ) {
values[ index ] = "none";
- // Remember the value we're replacing
+ // Remember what we're overwriting
dataPriv.set( elem, "display", display );
}
}
}
- // Set the display of the elements in a second loop
- // to avoid the constant reflow
+ // Set the display of the elements in a second loop to avoid constant reflow
for ( index = 0; index < length; index++ ) {
if ( values[ index ] != null ) {
elements[ index ].style.display = values[ index ];
diff --git a/src/effects.js b/src/effects.js
index 64f9353ef..43162e1fb 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -154,9 +154,16 @@ function defaultPrefilter( elem, props, opts ) {
}
display = jQuery.css( elem, "display" );
if ( display === "none" ) {
- display = restoreDisplay || swap( elem, { "display": "" }, function() {
- return jQuery.css( elem, "display" );
- } );
+ if ( restoreDisplay ) {
+ display = restoreDisplay;
+ } else {
+
+ // Get nonempty value(s) by temporarily forcing visibility
+ showHide( [ elem ], true );
+ restoreDisplay = elem.style.display || restoreDisplay;
+ display = jQuery.css( elem, "display" );
+ showHide( [ elem ] );
+ }
}
// Animate inline elements as inline-block