blob: a9a3fb2e054e75465c13046160e89698100705c8 [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) {
Akrone0789112018-08-31 14:32:04 +020036 this.menu.hide(); // WithoutDestruction();
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;
Nils Diewald0e6992a2015-04-14 20:13:52 +000060 }
61 };
62});