diff options
author | Brendan Taylor <whateley@gmail.com> | 2011-03-06 09:28:07 -0700 |
---|---|---|
committer | Brendan Taylor <whateley@gmail.com> | 2011-03-06 09:28:07 -0700 |
commit | a0a11b1b1ad90a16641d0a87b0d43b1fabdabb08 (patch) | |
tree | acfdd1a79f390981512ecfd797609e5454c318af /examples | |
parent | bece24e3824d11c08fad9c6338f446ee29d4913f (diff) |
follow.js: hint wrapped links on their left end, not the left end of the bounding rectangle
Diffstat (limited to 'examples')
-rw-r--r-- | examples/data/scripts/follow.js | 24 |
1 files changed, 13 insertions, 11 deletions
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. |