From 18fc62c3ddc554d6fd4bd7939d8e79ef88cea159 Mon Sep 17 00:00:00 2001 From: snaka Date: Sat, 21 Feb 2009 03:23:22 +0000 Subject: Add API function. 他のキーにマップしたりスクリプトから呼び出せるようにAPIを用意した git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30405 d0d07461-0603-4401-acd4-de1884942a52 --- _smooziee.js | 215 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 118 insertions(+), 97 deletions(-) (limited to '_smooziee.js') diff --git a/_smooziee.js b/_smooziee.js index 5a7cd28..00c0d3c 100644 --- a/_smooziee.js +++ b/_smooziee.js @@ -11,120 +11,141 @@ // PLUGIN INFO: {{{ var PLUGIN_INFO = -smooziee -At j,k key scrolling to be smooth. -j,kキーでのスクロールをスムースに -2.0 -2.0pre -http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js -snaka -MIT style license -0.9 -|| -let g:smooziee_scroll_amount="300" -let g:smooziee_scroll_interval="10" -||< - -== ToDo == - -]]> - -|| -let g:smooziee_scroll_amount="300" -let g:smooziee_scroll_interval="10" -||< - -== ToDo == -- 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。 - -]]> + smooziee + At j,k key scrolling to be smooth. + j,kキーでのスクロールをスムースに + 2.0 + 2.0pre + http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js + snaka + MIT style license + 0.9 + || + let g:smooziee_scroll_amount="300" + let g:smooziee_scroll_interval="10" + ||< + + == API == + >|| + smooziee.smoothScrollBy(amount); + ||< + Example. + >|| + :js liberator.plugins.smooziee.smoothScrollBy(600) + :js liberator.plugins.smooziee.smoothScrollBy(-600) + ||< + + == ToDo == + + ]]> + + || + let g:smooziee_scroll_amount="300" + let g:smooziee_scroll_interval="10" + ||< + + == API == + 他のキーにマップする場合やスクリプトから呼び出せるようAPIを用意してます。 + >|| + smooziee.smoothScrollBy(amount); + ||< + amountにはスクロール量(ピクセル)を指定してください。正の値で下方向へ負の値で上方向へスクロールします。 + + Example. + >|| + :js liberator.plugins.smooziee.smoothScrollBy(600) + :js liberator.plugins.smooziee.smoothScrollBy(-600) + ||< + + == ToDo == + - 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。 + + ]]> ; // }}} -(function(){ - // configurations - var scrollAmount = 400; - var interval = 20; - - // - // Private - // - var next = null; - var destY = null; - var win = null; - - function setup() { - win = window.content.window.wrappedJSObject; - scrollAmount = window.eval(liberator.globalVariables.smooziee_scroll_amount) || scrollAmount; - interval = window.eval(liberator.globalVariables.smooziee_scroll_interval) || interval; - } - - // direction : positive (down) / negative (up) - function smoothScroll(amount, direction) { - var moment = Math.floor(amount / 2); - win.scrollBy(0, moment * direction); - - if (moment < 1) { - setTimeout(makeScrollTo(0, destY), interval); - destY = null; - return; - } - next = setTimeout(function() smoothScroll(moment, direction), interval); - } - - function makeScrollTo(x, y) { - return function() { - win.scrollTo(x, y); - }; - } +let self = liberator.plugins.smooziee = (function(){ - // - // Mappings - // + // Mappings {{{ mappings.addUserMap( [modes.NORMAL], ["j"], "Smooth scroll down", function(){ - setup(); - destY = win.scrollY + scrollAmount; - clearTimeout(next); - smoothScroll(scrollAmount, 1); + self.smoothScrollBy(getScrollAmount()); } ); - mappings.addUserMap( [modes.NORMAL], ["k"], "Smooth scroll up", function(){ - setup(); - destY = win.scrollY - scrollAmount; - clearTimeout(next); - smoothScroll(scrollAmount, -1); + self.smoothScrollBy(getScrollAmount() * -1); } ); + // }}} + // PUBLIC {{{ + var PUBLICS = { + smoothScrollBy: function(moment) { + win = window.content.window.wrappedJSObject; + interval = window.eval(liberator.globalVariables.smooziee_scroll_interval) || 20; + destY = win.scrollY + moment; + clearTimeout(next); + smoothScroll(moment); + } + } + + // }}} + // PRIVATE {{{ + var next; + var destY; + var win; + var interval; + + function getScrollAmount() window.eval(liberator.globalVariables.smooziee_scroll_amount) || 400; + + function smoothScroll(moment) { + if (moment > 0) + moment = Math.floor(moment / 2); + else + moment = Math.ceil(moment / 2); + + win.scrollBy(0, moment); + + if (Math.abs(moment) < 1) { + setTimeout(makeScrollTo(0, 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: -- cgit v1.2.3