blob: 1763306d4727a5350f191fad19296e2c4c39517b [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)
15 .upgradeTo(this)
Akron7524be12016-06-01 17:31:33 +020016 ._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) {
30 this.menu.hide();
31 });
32
33 // Focus on input field on hide
34 obj.onHide = function () {
Akron00cd4d12016-05-31 21:01:11 +020035 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});