blob: dd99d1f7cebbd296131f2dc945991b163ff18f96 [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu
3 */
Akron1ff3ac22016-04-28 16:30:45 +02004define(['menu',
5 'hint/item',
6 'hint/prefix',
7 'hint/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) {
Nils Diewald0e6992a2015-04-14 20:13:52 +00008 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00009
10 /**
11 * Create new hint helper menu.
12 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000013 create : function (hint, context, params) {
14 var obj = Object.create(menuClass)
Akron72f73572017-12-05 12:31:09 +010015 .upgradeTo(this)
16 ._init(params, {
17 itemClass : itemClass,
18 prefixClass : prefixClass,
19 lengthFieldClass : lengthFieldClass
20 });
Nils Diewald0e6992a2015-04-14 20:13:52 +000021 obj._context = context;
22 obj._element.classList.add('hint');
23 obj._hint = hint;
24
Nils Diewald20f7ace2015-05-07 12:51:34 +000025 // Make the top item always active
26 obj._firstActive = true;
27
Nils Diewald0e6992a2015-04-14 20:13:52 +000028 // This is only domspecific
29 obj.element().addEventListener('blur', function (e) {
Akrone39cc862018-04-25 15:16:11 +020030 this.menu.hideWithoutDestruction();
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 });
32
33 // Focus on input field on hide
34 obj.onHide = function () {
Akron72f73572017-12-05 12:31:09 +010035 this._hint.unshow();
Nils Diewald0e6992a2015-04-14 20:13:52 +000036 };
37
38 return obj;
39 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000040
41 /**
42 * The hint helper object,
43 * the menu is attached to.
44 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000045 hint : function () {
46 return this._hint;
Akrone39cc862018-04-25 15:16:11 +020047 },
48
49 /**
50 * Hide the menu just for the moment,
51 * without cleaning up anything.
52 */
53 hideWithoutDestruction : function () {
54 this.element().classList.remove("visible");
55 if (this._hint)
56 this._hint.inputField().element().focus();
Nils Diewald0e6992a2015-04-14 20:13:52 +000057 }
58 };
59});