blob: b28c03a330ee1922054d7388501f71ccd20d2a57 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu
3 */
Akronda5bd3a2020-10-16 17:37:49 +02004
5"use strict";
6
Akroncae907d2018-08-20 17:22:15 +02007define([
Leo Repp8e21cbe2021-08-18 16:37:52 +02008 'containermenu',
Akron1ff3ac22016-04-28 16:30:45 +02009 'hint/item',
10 'hint/prefix',
Akroncae907d2018-08-20 17:22:15 +020011 'hint/lengthField'
12], function (
Leo Repp8e21cbe2021-08-18 16:37:52 +020013 containerMenuClass,
Akroncae907d2018-08-20 17:22:15 +020014 itemClass,
15 prefixClass,
16 lengthFieldClass) {
Nils Diewald7148c6f2015-05-04 15:07:53 +000017
Akroncae907d2018-08-20 17:22:15 +020018 return {
19
Nils Diewald7148c6f2015-05-04 15:07:53 +000020 /**
21 * Create new hint helper menu.
22 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000023 create : function (hint, context, params) {
Leo Repp8e21cbe2021-08-18 16:37:52 +020024 const obj = containerMenuClass.create(params, {
25 itemClass : itemClass,
26 prefixClass : prefixClass,
27 lengthFieldClass : lengthFieldClass})
28 .upgradeTo(this);
Nils Diewald0e6992a2015-04-14 20:13:52 +000029 obj._context = context;
Akron24aa0052020-11-10 11:00:34 +010030 obj._el.classList.add('hint');
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 obj._hint = hint;
32
Nils Diewald20f7ace2015-05-07 12:51:34 +000033 // Make the top item always active
34 obj._firstActive = true;
35
Nils Diewald0e6992a2015-04-14 20:13:52 +000036 obj.element().addEventListener('blur', function (e) {
Akrone0789112018-08-31 14:32:04 +020037 this.menu.hide(); // WithoutDestruction();
Nils Diewald0e6992a2015-04-14 20:13:52 +000038 });
39
40 // Focus on input field on hide
41 obj.onHide = function () {
Akron954c6a52020-11-10 14:26:29 +010042 const h = this._hint;
Akroncae907d2018-08-20 17:22:15 +020043 h._inputField.element().focus();
44 if (h.active() !== null) {
45 if (h._alert.active) {
46 h._unshowAlert();
47 };
48 h.active(null);
49 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000050 };
51
52 return obj;
53 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000054
55 /**
56 * The hint helper object,
57 * the menu is attached to.
58 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000059 hint : function () {
60 return this._hint;
Nils Diewald0e6992a2015-04-14 20:13:52 +000061 }
62 };
63});