blob: df27a1165be06ff97df48ffa584ddf7227c70acf [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)
Akron1ff3ac22016-04-28 16:30:45 +020016 ._init(itemClass, prefixClass, lengthFieldClass, params);
Nils Diewald0e6992a2015-04-14 20:13:52 +000017 obj._context = context;
18 obj._element.classList.add('hint');
19 obj._hint = hint;
20
Nils Diewald20f7ace2015-05-07 12:51:34 +000021 // Make the top item always active
22 obj._firstActive = true;
23
Nils Diewald0e6992a2015-04-14 20:13:52 +000024 // This is only domspecific
25 obj.element().addEventListener('blur', function (e) {
26 this.menu.hide();
27 });
28
29 // Focus on input field on hide
30 obj.onHide = function () {
Akron00cd4d12016-05-31 21:01:11 +020031 this._hint.unshow();
Nils Diewald0e6992a2015-04-14 20:13:52 +000032 };
33
34 return obj;
35 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000036
37 /**
38 * The hint helper object,
39 * the menu is attached to.
40 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000041 hint : function () {
42 return this._hint;
43 }
44 };
45});