Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Hint menu |
| 3 | */ |
| 4 | define(['menu', 'hint/item', 'hint/prefix'], function (menuClass, itemClass, prefixClass) { |
| 5 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * Create new hint helper menu. |
| 9 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 10 | create : function (hint, context, params) { |
| 11 | var obj = Object.create(menuClass) |
| 12 | .upgradeTo(this) |
| 13 | ._init(itemClass, prefixClass, params); |
| 14 | obj._context = context; |
| 15 | obj._element.classList.add('hint'); |
| 16 | obj._hint = hint; |
| 17 | |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 18 | // Make the top item always active |
| 19 | obj._firstActive = true; |
| 20 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 21 | // This is only domspecific |
| 22 | obj.element().addEventListener('blur', function (e) { |
| 23 | this.menu.hide(); |
| 24 | }); |
| 25 | |
| 26 | // Focus on input field on hide |
| 27 | obj.onHide = function () { |
| 28 | var input = this._hint.inputField(); |
| 29 | input.container().classList.remove('active'); |
| 30 | input.element().focus(); |
| 31 | }; |
| 32 | |
| 33 | return obj; |
| 34 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * The hint helper object, |
| 38 | * the menu is attached to. |
| 39 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 40 | hint : function () { |
| 41 | return this._hint; |
| 42 | } |
| 43 | }; |
| 44 | }); |