diff options
| author | Stephen Blott | 2014-12-19 08:35:03 +0000 |
|---|---|---|
| committer | Stephen Blott | 2014-12-19 08:35:03 +0000 |
| commit | ac2e1077107d72ef82e1424634aa86945696e6b4 (patch) | |
| tree | 71749e66f85c6fc304f5f6761b248c2eb7412dcb /content_scripts | |
| parent | 0506ea78ebcd003b47db4f5587e07251f7c8682b (diff) | |
| download | vimium-ac2e1077107d72ef82e1424634aa86945696e6b4.tar.bz2 | |
Initialize scroller to *largest* visible scrollable element.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/scroller.coffee | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee index 48b99cff..dec817a1 100644 --- a/content_scripts/scroller.coffee +++ b/content_scripts/scroller.coffee @@ -84,14 +84,17 @@ findScrollableElement = (element, direction, amount, factor) -> element = element.parentElement || document.body element -# On some pages, document.body is not scrollable. Here, we search the document for the first visible element -# which does scroll vertically. This is used to initialize activatedElement. See #1358. +# On some pages, document.body is not scrollable. Here, we search the document for the largest visible +# element which does scroll vertically. This is used to initialize activatedElement. See #1358. firstScrollableElement = (element=document.body) -> if doesScroll element, "y", 1, 1 element else - for child in element.children - return ele if DomUtils.getVisibleClientRect(child) and ele = firstScrollableElement child + children = ({element: child, rect: DomUtils.getVisibleClientRect(child)} for child in element.children) + children = children.filter (child) -> child.rect # Filter out non-visible elements. + children.map (child) -> child.area = child.rect.width * child.rect.height + for child in children.sort((a,b) -> b.area - a.area) # Largest to smallest by visible area. + return ele if ele = firstScrollableElement child.element null checkVisibility = (element) -> |
