blob: b7e0d496047f78901201002110a4dbaada893eaf [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Hint menu
3 */
Akronda5bd3a2020-10-16 17:37:49 +02004
5"use strict";
6
Akroncae907d2018-08-20 17:22:15 +02007define([
8 'menu',
Akron1ff3ac22016-04-28 16:30:45 +02009 'hint/item',
10 'hint/prefix',
Akroncae907d2018-08-20 17:22:15 +020011 'hint/lengthField'
12], function (
13 menuClass,
14 itemClass,
15 prefixClass,
16 lengthFieldClass) {
Nils Diewald7148c6f2015-05-04 15:07:53 +000017
Akroncae907d2018-08-20 17:22:15 +020018 return {
19
Nils Diewald7148c6f2015-05-04 15:07:53 +000020 /**
21 * Create new hint helper menu.
22 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000023 create : function (hint, context, params) {
24 var obj = Object.create(menuClass)
Akron72f73572017-12-05 12:31:09 +010025 .upgradeTo(this)
26 ._init(params, {
27 itemClass : itemClass,
28 prefixClass : prefixClass,
29 lengthFieldClass : lengthFieldClass
30 });
Nils Diewald0e6992a2015-04-14 20:13:52 +000031 obj._context = context;
Akron24aa0052020-11-10 11:00:34 +010032 obj._el.classList.add('hint');
Nils Diewald0e6992a2015-04-14 20:13:52 +000033 obj._hint = hint;
34
Nils Diewald20f7ace2015-05-07 12:51:34 +000035 // Make the top item always active
36 obj._firstActive = true;
37
Nils Diewald0e6992a2015-04-14 20:13:52 +000038 obj.element().addEventListener('blur', function (e) {
Akrone0789112018-08-31 14:32:04 +020039 this.menu.hide(); // WithoutDestruction();
Nils Diewald0e6992a2015-04-14 20:13:52 +000040 });
41
42 // Focus on input field on hide
43 obj.onHide = function () {
Akroncae907d2018-08-20 17:22:15 +020044 var h = this._hint;
45 h._inputField.element().focus();
46 if (h.active() !== null) {
47 if (h._alert.active) {
48 h._unshowAlert();
49 };
50 h.active(null);
51 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000052 };
53
54 return obj;
55 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000056
57 /**
58 * The hint helper object,
59 * the menu is attached to.
60 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000061 hint : function () {
62 return this._hint;
Nils Diewald0e6992a2015-04-14 20:13:52 +000063 }
64 };
65});