diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2015-04-02 16:57:33 -0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2015-05-11 13:01:13 -0400 |
commit | 9df8bd205ab78308c34af70c934c42175e560e86 (patch) | |
tree | 4ad0faa80690df471d3b5edb3d0246a41ee9fc9a /src/css/showHide.js | |
parent | d18b64578859a6c28e2d4b92e558193f9db9b1d4 (diff) | |
download | jquery-9df8bd205ab78308c34af70c934c42175e560e86.tar.gz jquery-9df8bd205ab78308c34af70c934c42175e560e86.zip |
CSS: Ignore the CSS cascade in show()/hide()/etc.
Fixes gh-1767
Fixes gh-2071
Closes gh-2180
(cherry picked from commit 86419b10bfa5e3b71a7d416288ab806d47a31d1f)
Conflicts:
src/css.js
src/css/defaultDisplay.js
src/effects.js
test/data/testsuite.css
test/unit/css.js
test/unit/effects.js
Diffstat (limited to 'src/css/showHide.js')
-rw-r--r-- | src/css/showHide.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/css/showHide.js b/src/css/showHide.js new file mode 100644 index 000000000..f500f186f --- /dev/null +++ b/src/css/showHide.js @@ -0,0 +1,45 @@ +define([], function() { + +function showHide( elements, show ) { + var display, elem, + values = [], + index = 0, + length = elements.length; + + // Determine new display value for elements that need to change + for ( ; index < length; index++ ) { + elem = elements[ index ]; + if ( !elem.style ) { + continue; + } + + display = elem.style.display; + if ( show ) { + if ( display === "none" ) { + // Restore a pre-hide() value if we have one + values[ index ] = jQuery._data( elem, "display" ) || ""; + } + } else { + if ( display !== "none" ) { + values[ index ] = "none"; + + // Remember the value we're replacing + jQuery._data( elem, "display", display ); + } + } + } + + // Set the display of the elements in a second loop + // to avoid the constant reflow + for ( index = 0; index < length; index++ ) { + if ( values[ index ] != null ) { + elements[ index ].style.display = values[ index ]; + } + } + + return elements; +} + +return showHide; + +}); |