blob: 7d89e51d880fd9e6c2324fdb0c6e21b0255ae50e [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 () {
31 var input = this._hint.inputField();
32 input.container().classList.remove('active');
33 input.element().focus();
34 };
35
36 return obj;
37 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000038
39 /**
40 * The hint helper object,
41 * the menu is attached to.
42 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000043 hint : function () {
44 return this._hint;
45 }
46 };
47});