Skip to content

Commit

Permalink
CSS: fix visible/hidden for IE6/7
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Jan 6, 2016
1 parent 9e2f55f commit ecf52b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/css/hiddenVisibleSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};

} );
3 changes: 2 additions & 1 deletion src/css/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ define( [
div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
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";
Expand Down

0 comments on commit ecf52b9

Please sign in to comment.