Permalink
Browse files

CSS: Restore cascade-override behavior in .show

Fixes gh-2654
Fixes gh-2308
Close gh-2810
Ref 86419b1
  • Loading branch information...
1 parent a268f52 commit dba93f79c405373ec3a492fd0a4bf89b3136a6e6 @gibson042 gibson042 committed with Timmy Willison Jan 11, 2016
Showing with 391 additions and 116 deletions.
  1. +38 −6 src/css/showHide.js
  2. +10 −3 src/effects.js
  3. +5 −9 test/data/testsuite.css
  4. +253 −22 test/unit/css.js
  5. +85 −76 test/unit/effects.js
View
@@ -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 ];
View
@@ -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
@@ -20,10 +20,6 @@ div#fx-tests div.overflow {
overflow: visible;
}
-div.inline {
- display: inline;
-}
-
div.autoheight {
height: auto;
}
@@ -68,11 +64,6 @@ div.noopacity {
opacity: 0;
}
-div.hidden,
-span.hidden {
- display: none;
-}
-
div#fx-tests div.widewidth {
background-repeat: repeat-x;
}
@@ -134,3 +125,8 @@ section { background:#f0f; display:block; }
#span-14824 { display: block; }
#display { display: list-item !important; }
+
+.block { display: block; }
+.inline { display: inline; }
+.list-item { display: list-item; }
+.hidden, .none { display: none; }
Oops, something went wrong.

0 comments on commit dba93f7

Please sign in to comment.