aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/showHide.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2015-04-02 16:57:33 -0400
committerRichard Gibson <richard.gibson@gmail.com>2015-05-11 13:00:49 -0400
commit86419b10bfa5e3b71a7d416288ab806d47a31d1f (patch)
tree0e67bab0273e904df2f308ab26980291ec22adeb /src/css/showHide.js
parent5c3101fee60046fa7976b3131fada8dfe9fbd53e (diff)
downloadjquery-86419b10bfa5e3b71a7d416288ab806d47a31d1f.tar.gz
jquery-86419b10bfa5e3b71a7d416288ab806d47a31d1f.zip
CSS: Ignore the CSS cascade in show()/hide()/etc.
Fixes gh-1767 Fixes gh-2071 Closes gh-2180
Diffstat (limited to 'src/css/showHide.js')
-rw-r--r--src/css/showHide.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/css/showHide.js b/src/css/showHide.js
new file mode 100644
index 000000000..d0cca589b
--- /dev/null
+++ b/src/css/showHide.js
@@ -0,0 +1,47 @@
+define([
+ "../data/var/dataPriv"
+], function( dataPriv ) {
+
+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 ] = dataPriv.get( elem, "display" ) || "";
+ }
+ } else {
+ if ( display !== "none" ) {
+ values[ index ] = "none";
+
+ // Remember the value we're replacing
+ dataPriv.set( 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;
+
+});