diff options
author | anekos | 2014-12-24 17:24:10 +0900 |
---|---|---|
committer | anekos | 2014-12-24 17:24:55 +0900 |
commit | 6b4797c3f0fecdcaa3350e3baeeb918734aeb04b (patch) | |
tree | 96016430bc390eb938927a282e589993ac86f853 /_smooziee.js | |
parent | 5ea49671ec900d74aadc50a4df4414dcc6a187fb (diff) | |
download | vimperator-plugins-6b4797c3f0fecdcaa3350e3baeeb918734aeb04b.tar.bz2 |
Revert "Merge branch 'zoresvit-patch-1'"
Because the commit is not compatible for PUBLICS.smoothScrollBy.
This reverts commit 875ba15b1cd4b9498bf30118e2a24e78f49b86e0, reversing
changes made to 575223a51be0adbcd5e8d391dbfb6e755eb2caf8.
Diffstat (limited to '_smooziee.js')
-rw-r--r-- | _smooziee.js | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/_smooziee.js b/_smooziee.js index 42eb9e3..ae4915c 100644 --- a/_smooziee.js +++ b/_smooziee.js @@ -80,80 +80,68 @@ var INFO = xml` let self = liberator.plugins.smooziee = (function(){ + // Mappings {{{ mappings.addUserMap( [modes.NORMAL], ["j"], "Smooth scroll down", function(count){ - self.smoothScrollBy(getScrollAmount()); + self.smoothScrollBy(getScrollAmount() * (count || 1)); }, { count: true } - ); + ); mappings.addUserMap( [modes.NORMAL], ["k"], "Smooth scroll up", function(count){ - self.smoothScrollBy(getScrollAmount() * -1); + self.smoothScrollBy(getScrollAmount() * -(count || 1)); }, { count: true } - ); - - var next; - var win; - var interval; - + ); + // }}} + // PUBLIC {{{ var PUBLICS = { smoothScrollBy: function(moment) { win = Buffer.findScrollableWindow(); - interval = window.eval(liberator.globalVariables.smooth_scroll_interval || '30'); + interval = window.eval(liberator.globalVariables.smooziee_scroll_interval || '20'); + destY = win.scrollY + moment; clearTimeout(next); smoothScroll(moment); } } - function logBase(x, y) { - // Logarithm of arbitrary base `x` - return Math.log(y) / Math.log(x); - } - - function getScrollAmount() { - // see recognition of Fibonacci Numbers (here approximation is used) - // http://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers - phi = 1.618033; - sqrt5 = 2.236067; - fn = liberator.globalVariables.smooth_scroll_amount || '150' - n = Math.ceil(logBase(phi, (fn * sqrt5 + Math.sqrt(5 * Math.pow(fn, 2) + 4)) / 2)) - return window.eval(n); - } + // }}} + // PRIVATE {{{ + var next; + var destY; + var win; + var interval; - function fib(n){ - // see optimized Binet's formula for Fibonacci sequence - // http://en.wikipedia.org/wiki/Fibonacci_number#Closed_form_expression - phi = 1.618033; - sqrt5 = 2.236067; - return Math.floor((Math.pow(phi, n) / sqrt5) + 0.5) - } + function getScrollAmount() window.eval(liberator.globalVariables.smooziee_scroll_amount || '400'); function smoothScroll(moment) { - if (moment > 0) { - moment = moment - 1; - win.scrollBy(0, fib(Math.abs(moment))); - } else { - moment = moment + 1; - win.scrollBy(0, -fib(Math.abs(moment))); - } + if (moment > 0) + moment = Math.floor(moment / 2); + else + moment = Math.ceil(moment / 2); - if (moment == 0) - return; + win.scrollBy(0, moment); + if (Math.abs(moment) < 1) { + setTimeout(makeScrollTo(win.scrollX, destY), interval); + destY = null; + return; + } next = setTimeout(function() smoothScroll(moment), interval); } + function makeScrollTo(x, y) function() win.scrollTo(x, y); + // }}} return PUBLICS; })(); // vim: sw=2 ts=2 et si fdm=marker: |