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