| 1 | // |
|---|
| 2 | // _smooziee.js |
|---|
| 3 | // |
|---|
| 4 | // LICENSE: {{{ |
|---|
| 5 | // Copyright (c) 2009 snaka<snaka.gml@gmail.com> |
|---|
| 6 | // |
|---|
| 7 | // distributable under the terms of an MIT-style license. |
|---|
| 8 | // http://www.opensource.jp/licenses/mit-license.html |
|---|
| 9 | // }}} |
|---|
| 10 | // |
|---|
| 11 | // PLUGIN INFO: {{{ |
|---|
| 12 | var PLUGIN_INFO = |
|---|
| 13 | <VimperatorPlugin> |
|---|
| 14 | <name>smooziee</name> |
|---|
| 15 | <description>At j,k key scrolling to be smooth.</description> |
|---|
| 16 | <description lang="ja">j,kキーでのスクロールをスムースに</description> |
|---|
| 17 | <minVersion>2.3pre</minVersion> |
|---|
| 18 | <maxVersion>2.3</maxVersion> |
|---|
| 19 | <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_smooziee.js</updateURL> |
|---|
| 20 | <author mail="snaka.gml@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/snaka72/">snaka</author> |
|---|
| 21 | <license>MIT style license</license> |
|---|
| 22 | <version>0.10.1</version> |
|---|
| 23 | <detail><![CDATA[ |
|---|
| 24 | == Subject == |
|---|
| 25 | j,k key scrolling to be smoothly. |
|---|
| 26 | |
|---|
| 27 | == Global variables == |
|---|
| 28 | You can configure following variable as you like. |
|---|
| 29 | :smooziee_scroll_amount: Scrolling amount(unit:px). Default value is 400px. |
|---|
| 30 | :smooziee_interval: Scrolling interval(unit:ms). Default value is 20ms. |
|---|
| 31 | |
|---|
| 32 | === Excample === |
|---|
| 33 | Set scroll amount is 300px and interval is 10ms. |
|---|
| 34 | >|| |
|---|
| 35 | let g:smooziee_scroll_amount="300" |
|---|
| 36 | let g:smooziee_scroll_interval="10" |
|---|
| 37 | ||< |
|---|
| 38 | |
|---|
| 39 | == API == |
|---|
| 40 | >|| |
|---|
| 41 | smooziee.smoothScrollBy(amount); |
|---|
| 42 | ||< |
|---|
| 43 | Example. |
|---|
| 44 | >|| |
|---|
| 45 | :js liberator.plugins.smooziee.smoothScrollBy(600) |
|---|
| 46 | :js liberator.plugins.smooziee.smoothScrollBy(-600) |
|---|
| 47 | ||< |
|---|
| 48 | |
|---|
| 49 | == ToDo == |
|---|
| 50 | |
|---|
| 51 | ]]></detail> |
|---|
| 52 | |
|---|
| 53 | <detail lang="ja"><![CDATA[ |
|---|
| 54 | == 概要 == |
|---|
| 55 | 普段のj,kキーのスクロールをLDRizeライクにスムースにします。 |
|---|
| 56 | |
|---|
| 57 | == グローバル変数 == |
|---|
| 58 | 以下の変数を.vimperatorrcなどで設定することで動作を調整することができます。 |
|---|
| 59 | :smooziee_scroll_amount: |
|---|
| 60 | 1回にスクロールする幅です(単位:ピクセル)。デフォルトは"400"です。 |
|---|
| 61 | :smooziee_interval: |
|---|
| 62 | スクロール時のアニメーションのインターバルです(単位:ミリ秒)。 |
|---|
| 63 | "1"以上の値を設定します。デフォルトは"20"です。 |
|---|
| 64 | === 設定例 === |
|---|
| 65 | スクロール量を300pxに、インターバルを10msに設定します。 |
|---|
| 66 | >|| |
|---|
| 67 | let g:smooziee_scroll_amount="300" |
|---|
| 68 | let g:smooziee_scroll_interval="10" |
|---|
| 69 | ||< |
|---|
| 70 | |
|---|
| 71 | == API == |
|---|
| 72 | 他のキーにマップする場合やスクリプトから呼び出せるようAPIを用意してます。 |
|---|
| 73 | >|| |
|---|
| 74 | smooziee.smoothScrollBy(amount); |
|---|
| 75 | ||< |
|---|
| 76 | amountにはスクロール量(ピクセル)を指定してください。正の値で下方向へ負の値で上方向へスクロールします。 |
|---|
| 77 | |
|---|
| 78 | Example. |
|---|
| 79 | >|| |
|---|
| 80 | :js liberator.plugins.smooziee.smoothScrollBy(600) |
|---|
| 81 | :js liberator.plugins.smooziee.smoothScrollBy(-600) |
|---|
| 82 | ||< |
|---|
| 83 | |
|---|
| 84 | == ToDo == |
|---|
| 85 | - 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。 |
|---|
| 86 | |
|---|
| 87 | ]]></detail> |
|---|
| 88 | </VimperatorPlugin>; |
|---|
| 89 | // }}} |
|---|
| 90 | |
|---|
| 91 | let self = liberator.plugins.smooziee = (function(){ |
|---|
| 92 | |
|---|
| 93 | // Mappings {{{ |
|---|
| 94 | mappings.addUserMap( |
|---|
| 95 | [modes.NORMAL], |
|---|
| 96 | ["j"], |
|---|
| 97 | "Smooth scroll down", |
|---|
| 98 | function(count){ |
|---|
| 99 | self.smoothScrollBy(getScrollAmount() * (count || 1)); |
|---|
| 100 | }, |
|---|
| 101 | { |
|---|
| 102 | count: true |
|---|
| 103 | } |
|---|
| 104 | ); |
|---|
| 105 | mappings.addUserMap( |
|---|
| 106 | [modes.NORMAL], |
|---|
| 107 | ["k"], |
|---|
| 108 | "Smooth scroll up", |
|---|
| 109 | function(count){ |
|---|
| 110 | self.smoothScrollBy(getScrollAmount() * -(count || 1)); |
|---|
| 111 | }, |
|---|
| 112 | { |
|---|
| 113 | count: true |
|---|
| 114 | } |
|---|
| 115 | ); |
|---|
| 116 | // }}} |
|---|
| 117 | // PUBLIC {{{ |
|---|
| 118 | var PUBLICS = { |
|---|
| 119 | smoothScrollBy: function(moment) { |
|---|
| 120 | win = Buffer.findScrollableWindow(); |
|---|
| 121 | interval = window.eval(liberator.globalVariables.smooziee_scroll_interval) || 20; |
|---|
| 122 | destY = win.scrollY + moment; |
|---|
| 123 | clearTimeout(next); |
|---|
| 124 | smoothScroll(moment); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | // }}} |
|---|
| 129 | // PRIVATE {{{ |
|---|
| 130 | var next; |
|---|
| 131 | var destY; |
|---|
| 132 | var win; |
|---|
| 133 | var interval; |
|---|
| 134 | |
|---|
| 135 | function getScrollAmount() window.eval(liberator.globalVariables.smooziee_scroll_amount) || 400; |
|---|
| 136 | |
|---|
| 137 | function smoothScroll(moment) { |
|---|
| 138 | if (moment > 0) |
|---|
| 139 | moment = Math.floor(moment / 2); |
|---|
| 140 | else |
|---|
| 141 | moment = Math.ceil(moment / 2); |
|---|
| 142 | |
|---|
| 143 | win.scrollBy(0, moment); |
|---|
| 144 | |
|---|
| 145 | if (Math.abs(moment) < 1) { |
|---|
| 146 | setTimeout(makeScrollTo(win.scrollX, destY), interval); |
|---|
| 147 | destY = null; |
|---|
| 148 | return; |
|---|
| 149 | } |
|---|
| 150 | next = setTimeout(function() smoothScroll(moment), interval); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | function makeScrollTo(x, y) function() win.scrollTo(x, y); |
|---|
| 154 | // }}} |
|---|
| 155 | return PUBLICS; |
|---|
| 156 | })(); |
|---|
| 157 | // vim: sw=2 ts=2 et si fdm=marker: |
|---|