// // _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.0pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js snaka MIT style license 0.9 ; // }}} (function(){ // configurations var scrollAmount = window.eval(liberator.globalVariables.smooziee_scroll_amount || 400); var interval = window.eval(liberator.globalVariables.smooziee_interval || 20); // // Private // var next = null; var destY = null; var win = function() window.content.window.wrappedJSObject; // 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 resetDestination() { clearTimeout(next); } function makeScrollTo(x, y) { return function() { win().scrollTo(x, y); }; } // // Mappings // mappings.addUserMap( [modes.NORMAL], ["j"], "Smooth scroll down", function(){ destY = win().scrollY + scrollAmount; resetDestination(); smoothScroll(scrollAmount, 1); } ); mappings.addUserMap( [modes.NORMAL], ["k"], "Smooth scroll up", function(){ destY = win().scrollY - scrollAmount; resetDestination(); smoothScroll(scrollAmount, -1); } ); })(); // vim: sw=2 ts=2 et si fdm=marker: