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