From a0a11b1b1ad90a16641d0a87b0d43b1fabdabb08 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sun, 6 Mar 2011 09:28:07 -0700 Subject: follow.js: hint wrapped links on their left end, not the left end of the bounding rectangle --- examples/data/scripts/follow.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index 2b9da59..536256b 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -67,19 +67,21 @@ uzbl.follow.query = function(selector) { // Calculate element position to draw the hint uzbl.follow.elementPosition = function(el) { - var rect = el.getBoundingClientRect(); - - var left, up; - - if (uzbl.follow.isFrame(el)) { - left = document.defaultView.scrollX; - up = document.defaultView.scrollY; - } else { - left = Math.max((rect.left + document.defaultView.scrollX), document.defaultView.scrollX); - up = Math.max((rect.top + document.defaultView.scrollY), document.defaultView.scrollY); + // el.getBoundingClientRect is another way to do this, but when a link is + // line-wrapped we want our hint at the left end of the link, not its + // bounding rectangle + var up = el.offsetTop; + var left = el.offsetLeft; + var width = el.offsetWidth; + var height = el.offsetHeight; + + while (el.offsetParent) { + el = el.offsetParent; + up += el.offsetTop; + left += el.offsetLeft; } - return [up, left, rect.width, rect.height]; + return [up, left, width, height]; } // Calculate if an element is on the viewport. -- cgit v1.2.3