From 3ae96d00eca10ab3ac8c7e591cc2fc7ce0351504 Mon Sep 17 00:00:00 2001 From: snaka Date: Tue, 10 Feb 2009 16:53:21 +0000 Subject: Add _smooziee.js plugin to repository. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@29882 d0d07461-0603-4401-acd4-de1884942a52 --- _smooziee.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 _smooziee.js (limited to '_smooziee.js') diff --git a/_smooziee.js b/_smooziee.js new file mode 100644 index 0000000..612b589 --- /dev/null +++ b/_smooziee.js @@ -0,0 +1,112 @@ +// +// _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: -- cgit v1.2.3