Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Hint menu |
| 3 | */ |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame^] | 4 | |
| 5 | "use strict"; |
| 6 | |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 7 | define([ |
| 8 | 'menu', |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 9 | 'hint/item', |
| 10 | 'hint/prefix', |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 11 | 'hint/lengthField' |
| 12 | ], function ( |
| 13 | menuClass, |
| 14 | itemClass, |
| 15 | prefixClass, |
| 16 | lengthFieldClass) { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 17 | |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 18 | return { |
| 19 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 20 | /** |
| 21 | * Create new hint helper menu. |
| 22 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 23 | create : function (hint, context, params) { |
| 24 | var obj = Object.create(menuClass) |
Akron | 72f7357 | 2017-12-05 12:31:09 +0100 | [diff] [blame] | 25 | .upgradeTo(this) |
| 26 | ._init(params, { |
| 27 | itemClass : itemClass, |
| 28 | prefixClass : prefixClass, |
| 29 | lengthFieldClass : lengthFieldClass |
| 30 | }); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | obj._context = context; |
| 32 | obj._element.classList.add('hint'); |
| 33 | obj._hint = hint; |
| 34 | |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 35 | // Make the top item always active |
| 36 | obj._firstActive = true; |
| 37 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 38 | obj.element().addEventListener('blur', function (e) { |
Akron | e078911 | 2018-08-31 14:32:04 +0200 | [diff] [blame] | 39 | this.menu.hide(); // WithoutDestruction(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 40 | }); |
| 41 | |
| 42 | // Focus on input field on hide |
| 43 | obj.onHide = function () { |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 44 | var h = this._hint; |
| 45 | h._inputField.element().focus(); |
| 46 | if (h.active() !== null) { |
| 47 | if (h._alert.active) { |
| 48 | h._unshowAlert(); |
| 49 | }; |
| 50 | h.active(null); |
| 51 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | return obj; |
| 55 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * The hint helper object, |
| 59 | * the menu is attached to. |
| 60 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 61 | hint : function () { |
| 62 | return this._hint; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 63 | } |
| 64 | }; |
| 65 | }); |