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([ |
Leo Repp | 8e21cbe | 2021-08-18 16:37:52 +0200 | [diff] [blame^] | 8 | 'containermenu', |
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 ( |
Leo Repp | 8e21cbe | 2021-08-18 16:37:52 +0200 | [diff] [blame^] | 13 | containerMenuClass, |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 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) { |
Leo Repp | 8e21cbe | 2021-08-18 16:37:52 +0200 | [diff] [blame^] | 24 | const obj = containerMenuClass.create(params, { |
| 25 | itemClass : itemClass, |
| 26 | prefixClass : prefixClass, |
| 27 | lengthFieldClass : lengthFieldClass}) |
| 28 | .upgradeTo(this); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 29 | obj._context = context; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 30 | obj._el.classList.add('hint'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | obj._hint = hint; |
| 32 | |
Nils Diewald | 20f7ace | 2015-05-07 12:51:34 +0000 | [diff] [blame] | 33 | // Make the top item always active |
| 34 | obj._firstActive = true; |
| 35 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 36 | obj.element().addEventListener('blur', function (e) { |
Akron | e078911 | 2018-08-31 14:32:04 +0200 | [diff] [blame] | 37 | this.menu.hide(); // WithoutDestruction(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 38 | }); |
| 39 | |
| 40 | // Focus on input field on hide |
| 41 | obj.onHide = function () { |
Akron | 954c6a5 | 2020-11-10 14:26:29 +0100 | [diff] [blame] | 42 | const h = this._hint; |
Akron | cae907d | 2018-08-20 17:22:15 +0200 | [diff] [blame] | 43 | h._inputField.element().focus(); |
| 44 | if (h.active() !== null) { |
| 45 | if (h._alert.active) { |
| 46 | h._unshowAlert(); |
| 47 | }; |
| 48 | h.active(null); |
| 49 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | return obj; |
| 53 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * The hint helper object, |
| 57 | * the menu is attached to. |
| 58 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 59 | hint : function () { |
| 60 | return this._hint; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 61 | } |
| 62 | }; |
| 63 | }); |