From ecf52b948bcc7c9a28b5b2f93a0764868f09428e Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Tue, 5 Jan 2016 20:10:06 -0500 Subject: [PATCH] CSS: fix visible/hidden for IE6/7 --- src/css/hiddenVisibleSelectors.js | 26 ++++++++++++++++++++++---- src/css/support.js | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/css/hiddenVisibleSelectors.js b/src/css/hiddenVisibleSelectors.js index 46c2cb827..899b9eca4 100644 --- a/src/css/hiddenVisibleSelectors.js +++ b/src/css/hiddenVisibleSelectors.js @@ -5,14 +5,32 @@ define( [ "../css" ], function( jQuery, support ) { +function getDisplay( elem ) { + return elem.style && elem.style.display || jQuery.css( elem, "display" ); +} + +function filterHidden( elem ) { + while ( elem && elem.nodeType === 1 ) { + if ( getDisplay( elem ) === "none" || elem.type === "hidden" ) { + return true; + } + elem = elem.parentNode; + } + return false; +} + jQuery.expr.filters.hidden = function( elem ) { - return !jQuery.expr.filters.visible( elem ); + + // Support: Opera <= 12.12 + // Opera reports offsetWidths and offsetHeights less than zero on some elements + return support.reliableHiddenOffsets() ? + ( elem.offsetWidth <= 0 && elem.offsetHeight <= 0 && + !elem.getClientRects().length ) : + filterHidden( elem ); }; jQuery.expr.filters.visible = function( elem ) { - return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ) && - ( support.reliableHiddenOffsets() || - ( ( elem.style && elem.style.display ) || jQuery.css( elem, "display" ) ) !== "none" ); + return !jQuery.expr.filters.hidden( elem ); }; } ); diff --git a/src/css/support.js b/src/css/support.js index 97d6d4aa1..6ff4cb19f 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -159,7 +159,8 @@ define( [ div.innerHTML = "
t
"; contents = div.getElementsByTagName( "td" ); contents[ 0 ].style.cssText = "margin:0;border:0;padding:0;display:none"; - reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0; + reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0 && + contents[ 0 ].getClientRects().length === 0; if ( reliableHiddenOffsetsVal ) { contents[ 0 ].style.display = ""; contents[ 1 ].style.display = "none";