diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2016-04-04 09:58:14 -0400 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2016-04-11 13:21:11 -0400 |
commit | 755e7ccf018eb150eddefe78063a9ec58b3229e3 (patch) | |
tree | a54c23d4201838b82d2687218992d39bee226b3c /src/css/var/isHiddenWithinTree.js | |
parent | ce6c83f710c28108ccb4d50a7b924baa890dc961 (diff) | |
download | jquery-755e7ccf018eb150eddefe78063a9ec58b3229e3.tar.gz jquery-755e7ccf018eb150eddefe78063a9ec58b3229e3.zip |
CSS: Toggle detached elements as visible unless they have display: none
Fixes gh-2863
Closes gh-3037
Diffstat (limited to 'src/css/var/isHiddenWithinTree.js')
-rw-r--r-- | src/css/var/isHiddenWithinTree.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/css/var/isHiddenWithinTree.js b/src/css/var/isHiddenWithinTree.js index 1c81f6480..c01d228d8 100644 --- a/src/css/var/isHiddenWithinTree.js +++ b/src/css/var/isHiddenWithinTree.js @@ -5,14 +5,29 @@ define( [ // css is assumed ], function( jQuery ) { - // This function differs from the :hidden selector - // in that it intentionally ignores hidden ancestors (gh-2404) + // isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or + // through the CSS cascade), which is useful in deciding whether or not to make it visible. + // It differs from the :hidden selector (jQuery.expr.pseudos.hidden) in two important ways: + // * A hidden ancestor does not force an element to be classified as hidden. + // * Being disconnected from the document does not force an element to be classified as hidden. + // These differences improve the behavior of .toggle() et al. when applied to elements that are + // detached or contained within hidden ancestors (gh-2404, gh-2863). return function( elem, el ) { // isHiddenWithinTree might be called from jQuery#filter function; // in that case, element will be second argument elem = el || elem; - return jQuery.css( elem, "display" ) === "none" || - !jQuery.contains( elem.ownerDocument, elem ); + + // Inline style trumps all + return elem.style.display === "none" || + elem.style.display === "" && + + // Otherwise, check computed style + // Support: Firefox <=43 - 45 + // Disconnected elements can have computed display: none, so first confirm that elem is + // in the document. + jQuery.contains( elem.ownerDocument, elem ) && + + jQuery.css( elem, "display" ) === "none"; }; } ); |