aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhil Crosby2014-04-18 23:00:28 -0700
committerPhil Crosby2014-04-18 23:00:28 -0700
commit5ebc1aa78ba595e3753e00c3d912d9e45e310e7f (patch)
tree745db32693b9a2a8122c727be385b0d44e04c676 /lib
parent366c0a56a4eed38fa8425fd227cd389181fbed92 (diff)
parent004f9a119d15d1b7e96ba50c1fec2c56b052a5b8 (diff)
downloadvimium-5ebc1aa78ba595e3753e00c3d912d9e45e310e7f.tar.bz2
Merge pull request #945 from shyiko/master
Fixed detection of links which are only partially inside the viewport
Diffstat (limited to 'lib')
-rw-r--r--lib/dom_utils.coffee16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 38b23202..70e52a6c 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -46,11 +46,21 @@ DomUtils =
#
getVisibleClientRect: (element) ->
# Note: this call will be expensive if we modify the DOM in between calls.
- clientRects = element.getClientRects()
+ clientRects = ({
+ top: clientRect.top, right: clientRect.right, bottom: clientRect.bottom, left: clientRect.left,
+ width: clientRect.width, height: clientRect.height
+ } for clientRect in element.getClientRects())
for clientRect in clientRects
- if (clientRect.top < -2 || clientRect.top >= window.innerHeight - 4 ||
- clientRect.left < -2 || clientRect.left >= window.innerWidth - 4)
+ if (clientRect.top < 0)
+ clientRect.height += clientRect.top
+ clientRect.top = 0
+
+ if (clientRect.left < 0)
+ clientRect.width += clientRect.left
+ clientRect.left = 0
+
+ if (clientRect.top >= window.innerHeight - 4 || clientRect.left >= window.innerWidth - 4)
continue
if (clientRect.width < 3 || clientRect.height < 3)