Skip to content

Commit

Permalink
Fix #118: Incorporate review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
biancadanforth committed Aug 9, 2019
1 parent cfd7a50 commit c912f13
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions utilsForFrontend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,9 @@ export function sigmoid(x) {
/**
* Return whether an element is practically visible, considering things like 0
* size or opacity, ``visibility: hidden`` and ``overflow: hidden``.
*
* This could be 5x more efficient if https://github.com/w3c/csswg-drafts/issues/4122
* happens.
*/
export function isVisible(fnodeOrElement) {
// This could be 5x more efficient if https://github.com/w3c/csswg-drafts/issues/4122 happens.
const element = toDomElement(fnodeOrElement);
// Avoid reading ``display: none`` due to Bug 1381071
const elementRect = element.getBoundingClientRect();
Expand All @@ -475,7 +473,14 @@ export function isVisible(fnodeOrElement) {
if (elementStyle.visibility === 'hidden') {
return false;
}
// Check if the element is off-screen
const frame = element.ownerDocument.defaultView;
if (elementRect.x + elementRect.width < 0
|| (elementRect.y + elementRect.height) < 0
|| (elementRect.x > frame.innerWidth || elementRect.y > frame.innerHeight)
) {
return false;
}
for (const ancestor of ancestors(element)) {
const isElement = ancestor === element;
const style = isElement ? elementStyle : getComputedStyle(ancestor);
Expand All @@ -493,10 +498,6 @@ export function isVisible(fnodeOrElement) {
// has overflow: hidden
return false;
}
// Check if the element is off-screen
if (isElement && ((rect.right + frame.scrollX < 0) || (rect.bottom + frame.scrollY < 0))) {
return false;
}
}
return true;
}
Expand Down

0 comments on commit c912f13

Please sign in to comment.