From ac2e1077107d72ef82e1424634aa86945696e6b4 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 19 Dec 2014 08:35:03 +0000 Subject: Initialize scroller to *largest* visible scrollable element. --- content_scripts/scroller.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'content_scripts') 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) -> -- cgit v1.2.3