Skip to content

Commit

Permalink
Adds lightbox support, tweaks comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
paullewis committed Jul 15, 2016
1 parent d2b2cec commit 6a33c28
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lighthouse-core/driver/gatherers/interstitial.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ const Gather = require('./gather');
function getInterstitial() {
const viewportSize = window.outerWidth * window.outerHeight;

// Walk the tree of elements
// Walk the tree of elements...
const candidates = [...document.querySelectorAll('*')]
.filter(e => {
// Check for position fixed.
const computedStyle = window.getComputedStyle(e);
const isFixed = computedStyle.position === 'fixed';

// Check for nav elements.
const regExpNav = /menu|nav|sidebar|drawer/i;
const isNav = regExpNav.test(e.className) ||
regExpNav.test(e.id) ||
regExpNav.test(e.nodeName);
// Check for nav / drawer / lightbox elements, since these are typically okay.
const regExpValidOverlays = /menu|nav|sidebar|drawer|lightbox/i;
const isValidOverlay = regExpValidOverlays.test(e.className) ||
regExpValidOverlays.test(e.id) ||
regExpValidOverlays.test(e.nodeName);

// Get the size of the element.
const eBCR = e.getBoundingClientRect();
const size = eBCR.width * eBCR.height;
const isCoveringViewport = ((size / viewportSize) > 0.5);

// Check it's visible.
const isVisible = computedStyle.opacity > 0 && computedStyle.display !== 'none';

// Check it's clickable
// Check it's clickable.
const isClickable = computedStyle.pointerEvents !== 'none';

// Only allow through fixed, non-nav elements whose size makes them cover
// Only allow through fixed, non-nav/lightbox elements whose size makes them cover
// over 50% of the available viewport, and are visible and clickable.
return isClickable && isVisible && isFixed && !isNav && (size / viewportSize > 0.5);
return isClickable && isVisible && isFixed && !isValidOverlay && isCoveringViewport;
});

// __returnResults is injected by evaluateAsync for passing back the result.
Expand Down

0 comments on commit 6a33c28

Please sign in to comment.