aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/scroller.coffee11
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) ->