Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Update isVisible to check for clickability
Browse files Browse the repository at this point in the history
Also moved `getHighestScoringImage` up, as I was getting an undefined error otherwise. I guess there were some changes to function hoisting in the JavaScript engine recently?
  • Loading branch information
biancadanforth committed Jul 24, 2019
1 parent 83c1ea4 commit 3f59006
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/extraction/fathom/ruleset_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import {dom, out, rule, ruleset, score, type} from 'fathom-web';
import {ancestors} from 'fathom-web/utilsForFrontend';
import {euclidean} from 'fathom-web/clusters';

const TOP_BUFFER = 150;
Expand All @@ -16,6 +15,10 @@ const ONEISH = 0.9;
* easier testing.
*/
export default class RulesetFactory {
getHighestScoringImage(fnode) {
return fnode._ruleset.get('image')[0]; // eslint-disable-line no-underscore-dangle
}

/** Scores fnode in direct proportion to its size */
isBig(fnode) {
const domRect = fnode.element.getBoundingClientRect();
Expand Down Expand Up @@ -196,20 +199,26 @@ export default class RulesetFactory {
}

isVisible(fnode) {
for (const ancestor of ancestors(fnode.element)) {
const style = getComputedStyle(ancestor);
const isElementHidden = (
style.visibility === 'hidden'
|| style.display === 'none'
|| style.opacity === '0'
|| style.width === '0'
|| style.height === '0'
);
if (isElementHidden) {
return false;
}
const element = fnode.element;
const rect = element.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) {
return false;
}
return true;
const style = getComputedStyle(element);
if (style.opacity === '0') {
return false;
}
// workaround for https://github.com/w3c/csswg-drafts/issues/4122
const scrollX = window.pageXOffset;
const scrollY = window.pageYOffset;
const absX = rect.x + scrollX;
const absY = rect.y + scrollY;
window.scrollTo(absX, absY);
const newX = absX - window.pageXOffset;
const newY = absY - window.pageYOffset;
const eles = document.elementsFromPoint(newX, newY);
window.scrollTo(scrollX, scrollY);
return eles.includes(element);
}

hasBackgroundImage(fnode) {
Expand Down Expand Up @@ -306,10 +315,6 @@ export default class RulesetFactory {
coeffs,
biases);
}

getHighestScoringImage(fnode) {
return fnode._ruleset.get('image')[0]; // eslint-disable-line no-underscore-dangle
}
}

/**
Expand Down

0 comments on commit 3f59006

Please sign in to comment.