blob: 105273e05791e8d5e2aced169f5278dd23fc4263 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu
3 */
Akroncae907d2018-08-20 17:22:15 +02004define([
5 'menu',
Akron1ff3ac22016-04-28 16:30:45 +02006 'hint/item',
7 'hint/prefix',
Akroncae907d2018-08-20 17:22:15 +02008 'hint/lengthField'
9], function (
10 menuClass,
11 itemClass,
12 prefixClass,
13 lengthFieldClass) {
Nils Diewald7148c6f2015-05-04 15:07:53 +000014
Akroncae907d2018-08-20 17:22:15 +020015 return {
16
Nils Diewald7148c6f2015-05-04 15:07:53 +000017 /**
18 * Create new hint helper menu.
19 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000020 create : function (hint, context, params) {
21 var obj = Object.create(menuClass)
Akron72f73572017-12-05 12:31:09 +010022 .upgradeTo(this)
23 ._init(params, {
24 itemClass : itemClass,
25 prefixClass : prefixClass,
26 lengthFieldClass : lengthFieldClass
27 });
Nils Diewald0e6992a2015-04-14 20:13:52 +000028 obj._context = context;
29 obj._element.classList.add('hint');
30 obj._hint = hint;
31
Nils Diewald20f7ace2015-05-07 12:51:34 +000032 // Make the top item always active
33 obj._firstActive = true;
34
Nils Diewald0e6992a2015-04-14 20:13:52 +000035 obj.element().addEventListener('blur', function (e) {
Akrone39cc862018-04-25 15:16:11 +020036 this.menu.hideWithoutDestruction();
Nils Diewald0e6992a2015-04-14 20:13:52 +000037 });
38
39 // Focus on input field on hide
40 obj.onHide = function () {
Akroncae907d2018-08-20 17:22:15 +020041 var h = this._hint;
42 h._inputField.element().focus();
43 if (h.active() !== null) {
44 if (h._alert.active) {
45 h._unshowAlert();
46 };
47 h.active(null);
48 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000049 };
50
51 return obj;
52 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000053
54 /**
55 * The hint helper object,
56 * the menu is attached to.
57 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000058 hint : function () {
59 return this._hint;
Akrone39cc862018-04-25 15:16:11 +020060 },
61
62 /**
63 * Hide the menu just for the moment,
Akron95abaf42018-04-26 15:33:22 +020064 * without cleaning up anything,
65 /* but resetting the prefix.
Akrone39cc862018-04-25 15:16:11 +020066 */
67 hideWithoutDestruction : function () {
68 this.element().classList.remove("visible");
Akron95abaf42018-04-26 15:33:22 +020069 if (this._hint) {
Akrone39cc862018-04-25 15:16:11 +020070 this._hint.inputField().element().focus();
Akron5746ecf2018-06-23 10:57:24 +020071 this.onHide();
Akron95abaf42018-04-26 15:33:22 +020072 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000073 }
74 };
75});