Changeset 28170
- Timestamp:
- 01/08/09 21:28:21 (6 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/resizable_textarea.js
r28169 r28170 12 12 <description lang="ja">テキストエリアをリサイズ可能にする。</description> 13 13 <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author> 14 <version>0. 1.0</version>14 <version>0.2.0</version> 15 15 <license>MIT</license> 16 16 <minVersion>2.0pre</minVersion> 17 17 <maxVersion>2.0α2</maxVersion> 18 <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/resiz eble_textarea.js</updateURL>18 <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/resizable_textarea.js</updateURL> 19 19 <detail><![CDATA[ 20 20 == Usage == 21 === NORMAL MODE or VISUAL MODE or CARET MODE === 21 22 >|| 22 :textareaResize 23 or 24 :tr 23 :textareaResize or :tr 25 24 ||< 25 you can resize textareas by using a mouse. 26 27 === INSERT MODE or TEXTAREA MODE === 28 >|| 29 "<A-r>" or "<M-r>" 30 ||< 31 you can resize current component by using a keyboad. 32 === keymap === 33 "k" or "up": 34 height more small. 35 "j" or "down": 36 height more large. 37 "h" or "left": 38 width more small. 39 "l" or "right": 40 width more large. 41 "escape" or "enter": 42 end of resize. 26 43 ]]></detail> 27 44 </VimperatorPlugin>; … … 38 55 initResize: this._bind(this, this.initResize), 39 56 resize: this._bind(this, this.resize), 40 stopResize: this._bind(this, this.stopResize) 57 stopResize: this._bind(this, this.stopResize), 58 currentResize: this._bind(this, this.currentResize) 41 59 }; 42 60 }, 43 resizable: function(args) { 61 resizable: function(focused) { 62 if (focused) { 63 this.initResize({ target: focused }, focused); 64 return; 65 } 44 66 this.changeCursor(false); 45 67 this.doc.addEventListener("mousedown", this.handler.initResize, false); 46 68 }, 47 initResize: function(event ) {69 initResize: function(event, focused) { 48 70 var target = this.target = event.target; 49 71 if (!target || … … 52 74 return; 53 75 76 if (focused) { 77 this.target.startBgColor = this.target.style.backgroundColor; 78 this.target.style.backgroundColor = "#F4BC14"; 79 this.doc.addEventListener("keydown", this.handler.currentResize, false); 80 return; 81 } 82 54 83 this.target.startWidth = this.target.clientWidth; 55 84 this.target.startHeight = this.target.clientHeight; 56 this.target.startX = event.clientX ;57 this.target.startY = event.clientY ;85 this.target.startX = event.clientX || event.target.offsetLeft; 86 this.target.startY = event.clientY || event.target.offsetTop; 58 87 59 88 this.doc.addEventListener("mousemove", this.handler.resize, false); … … 87 116 } 88 117 }, 118 currentResize: function(event) { 119 var nodeName = this.target.nodeName.toLowerCase(); 120 switch (event.keyCode) { 121 case KeyEvent.DOM_VK_UP: case KeyEvent.DOM_VK_K: 122 if (nodeName == "textarea") 123 this.target.style.height = this.target.clientHeight - 10 + "px"; 124 break; 125 case KeyEvent.DOM_VK_DOWN: case KeyEvent.DOM_VK_J: 126 if (nodeName == "textarea") 127 this.target.style.height = this.target.clientHeight + 15 + "px"; 128 break; 129 case KeyEvent.DOM_VK_LEFT: case KeyEvent.DOM_VK_H: 130 this.target.style.width = this.target.clientWidth - 10 + "px"; 131 break; 132 case KeyEvent.DOM_VK_RIGHT: case KeyEvent.DOM_VK_L: 133 this.target.style.width = this.target.clientWidth + 15 + "px"; 134 break; 135 case KeyEvent.DOM_VK_RETURN: case KeyEvent.DOM_VK_ENTER: case KeyEvent.DOM_VK_ESCAPE: 136 this.target.style.background = this.target.startBgColor; 137 setTimeout(function(self) { 138 self.doc.removeEventListener("keydown", self.handler.currentResize, false); 139 self.target.focus(); 140 }, 10, this 141 ); 142 break; 143 } 144 try{ 145 event.preventDefault(); 146 } catch (e) {} 147 }, 89 148 _bind: function() { 90 149 var obj = Array.prototype.shift.apply(arguments); … … 99 158 100 159 commands.addUserCommand( 101 [ "textareaResize", "tr" ], " resizable textarea.",160 [ "textareaResize", "tr" ], "Allows you to resize textareas.", 102 161 function() { 103 162 var instance = new TextResizer(window.content.document); 104 instance.resizable.apply(instance , arguments);163 instance.resizable.apply(instance); 105 164 }, 106 165 null, … … 108 167 ); 109 168 169 mappings.add( 170 [ modes.INSERT, modes.TEXTAREA ], 171 [ "<M-r>", "<A-r>" ], 172 "Allows you to resize current textarea.", 173 function() { 174 var instance = new TextResizer(window.content.document); 175 instance.resizable.apply(instance, [ document.commandDispatcher.focusedElement ]); 176 } 177 ); 178 110 179 })(); 111 180 // vim: set fdm=marker sw=2 ts=2 sts=0 et:
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)