blob: fcf3fc6d76b5dc79183da45695065b8a05344a32 [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) {
Akron72f73572017-12-05 12:31:09 +010030 this.menu.hide();
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;
47 }
48 };
49});