Skip to content

Commit

Permalink
Don't calculate intersectRatio again. (#5965)
Browse files Browse the repository at this point in the history
  • Loading branch information
lannka committed Nov 2, 2016
1 parent b9fd302 commit 72923f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion extensions/amp-analytics/0.1/test/test-visibility-impl.js
Expand Up @@ -86,10 +86,14 @@ describe('amp-analytics.visibility', () => {
function makeIntersectionEntry(boundingClientRect, rootBounds) {
boundingClientRect = layoutRectLtwh.apply(null, boundingClientRect);
rootBounds = layoutRectLtwh.apply(null, rootBounds);
const intersect = rectIntersection(boundingClientRect, rootBounds);
const ratio = (intersect.width * intersect.height)
/ (boundingClientRect.width * boundingClientRect.height);
return {
intersectionRect: rectIntersection(boundingClientRect, rootBounds),
intersectionRect: intersect,
boundingClientRect,
rootBounds,
intersectionRatio: ratio,
};
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/visibility-impl.js
Expand Up @@ -331,8 +331,8 @@ export class Visibility {
const change = res.element.getIntersectionChangeEntry();
const ir = change.intersectionRect;
const br = change.boundingClientRect;
const visible = br.height * br.width == 0 ? 0 :
ir.width * ir.height * 100 / (br.height * br.width);
const visible =
isNaN(change.intersectionRatio) ? 0 : change.intersectionRatio * 100;

const listeners = this.listeners_[res.getId()];
for (let c = listeners.length - 1; c >= 0; c--) {
Expand Down

0 comments on commit 72923f1

Please sign in to comment.