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 | |
| 18 | // This is only domspecific |
| 19 | obj.element().addEventListener('blur', function (e) { |
| 20 | this.menu.hide(); |
| 21 | }); |
| 22 | |
| 23 | // Focus on input field on hide |
| 24 | obj.onHide = function () { |
| 25 | var input = this._hint.inputField(); |
| 26 | input.container().classList.remove('active'); |
| 27 | input.element().focus(); |
| 28 | }; |
| 29 | |
| 30 | return obj; |
| 31 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * The hint helper object, |
| 35 | * the menu is attached to. |
| 36 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 37 | hint : function () { |
| 38 | return this._hint; |
| 39 | } |
| 40 | }; |
| 41 | }); |