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