diff options
| author | Phil Crosby | 2014-12-16 10:04:35 -0800 |
|---|---|---|
| committer | Phil Crosby | 2014-12-16 10:04:35 -0800 |
| commit | 902a1f64fe5a22902b80f7e85bed91f8cdc0e57b (patch) | |
| tree | 236caa30d910e07160e9383638cfc935572e6d0e | |
| parent | a36a735fca856bb59dd62b6bc77c56431cc9b9fd (diff) | |
| parent | 5583e0f6921c8bc01fe701bf3c74ef34c4244f4a (diff) | |
| download | vimium-902a1f64fe5a22902b80f7e85bed91f8cdc0e57b.tar.bz2 | |
Merge pull request #1336 from smblott-github/do-not-use-math.sign
Do not use Math.sign().
| -rw-r--r-- | content_scripts/scroller.coffee | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee index a2617289..09470158 100644 --- a/content_scripts/scroller.coffee +++ b/content_scripts/scroller.coffee @@ -4,6 +4,13 @@ # activatedElement = null +# Return 0, -1 or 1: the sign of the argument. +getSign = (val) -> + if not val + 0 + else + if val < 0 then -1 else 1 + scrollProperties = x: { axisName: 'scrollLeft' @@ -63,7 +70,7 @@ doesScroll = (element, direction, amount, factor) -> # we're definitely scrolling forwards, so any positive value will do for delta. In the latter, we're # definitely scrolling backwards, so a delta of -1 will do. For absolute scrolls, factor is always 1. delta = factor * getDimension(element, direction, amount) || -1 - delta = Math.sign delta # 1 or -1 + delta = getSign delta # 1 or -1 performScroll(element, direction, delta) and performScroll(element, direction, -delta) # From element and its parents, find the first which we should scroll and which does scroll. @@ -136,7 +143,7 @@ CoreScroller = myKeyIsStillDown = => @time == activationTime and @keyIsDown # Store amount's sign and make amount positive; the arithmetic is clearer when amount is positive. - sign = Math.sign amount + sign = getSign amount amount = Math.abs amount # Initial intended scroll duration (in ms). We allow a bit longer for longer scrolls. |
