/* {{{ Copyright (c) 2008, anekos. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################### # http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license # # に参考になる日本語訳がありますが、有効なのは上記英文となります。 # ################################################################################### }}} */ // PLUGIN_INFO {{{ let PLUGIN_INFO = Auto Reload 自動リロード Watch local file, and automatically reload current page when the file is modified. ローカルのファイルを監視して、現在のページをリロードする 1.0.1 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) 2.3pre 2.3pre ; // }}} (function () { let uuid = '{e49e10b3-a867-457a-8c4e-dbe09e3b285a}'; commands.addUserCommand( ['autoreload'], 'Auto reload current tab', function (args) { let tab = gBrowser.mCurrentTab; let storage = tab[this.uuid] || (tab[this.uuid] = {}); let reload; let func = reload = function () tabs.reload(tab); let time = parseInt(parseFloat(args[0] || 1) * 1000); let (file = io.File(args.string)) { if (file.exists() && file.isFile()) { let filepath = file.path; storage.lastModifiedTime = file.lastModifiedTime; time = 200; func = function () { let file = io.File(filepath); let mt = file.lastModifiedTime; if (storage.lastModifiedTime == mt) return; storage.lastModifiedTime = mt; reload(); }; } } if (storage.timer) { liberator.log('removed'); clearInterval(storage.timer); } storage.timer = setInterval(func, time); }, { completer: function (context, args) completion.file(context) }, true ); })(); // vim:sw=2 ts=2 et si fdm=marker: d='n12' href='#n12'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
/*** BEGIN LICENSE BLOCK {{{
  Copyright (c) 2009 suVene<suvene@zeromemory.info>

  distributable under the terms of an MIT-style license.
  http://www.opensource.jp/licenses/mit-license.html
}}}  END LICENSE BLOCK ***/
// PLUGIN_INFO//{{{
var PLUGIN_INFO =
<VimperatorPlugin>
  <name>{NAME}</name>
  <description>Allows you to resize textareas.</description>
  <description lang="ja">テキストエリアをリサイズ可能にする</description>
  <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
  <version>0.2.1</version>
  <license>MIT</license>
  <minVersion>2.0pre</minVersion>
  <maxVersion>2.0α2</maxVersion>
  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/resizable_textarea.js</updateURL>
  <detail><![CDATA[
== Usage ==
=== NORMAL MODE or VISUAL MODE or CARET MODE ===
>||
:textareaResize or :tr
||<
you can resize textareas by using a mouse.

=== INSERT MODE or TEXTAREA MODE ===
>||
"<A-r>" or "<M-r>"
||<
you can resize current component by using a keyboad.
=== keymap ===
"k" or "up":
  height more small.
"j" or "down":
  height more large.
"h" or "left":
  width more small.
"l" or "right":
  width more large.
"escape" or "enter":
  end of resize.
  ]]></detail>
</VimperatorPlugin>;
//}}}
(function() {

var TextResizer = function() {
  this.initialize.apply(this, arguments);
};
TextResizer.prototype = {
  initialize: function(doc) {
    this.doc = doc;
    this.handler = {
      initResize: this._bind(this, this.initResize),
      resize: this._bind(this, this.resize),
      stopResize: this._bind(this, this.stopResize),
      currentResize: this._bind(this, this.currentResize)
    };
  },
  resizable: function(focused) {
    if (focused) {
      this.initResize({ target: focused }, focused);
      return;
    }
    this.changeCursor(false);
    this.doc.addEventListener("mousedown", this.handler.initResize, false);
  },
  initResize: function(event, focused) {
    var target = this.target = event.target;
    if (!target ||
        (target.nodeName.toLowerCase() != "textarea" &&
         (target.nodeName.toLowerCase() != "input" || target.type != "text")))
      return;

    if (focused) {
      this.target.startBgColor = this.target.style.backgroundColor;
      this.target.style.backgroundColor = "#F4BC14";
      this.doc.addEventListener("keydown", this.handler.currentResize, false);
      return;
    }

    this.target.startWidth = this.target.clientWidth;
    this.target.startHeight = this.target.clientHeight;
    this.target.startX = event.clientX || event.target.offsetLeft;
    this.target.startY = event.clientY || event.target.offsetTop;

    this.doc.addEventListener("mousemove", this.handler.resize, false);
    this.doc.addEventListener("mouseup", this.handler.stopResize, false);

    try{
      event.preventDefault();
    } catch (e) {}
  },
  resize: function(event) {
    try{
      this.target.style.width = event.clientX - this.target.startX + this.target.startWidth + "px";
    } catch (e) {}

    if (this.target.nodeName.toLowerCase() == "textarea")
      this.target.style.height = event.clientY - this.target.startY + this.target.startHeight + "px";
  },
  stopResize:function(event) {
    this.doc.removeEventListener("mousedown", this.handler.initResize, false);
    this.doc.removeEventListener("mousemove", this.handler.resize, false);
    setTimeout(function(self) self.doc.removeEventListener("mouseup", self.handler.stopResize, false), 10, this);
    this.changeCursor(true);
  },
  changeCursor: function(normal) {
    for (let [,elem] in Iterator(this.doc.getElementsByTagName("textarea")))
      elem.style.cursor = normal ? "text" : "se-resize";

    for (let [,elem] in Iterator(this.doc.getElementsByTagName("input"))) {
      if (elem.type == "text")
        elem.style.cursor = normal ? "text" : "e-resize";
    }
  },
  currentResize: function(event) {
    var nodeName = this.target.nodeName.toLowerCase();
    switch (event.keyCode) {
    case KeyEvent.DOM_VK_UP: case KeyEvent.DOM_VK_K:
      if (nodeName == "textarea")
        this.target.style.height = this.target.offsetHeight - 10 + "px";
      break;
    case KeyEvent.DOM_VK_DOWN: case KeyEvent.DOM_VK_J:
      if (nodeName == "textarea")
        this.target.style.height = this.target.offsetHeight + 10 + "px";
      break;
    case KeyEvent.DOM_VK_LEFT: case KeyEvent.DOM_VK_H:
       this.target.style.width = this.target.offsetWidth - 10 + "px";
      break;
    case KeyEvent.DOM_VK_RIGHT: case KeyEvent.DOM_VK_L:
      this.target.style.width = this.target.offsetWidth + 10 + "px";
      break;
    case KeyEvent.DOM_VK_RETURN: case KeyEvent.DOM_VK_ENTER: case KeyEvent.DOM_VK_ESCAPE:
      this.target.style.background = this.target.startBgColor;
      setTimeout(function(self) {
          self.doc.removeEventListener("keydown", self.handler.currentResize, false);
          self.target.focus();
        }, 10, this
      );
      break;
    }
    try{
      event.preventDefault();
    } catch (e) {}
  },
  _bind: function() {
      var obj = Array.prototype.shift.apply(arguments);
      var func = Array.prototype.shift.apply(arguments);
      var args = [];
      for (let i = 0, len = arguments.length; i < len; args.push(arguments[i++]));
      return function(event) {
        return func.apply(obj, [ event ].concat(args));
      };
  }
};

commands.addUserCommand(
  [ "textareaResize", "tr" ], "Allows you to resize textareas.",
  function() {
    var instance = new TextResizer(window.content.document);
    instance.resizable.apply(instance);
  },
  null,
  true
);

mappings.add(
  [ modes.INSERT, modes.TEXTAREA ],
  [ "<M-r>", "<A-r>" ],
  "Allows you to resize current textarea.",
  function() {
    var instance = new TextResizer(window.content.document);
    instance.resizable.apply(instance, [ document.commandDispatcher.focusedElement ]);
  }
);

})();
// vim: set fdm=marker sw=2 ts=2 sts=0 et: