aboutsummaryrefslogtreecommitdiffstats
path: root/_smooziee.js
diff options
context:
space:
mode:
authorsnaka2009-02-21 03:23:22 +0000
committersnaka2009-02-21 03:23:22 +0000
commit18fc62c3ddc554d6fd4bd7939d8e79ef88cea159 (patch)
tree8bcb06b6891d4f493856901ef1aab279e6c7d984 /_smooziee.js
parent77382ad8b9417c4e1b546f4f9ef1ce9243d5dfd5 (diff)
downloadvimperator-plugins-18fc62c3ddc554d6fd4bd7939d8e79ef88cea159.tar.bz2
Add API function.
他のキーにマップしたりスクリプトから呼び出せるようにAPIを用意した git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30405 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to '_smooziee.js')
-rw-r--r--_smooziee.js215
1 files changed, 118 insertions, 97 deletions
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 =
<VimperatorPlugin>
-<name>smooziee</name>
-<description>At j,k key scrolling to be smooth.</description>
-<description lang="ja">j,kキーでのスクロールをスムースに</description>
-<minVersion>2.0</minVersion>
-<maxVersion>2.0pre</maxVersion>
-<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js</updateURL>
-<author mail="snaka.gml@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/snaka72/">snaka</author>
-<license>MIT style license</license>
-<version>0.9</version>
-<detail><![CDATA[
-== Subject ==
-j,k key scrolling to be smoothly.
-
-== Global variables ==
-You can configure following variable as you like.
-:smooziee_scroll_amount: Scrolling amount(unit:px). Default value is 400px.
-:smooziee_interval: Scrolling interval(unit:ms). Default value is 20ms.
-
-=== Excample ===
-Set scroll amount is 300px and interval is 10ms.
->||
-let g:smooziee_scroll_amount="300"
-let g:smooziee_scroll_interval="10"
-||<
-
-== ToDo ==
-
-]]></detail>
-
-<detail lang="ja"><![CDATA[
-== 概要 ==
-普段のj,kキーのスクロールをLDRizeライクにスムースにします。
-
-== グローバル変数 ==
-以下の変数を.vimperatorrcなどで設定することで動作を調整することができます。
-以下の変数を.vimperatorrcなどで設定することで動作を調整することができます。
-:smooziee_scroll_amount:1回にスクロールする幅です(単位:ピクセル)。デフォルトは"400"です。
-:smooziee_interval:スクロール時のアニメーションのインターバルです(単位:ミリ秒)。"1"以上の値を設定します。デフォルトは"20"です。
-=== 設定例 ===
-スクロール量を300pxに、インターバルを10msに設定します。
->||
-let g:smooziee_scroll_amount="300"
-let g:smooziee_scroll_interval="10"
-||<
-
-== ToDo ==
-- 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。
-
-]]></detail>
+ <name>smooziee</name>
+ <description>At j,k key scrolling to be smooth.</description>
+ <description lang="ja">j,kキーでのスクロールをスムースに</description>
+ <minVersion>2.0</minVersion>
+ <maxVersion>2.0pre</maxVersion>
+ <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js</updateURL>
+ <author mail="snaka.gml@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/snaka72/">snaka</author>
+ <license>MIT style license</license>
+ <version>0.9</version>
+ <detail><![CDATA[
+ == Subject ==
+ j,k key scrolling to be smoothly.
+
+ == Global variables ==
+ You can configure following variable as you like.
+ :smooziee_scroll_amount: Scrolling amount(unit:px). Default value is 400px.
+ :smooziee_interval: Scrolling interval(unit:ms). Default value is 20ms.
+
+ === Excample ===
+ Set scroll amount is 300px and interval is 10ms.
+ >||
+ 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 ==
+
+ ]]></detail>
+
+ <detail lang="ja"><![CDATA[
+ == 概要 ==
+ 普段のj,kキーのスクロールをLDRizeライクにスムースにします。
+
+ == グローバル変数 ==
+ 以下の変数を.vimperatorrcなどで設定することで動作を調整することができます。
+ :smooziee_scroll_amount:
+ 1回にスクロールする幅です(単位:ピクセル)。デフォルトは"400"です。
+ :smooziee_interval:
+ スクロール時のアニメーションのインターバルです(単位:ミリ秒)。
+ "1"以上の値を設定します。デフォルトは"20"です。
+ === 設定例 ===
+ スクロール量を300pxに、インターバルを10msに設定します。
+ >||
+ 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 ==
+ - 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。
+
+ ]]></detail>
</VimperatorPlugin>;
// }}}
-(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: