// // _smooziee.js // // LICENSE: {{{ // Copyright (c) 2009 snaka // // distributable under the terms of an MIT-style license. // http://www.opensource.jp/licenses/mit-license.html // }}} // // PLUGIN INFO: {{{ var PLUGIN_INFO = smooziee At j,k key scrolling to be smooth. j,kキーでのスクロールをスムースに 2.0 2.1pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js snaka MIT style license 0.9.2 || 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 == - 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。 ]]> ; // }}} let self = liberator.plugins.smooziee = (function(){ // Mappings {{{ mappings.addUserMap( [modes.NORMAL], ["j"], "Smooth scroll down", function(){ self.smoothScrollBy(getScrollAmount()); } ); mappings.addUserMap( [modes.NORMAL], ["k"], "Smooth scroll up", function(){ self.smoothScrollBy(getScrollAmount() * -1); } ); // }}} // PUBLIC {{{ var PUBLICS = { smoothScrollBy: function(moment) { win = findScrollableWindow(); 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; var findScrollableWindow = liberator.eval('findScrollableWindow', buffer.scrollLines); 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(win.scrollX, 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: