Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 1 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 2 | * Scrollable drop-down menus with view filter. |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 3 | * |
| 4 | * @author Nils Diewald |
| 5 | */ |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 6 | /* |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 7 | * TODO: First item shouldn't be automatically highlighted! |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 8 | * TODO: space is not a valid prefix! |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 9 | * TODO: Prefix should be case sensitive! |
Nils Diewald | 2488d05 | 2015-04-09 21:46:02 +0000 | [diff] [blame] | 10 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 11 | define([ |
| 12 | 'menu/item', |
| 13 | 'menu/prefix', |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 14 | 'menu/lengthField', |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 15 | 'util' |
| 16 | ], function (defaultItemClass, |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 17 | defaultPrefixClass, |
| 18 | lengthFieldClass) { |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 19 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 20 | // Default maximum number of menu items |
| 21 | var menuLimit = 8; |
| 22 | |
| 23 | function _codeFromEvent (e) { |
| 24 | if (e.charCode && (e.keyCode == 0)) |
| 25 | return e.charCode |
| 26 | return e.keyCode; |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * List of items for drop down menu (complete). |
| 32 | * Only a sublist of the menu is filtered (live). |
| 33 | * Only a sublist of the filtered menu is visible (shown). |
| 34 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 35 | return { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Create new Menu based on the action prefix |
| 38 | * and a list of menu items. |
| 39 | * |
| 40 | * @this {Menu} |
| 41 | * @constructor |
| 42 | * @param {string} Context prefix |
| 43 | * @param {Array.<Array.<string>>} List of menu items |
| 44 | */ |
| 45 | create : function (params) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 46 | return Object.create(this)._init(params); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 47 | }, |
| 48 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Destroy this menu |
| 51 | * (in case you don't trust the |
| 52 | * mark and sweep GC)! |
| 53 | */ |
| 54 | destroy : function () { |
| 55 | if (this._element != undefined) |
| 56 | delete this._element["menu"]; |
| 57 | |
| 58 | for (var i = 0; i < this._items.length; i++) { |
| 59 | delete this._items[i]["_menu"]; |
| 60 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 61 | delete this._prefix['_menu']; |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 62 | }, |
| 63 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Focus on this menu. |
| 67 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 68 | focus : function () { |
| 69 | this._element.focus(); |
| 70 | }, |
| 71 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 72 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 73 | // mouse wheel treatment |
| 74 | _mousewheel : function (e) { |
| 75 | var delta = 0; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 76 | |
| 77 | delta = e.deltaY / 120; |
| 78 | if (delta > 0) |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 79 | this.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 80 | else if (delta < 0) |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 81 | this.prev(); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 82 | e.halt(); |
| 83 | }, |
| 84 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 85 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 86 | // Arrow key and prefix treatment |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 87 | _keydown : function (e) { |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 88 | var code = _codeFromEvent(e); |
| 89 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 90 | switch (code) { |
| 91 | case 27: // 'Esc' |
| 92 | e.halt(); |
| 93 | this.hide(); |
| 94 | break; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 95 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 96 | case 38: // 'Up' |
| 97 | e.halt(); |
| 98 | this.prev(); |
| 99 | break; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 100 | case 33: // 'Page up' |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 101 | e.halt(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 102 | this.prev(); |
| 103 | break; |
| 104 | case 40: // 'Down' |
| 105 | e.halt(); |
| 106 | this.next(); |
| 107 | break; |
| 108 | case 34: // 'Page down' |
| 109 | e.halt(); |
| 110 | this.next(); |
| 111 | break; |
| 112 | case 39: // 'Right' |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 113 | if (this._prefix.active()) |
| 114 | break; |
| 115 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 116 | var item = this.liveItem(this._position); |
Akron | 5ef4fa0 | 2015-06-02 16:25:14 +0200 | [diff] [blame] | 117 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 118 | if (item["further"] !== undefined) { |
| 119 | item["further"].bind(item).apply(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 120 | }; |
Akron | 5ef4fa0 | 2015-06-02 16:25:14 +0200 | [diff] [blame] | 121 | |
| 122 | e.halt(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 123 | break; |
| 124 | case 13: // 'Enter' |
| 125 | |
| 126 | // Click on prefix |
| 127 | if (this._prefix.active()) |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 128 | this._prefix.onclick(e); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 129 | |
| 130 | // Click on item |
| 131 | else |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 132 | this.liveItem(this._position).onclick(e); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 133 | e.halt(); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 134 | break; |
| 135 | case 8: // 'Backspace' |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 136 | this._prefix.chop(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 137 | this.show(); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 138 | e.halt(); |
| 139 | break; |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 140 | }; |
| 141 | }, |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 142 | |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 143 | // Add characters to prefix |
| 144 | _keypress : function (e) { |
| 145 | var c = String.fromCharCode(_codeFromEvent(e)).toLowerCase(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 146 | |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 147 | // Add prefix |
| 148 | this._prefix.add(c); |
| 149 | |
| 150 | if (!this.show()) { |
| 151 | this.prefix('').show(); |
| 152 | e.halt(); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 153 | }; |
| 154 | }, |
| 155 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 156 | // Initialize list |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 157 | _init : function (itemClass, prefixClass, params) { |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 158 | var that = this; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 159 | this._itemClass = itemClass || defaultItemClass; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 160 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 161 | // Add prefix object |
| 162 | if (prefixClass !== undefined) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 163 | this._prefix = prefixClass.create(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 164 | } |
| 165 | else { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 166 | this._prefix = defaultPrefixClass.create(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 167 | }; |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 168 | this._prefix._menu = this; |
| 169 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 170 | // Add lengthField object |
| 171 | this._lengthField = lengthFieldClass.create(); |
| 172 | this._lengthField._menu = this; |
| 173 | |
| 174 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 175 | var e = document.createElement("ul"); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 176 | e.style.opacity = 0; |
| 177 | e.style.outline = 0; |
| 178 | e.setAttribute('tabindex', 0); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 179 | e.classList.add('menu'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 180 | e.classList.add('roll'); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 181 | e.appendChild(this._prefix.element()); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 182 | e.appendChild(this._lengthField.element()); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 183 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 184 | // This has to be cleaned up later on |
| 185 | e["menu"] = this; |
| 186 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 187 | // Arrow keys |
| 188 | e.addEventListener( |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 189 | 'keydown', |
| 190 | function (ev) { |
| 191 | that._keydown(ev) |
| 192 | }, |
| 193 | false |
| 194 | ); |
| 195 | |
| 196 | // Strings |
| 197 | e.addEventListener( |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 198 | 'keypress', |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 199 | function (ev) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 200 | that._keypress(ev) |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 201 | }, |
| 202 | false |
| 203 | ); |
| 204 | |
| 205 | // Mousewheel |
| 206 | e.addEventListener( |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 207 | 'wheel', |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 208 | function (ev) { |
| 209 | that._mousewheel(ev) |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 210 | }, |
| 211 | false |
| 212 | ); |
| 213 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 214 | this._element = e; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 215 | this.active = false; |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 216 | // this.selected = undefined; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 217 | this._items = new Array(); |
| 218 | var i; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 219 | |
| 220 | // Initialize item list based on parameters |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 221 | for (i in params) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 222 | var obj = this._itemClass.create(params[i]); |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 223 | |
| 224 | // This may become circular |
| 225 | obj["_menu"] = this; |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 226 | this._lengthField.add(params[i][0]); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 227 | this._items.push(obj); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 228 | }; |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 229 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 230 | this._limit = menuLimit; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 231 | this._position = 0; // position in the active list |
| 232 | this._active = -1; // active item in the item list |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 233 | this._firstActive = false; // Show the first item active always? |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 234 | this._reset(); |
| 235 | return this; |
| 236 | }, |
| 237 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 238 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 239 | * Get the associated dom element. |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 240 | */ |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 241 | element : function () { |
| 242 | return this._element; |
| 243 | }, |
| 244 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 245 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 246 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 247 | * Get the creator class for items |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 248 | */ |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 249 | itemClass : function () { |
| 250 | return this._itemClass; |
| 251 | }, |
| 252 | |
| 253 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 254 | * Get and set the numerical value |
| 255 | * for the maximum number of items visible. |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 256 | */ |
| 257 | limit : function (limit) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 258 | if (arguments.length === 1) { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 259 | this._limit = limit; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 260 | return this; |
| 261 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 262 | return this._limit; |
| 263 | }, |
| 264 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 265 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 266 | /** |
| 267 | * Upgrade this object to another object, |
| 268 | * while private data stays intact. |
| 269 | * |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 270 | * @param {Object} An object with properties. |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 271 | */ |
| 272 | upgradeTo : function (props) { |
| 273 | for (var prop in props) { |
| 274 | this[prop] = props[prop]; |
| 275 | }; |
| 276 | return this; |
| 277 | }, |
| 278 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 279 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 280 | // Reset chosen item and prefix |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 281 | _reset : function () { |
| 282 | this._offset = 0; |
| 283 | this._pos = 0; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 284 | this._prefix.value(''); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 285 | }, |
| 286 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 287 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 288 | /** |
| 289 | * Filter the list and make it visible |
| 290 | * |
| 291 | * @param {string} Prefix for filtering the list |
| 292 | */ |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 293 | show : function () { |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 294 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 295 | // Initialize the list |
| 296 | if (!this._initList()) |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 297 | return false; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 298 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 299 | // show based on initial offset |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 300 | this._showItems(0); |
| 301 | |
| 302 | // Set the first element to active |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 303 | // Todo: Or the last element chosen |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 304 | if (this._firstActive) |
| 305 | this.liveItem(0).active(true); |
| 306 | |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 307 | this._position = 0; |
| 308 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 309 | this._prefix.active(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 310 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 311 | this._element.style.opacity = 1; |
| 312 | |
Akron | 37513a6 | 2015-11-17 01:07:11 +0100 | [diff] [blame] | 313 | // Iterate to the active item |
| 314 | if (this._active !== -1 && !this._prefix.isSet()) { |
| 315 | while (this._list[this._position] < this._active) { |
| 316 | this.next(); |
| 317 | }; |
| 318 | }; |
| 319 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 320 | // Add classes for rolling menus |
| 321 | this._boundary(true); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 322 | return true; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 323 | }, |
| 324 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * Hide the menu and call the onHide callback. |
| 328 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 329 | hide : function () { |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 330 | this.active = false; |
| 331 | this.delete(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 332 | this._element.style.opacity = 0; |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 333 | this._prefix.clear(); |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 334 | this.onHide(); |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame] | 335 | /* this._element.blur(); */ |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 336 | }, |
| 337 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 338 | /** |
| 339 | * Function released when the menu hides. |
| 340 | * This method is expected to be overridden. |
| 341 | */ |
Nils Diewald | 5c5a747 | 2015-04-02 22:13:38 +0000 | [diff] [blame] | 342 | onHide : function () {}, |
| 343 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 344 | // Initialize the list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 345 | _initList : function () { |
| 346 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 347 | // Create a new list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 348 | if (this._list === undefined) { |
| 349 | this._list = []; |
| 350 | } |
| 351 | else if (this._list.length != 0) { |
| 352 | this._boundary(false); |
| 353 | this._list.length = 0; |
| 354 | }; |
| 355 | |
| 356 | // Offset is initially zero |
| 357 | this._offset = 0; |
| 358 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 359 | // There is no prefix set |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 360 | if (this.prefix().length <= 0) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 361 | var i = 0; |
| 362 | for (; i < this._items.length; i++) |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 363 | this._list.push(i); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 364 | while (this._items[++i] !== undefined) { |
| 365 | this._items[i].lowlight(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 366 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 367 | return true; |
| 368 | }; |
| 369 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 370 | // There is a prefix set, so filter the list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 371 | var pos; |
| 372 | var paddedPrefix = " " + this.prefix(); |
| 373 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 374 | // Iterate over all items and choose preferred matching items |
| 375 | // i.e. the matching happens at the word start |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 376 | for (pos = 0; pos < this._items.length; pos++) { |
| 377 | if ((this.item(pos).lcField().indexOf(paddedPrefix)) >= 0) |
| 378 | this._list.push(pos); |
| 379 | }; |
| 380 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 381 | // The list is empty - so lower your expectations |
| 382 | // Iterate over all items and choose matching items |
| 383 | // i.e. the matching happens anywhere in the word |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 384 | if (this._list.length == 0) { |
| 385 | for (pos = 0; pos < this._items.length; pos++) { |
| 386 | if ((this.item(pos).lcField().indexOf(this.prefix())) >= 0) |
| 387 | this._list.push(pos); |
| 388 | }; |
| 389 | }; |
| 390 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 391 | // Filter was successful - yeah! |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 392 | return this._list.length > 0 ? true : false; |
| 393 | }, |
| 394 | |
| 395 | // Set boundary for viewport |
| 396 | _boundary : function (bool) { |
| 397 | this.item(this._list[0]).noMore(bool); |
| 398 | this.item(this._list[this._list.length - 1]).noMore(bool); |
| 399 | }, |
| 400 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 401 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 402 | /** |
| 403 | * Get the prefix for filtering, |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 404 | * e.g. "ve" for "verb" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 405 | */ |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 406 | prefix : function (pref) { |
| 407 | if (arguments.length === 1) { |
| 408 | this._prefix.value(pref); |
| 409 | return this; |
| 410 | }; |
| 411 | return this._prefix.value(); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 412 | }, |
| 413 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 414 | /** |
| 415 | * Get the lengthField object. |
| 416 | */ |
| 417 | lengthField : function () { |
| 418 | return this._lengthField; |
| 419 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 420 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 421 | // Append Items that should be shown |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 422 | _showItems : function (offset) { |
| 423 | this.delete(); |
| 424 | |
| 425 | // Use list |
| 426 | var shown = 0; |
| 427 | var i; |
| 428 | for (i in this._list) { |
| 429 | |
| 430 | // Don't show - it's before offset |
| 431 | if (shown++ < offset) |
| 432 | continue; |
| 433 | |
| 434 | this._append(this._list[i]); |
| 435 | |
| 436 | if (shown >= (this.limit() + this._offset)) |
| 437 | break; |
| 438 | }; |
| 439 | }, |
| 440 | |
| 441 | /** |
| 442 | * Delete all visible items from the menu element |
| 443 | */ |
| 444 | delete : function () { |
| 445 | var child; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 446 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 447 | /* |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 448 | // Iterate over all visible items |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 449 | for (var i = 0; i <= this.limit(); i++) { |
| 450 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 451 | // there is a visible element |
| 452 | // unhighlight! |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 453 | if (child = this.shownItem(i)) { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 454 | child.lowlight(); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 455 | child.active(false); |
| 456 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 457 | }; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 458 | */ |
| 459 | |
| 460 | for (var i in this._list) { |
| 461 | var item = this._items[this._list[i]]; |
| 462 | item.lowlight(); |
| 463 | item.active(false); |
| 464 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 465 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 466 | // Remove all children |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 467 | var children = this._element.childNodes; |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 468 | // Leave the prefix and lengthField |
| 469 | for (var i = children.length - 1; i >= 2; i--) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 470 | this._element.removeChild( |
| 471 | children[i] |
| 472 | ); |
| 473 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 474 | }, |
| 475 | |
| 476 | |
| 477 | // Append item to the shown list based on index |
| 478 | _append : function (i) { |
| 479 | var item = this.item(i); |
| 480 | |
| 481 | // Highlight based on prefix |
| 482 | if (this.prefix().length > 0) |
| 483 | item.highlight(this.prefix()); |
| 484 | |
| 485 | // Append element |
| 486 | this.element().appendChild(item.element()); |
| 487 | }, |
| 488 | |
| 489 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 490 | // Prepend item to the shown list based on index |
| 491 | _prepend : function (i) { |
| 492 | var item = this.item(i); |
| 493 | |
| 494 | // Highlight based on prefix |
| 495 | if (this.prefix().length > 0) |
| 496 | item.highlight(this.prefix()); |
| 497 | |
| 498 | var e = this.element(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 499 | // Append element after lengthFiled/prefix |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 500 | e.insertBefore( |
| 501 | item.element(), |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 502 | e.children[2] |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 503 | ); |
| 504 | }, |
| 505 | |
| 506 | |
| 507 | /** |
| 508 | * Get a specific item from the complete list |
| 509 | * |
| 510 | * @param {number} index of the list item |
| 511 | */ |
| 512 | item : function (index) { |
| 513 | return this._items[index] |
| 514 | }, |
| 515 | |
| 516 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 517 | /** |
| 518 | * Get a specific item from the filtered list |
| 519 | * |
| 520 | * @param {number} index of the list item |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 521 | * in the filtered list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 522 | */ |
| 523 | liveItem : function (index) { |
| 524 | if (this._list === undefined) |
| 525 | if (!this._initList()) |
| 526 | return; |
| 527 | |
| 528 | return this._items[this._list[index]]; |
| 529 | }, |
| 530 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 531 | |
| 532 | /** |
| 533 | * Get a specific item from the visible list |
| 534 | * |
| 535 | * @param {number} index of the list item |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 536 | * in the visible list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 537 | */ |
| 538 | shownItem : function (index) { |
| 539 | if (index >= this.limit()) |
| 540 | return; |
| 541 | return this.liveItem(this._offset + index); |
| 542 | }, |
| 543 | |
| 544 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 545 | /** |
| 546 | * Get the length of the full list |
| 547 | */ |
| 548 | length : function () { |
| 549 | return this._items.length; |
| 550 | }, |
| 551 | |
| 552 | |
| 553 | /** |
| 554 | * Make the next item in the filtered menu active |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 555 | */ |
| 556 | next : function () { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 557 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 558 | // No active element set |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 559 | if (this._position === -1) |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 560 | return; |
| 561 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 562 | var newItem; |
| 563 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 564 | // Set new live item |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 565 | if (!this._prefix.active()) { |
| 566 | var oldItem = this.liveItem(this._position); |
| 567 | oldItem.active(false); |
| 568 | }; |
| 569 | |
| 570 | this._position++; |
| 571 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 572 | newItem = this.liveItem(this._position); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 573 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 574 | // The next element is undefined - roll to top or to prefix |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 575 | if (newItem === undefined) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 576 | |
| 577 | // Activate prefix |
| 578 | var prefix = this._prefix; |
| 579 | |
| 580 | // Mark prefix |
| 581 | if (prefix.isSet() && !prefix.active()) { |
| 582 | this._position--; |
| 583 | prefix.active(true); |
| 584 | return; |
| 585 | } |
| 586 | else { |
| 587 | this._offset = 0; |
| 588 | this._position = 0; |
| 589 | newItem = this.liveItem(0); |
| 590 | this._showItems(0); |
| 591 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | // The next element is outside the view - roll down |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 595 | else if (this._position >= (this.limit() + this._offset)) { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 596 | this._removeFirst(); |
| 597 | this._offset++; |
| 598 | this._append(this._list[this._position]); |
| 599 | }; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 600 | |
| 601 | this._prefix.active(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 602 | newItem.active(true); |
| 603 | }, |
| 604 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 605 | /* |
| 606 | * Page down to the first item on the next page |
| 607 | */ |
| 608 | /* |
| 609 | nextPage : function () { |
| 610 | |
| 611 | // Prefix is active |
| 612 | if (this._prefix.active()) { |
| 613 | this._prefix.active(false); |
| 614 | } |
| 615 | |
| 616 | // Last item is chosen |
| 617 | else if (this._position >= this.limit() + this._offset) { |
| 618 | |
| 619 | this._position = this.limit() + this._offset - 1; |
| 620 | newItem = this.liveItem(this._position); |
| 621 | var oldItem = this.liveItem(this._position--); |
| 622 | oldItem.active(false); |
| 623 | } |
| 624 | |
| 625 | // Last item of page is chosen |
| 626 | else if (0) { |
| 627 | |
| 628 | // Jump to last item |
| 629 | else { |
| 630 | var oldItem = this.liveItem(this._position); |
| 631 | oldItem.active(false); |
| 632 | |
| 633 | this._position = this.limit() + this._offset - 1; |
| 634 | newItem = this.liveItem(this._position); |
| 635 | }; |
| 636 | |
| 637 | newItem.active(true); |
| 638 | }, |
| 639 | */ |
| 640 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 641 | |
| 642 | /* |
| 643 | * Make the previous item in the menu active |
| 644 | */ |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 645 | prev : function () { |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 646 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 647 | // No active element set |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 648 | if (this._position === -1) { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 649 | return; |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 650 | // TODO: Choose last item |
| 651 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 652 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 653 | var newItem; |
| 654 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 655 | // Set new live item |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 656 | if (!this._prefix.active()) { |
| 657 | var oldItem = this.liveItem(this._position--); |
| 658 | oldItem.active(false); |
| 659 | }; |
| 660 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 661 | newItem = this.liveItem(this._position); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 662 | |
| 663 | // The previous element is undefined - roll to bottom |
| 664 | if (newItem === undefined) { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 665 | |
| 666 | // Activate prefix |
| 667 | var prefix = this._prefix; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 668 | this._offset = this.liveLength() - this.limit(); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 669 | |
| 670 | // Normalize offset |
| 671 | this._offset = this._offset < 0 ? 0 : this._offset; |
| 672 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 673 | this._position = this.liveLength() - 1; |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 674 | |
| 675 | if (prefix.isSet() && !prefix.active()) { |
| 676 | this._position++; |
| 677 | prefix.active(true); |
| 678 | return; |
| 679 | } |
| 680 | else { |
| 681 | newItem = this.liveItem(this._position); |
| 682 | this._showItems(this._offset); |
| 683 | }; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | // The previous element is outside the view - roll up |
| 687 | else if (this._position < this._offset) { |
| 688 | this._removeLast(); |
| 689 | this._offset--; |
| 690 | this._prepend(this._list[this._position]); |
| 691 | }; |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 692 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 693 | this._prefix.active(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 694 | newItem.active(true); |
| 695 | }, |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 696 | |
| 697 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 698 | /** |
| 699 | * Length of the filtered item list. |
| 700 | */ |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 701 | liveLength : function () { |
| 702 | if (this._list === undefined) |
| 703 | this._initList(); |
| 704 | return this._list.length; |
| 705 | }, |
| 706 | |
| 707 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 708 | // Remove the HTML node from the first item |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 709 | _removeFirst : function () { |
| 710 | this.item(this._list[this._offset]).lowlight(); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame^] | 711 | // leave lengthField/prefix |
| 712 | this._element.removeChild(this._element.children[2]); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 713 | }, |
| 714 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 715 | |
| 716 | // Remove the HTML node from the last item |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 717 | _removeLast : function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 718 | this.item(this._list[this._offset + this.limit() - 1]).lowlight(); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 719 | this._element.removeChild(this._element.lastChild); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 720 | } |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 721 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 722 | }); |