aboutsummaryrefslogtreecommitdiffstats
path: root/ubiquity.js
AgeCommit message (Expand)Author
2009-08-27Follow HEADanekos
2008-11-262.0pre補完対応修正が24時点のものだったので再度修正pekepeke
2008-11-262.0pre補完対応pekepeke
2008-11-12 * fixed regexes.drry
2008-11-10bug fix - 2.0preにちゃんと対応できてなかったので、ちゃん...pekepeke
2008-11-052.0pre対応pekepeke
2008-11-03 * fixed a typo.drry
2008-10-15namespaceの省略(vimperator CVS headと旧版との互換性維持のため)teramako
2008-09-03Ubiquityを無効にしていた場合、即終了するよう変更teramako
2008-09-02rename "ubiquityGlue.js" to "ubiquity.js"teramako
2008-09-02teramakoさんのをubiquity.jsにする為にリネームmattn
2008-09-02o^16psmattn
2008-09-02added ubiquity plugin for vimperator: 補完機能なし!mattn
href='#n132'>132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//
// _smooziee.js
//
// LICENSE: {{{
//   Copyright (c) 2009 snaka<snaka.gml@gmail.com>
//
//     distributable under the terms of an MIT-style license.
//     http://www.opensource.jp/licenses/mit-license.html
// }}}
//
// 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.1pre</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.2</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>;
// }}}

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: