isHiddenWithinTree.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. define( [
  2. "../../core",
  3. "../../selector"
  4. // css is assumed
  5. ], function( jQuery ) {
  6. "use strict";
  7. // isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or
  8. // through the CSS cascade), which is useful in deciding whether or not to make it visible.
  9. // It differs from the :hidden selector (jQuery.expr.pseudos.hidden) in two important ways:
  10. // * A hidden ancestor does not force an element to be classified as hidden.
  11. // * Being disconnected from the document does not force an element to be classified as hidden.
  12. // These differences improve the behavior of .toggle() et al. when applied to elements that are
  13. // detached or contained within hidden ancestors (gh-2404, gh-2863).
  14. return function( elem, el ) {
  15. // isHiddenWithinTree might be called from jQuery#filter function;
  16. // in that case, element will be second argument
  17. elem = el || elem;
  18. // Inline style trumps all
  19. return elem.style.display === "none" ||
  20. elem.style.display === "" &&
  21. // Otherwise, check computed style
  22. // Support: Firefox <=43 - 45
  23. // Disconnected elements can have computed display: none, so first confirm that elem is
  24. // in the document.
  25. jQuery.contains( elem.ownerDocument, elem ) &&
  26. jQuery.css( elem, "display" ) === "none";
  27. };
  28. } );