aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoly Fentanes2014-05-20 04:12:20 -0400
committerRoly Fentanes2014-05-20 04:12:20 -0400
commitfe4cb4e4d6beb8f39fe122fcd30e34edd012c33f (patch)
tree0fd306202403bb39b56a3bdf09e4cc47bd1a1ad5
parent19e2bfe115cc34bc4fc59343ead4f40d075f7b20 (diff)
downloadvimium-fe4cb4e4d6beb8f39fe122fcd30e34edd012c33f.tar.bz2
get new element position for each scroll tested element
-rw-r--r--content_scripts/scroller.coffee26
1 files changed, 15 insertions, 11 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee
index 08ab14a1..f3c632b3 100644
--- a/content_scripts/scroller.coffee
+++ b/content_scripts/scroller.coffee
@@ -39,17 +39,17 @@ ensureScrollChange = (direction, changeFn) ->
loop
oldScrollValue = element[axisName]
changeFn(element, axisName)
+ break unless (element[axisName] == oldScrollValue && element != document.body)
lastElement = element
# we may have an orphaned element. if so, just scroll the body element.
element = element.parentElement || document.body
- break unless (lastElement[axisName] == oldScrollValue && lastElement != document.body)
# if the activated element has been scrolled completely offscreen, subsequent changes in its scroll
# position will not provide any more visual feedback to the user. therefore we deactivate it so that
# subsequent scrolls only move the parent element.
rect = activatedElement.getBoundingClientRect()
if (rect.bottom < 0 || rect.top > window.innerHeight || rect.right < 0 || rect.left > window.innerWidth)
- activatedElement = lastElement
+ activatedElement = element
# scroll the active element in :direction by :amount * :factor.
# :factor is needed because :amount can take on string values, which scrollBy converts to element dimensions.
@@ -65,12 +65,13 @@ root.scrollBy = (direction, amount, factor = 1) ->
if (!activatedElement || !isRendered(activatedElement))
activatedElement = document.body
- amount = getDimension activatedElement, direction, amount if Utils.isString amount
-
- amount *= factor
-
- if (amount != 0)
- ensureScrollChange direction, (element, axisName) -> element[axisName] += amount
+ ensureScrollChange direction, (element, axisName) ->
+ if Utils.isString amount
+ elementAmount = getDimension element, direction, amount
+ else
+ elementAmount = amount
+ elementAmount *= factor
+ element[axisName] += elementAmount
root.scrollTo = (direction, pos) ->
return unless document.body
@@ -78,9 +79,12 @@ root.scrollTo = (direction, pos) ->
if (!activatedElement || !isRendered(activatedElement))
activatedElement = document.body
- pos = getDimension activatedElement, direction, pos if Utils.isString pos
-
- ensureScrollChange direction, (element, axisName) -> element[axisName] = pos
+ ensureScrollChange direction, (element, axisName) ->
+ if Utils.isString pos
+ elementPos = getDimension element, direction, pos
+ else
+ elementPos = pos
+ element[axisName] = elementPos
# TODO refactor and put this together with the code in getVisibleClientRect
isRendered = (element) ->