blob: 4704bd2d215131858ebd1b589acb150e284e85ef [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu
3 */
4define(['menu', 'hint/item', 'hint/prefix'], function (menuClass, itemClass, prefixClass) {
5 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +00006
7 /**
8 * Create new hint helper menu.
9 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000010 create : function (hint, context, params) {
11 var obj = Object.create(menuClass)
12 .upgradeTo(this)
13 ._init(itemClass, prefixClass, params);
14 obj._context = context;
15 obj._element.classList.add('hint');
16 obj._hint = hint;
17
Nils Diewald20f7ace2015-05-07 12:51:34 +000018 // Make the top item always active
19 obj._firstActive = true;
20
Nils Diewald0e6992a2015-04-14 20:13:52 +000021 // This is only domspecific
22 obj.element().addEventListener('blur', function (e) {
23 this.menu.hide();
24 });
25
26 // Focus on input field on hide
27 obj.onHide = function () {
28 var input = this._hint.inputField();
29 input.container().classList.remove('active');
30 input.element().focus();
31 };
32
33 return obj;
34 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000035
36 /**
37 * The hint helper object,
38 * the menu is attached to.
39 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000040 hint : function () {
41 return this._hint;
42 }
43 };
44});