blob: f2f4b2f179c69f857ca81858442bb70dd531ca0f [file] [log] [blame]
Nils Diewald4c221252015-04-21 20:19:25 +00001/**
2 * Menu showing all key fields.
3 */
Akrone4961b12017-05-10 21:04:46 +02004define(['menu', 'vc/item', 'vc/prefix'], function (menuClass, itemClass, prefixClass) {
Akron0b489ad2018-02-02 16:49:32 +01005
Nils Diewald0e6992a2015-04-14 20:13:52 +00006 return {
7 create : function (params) {
Nils Diewald7148c6f2015-05-04 15:07:53 +00008 var obj = Object.create(menuClass)
Akrone4961b12017-05-10 21:04:46 +02009 .upgradeTo(this)
10 ._init(params, {
11 itemClass : itemClass,
12 prefixClass : prefixClass
13 });
Nils Diewald7148c6f2015-05-04 15:07:53 +000014 obj.limit(6);
15
16 // This is only domspecific
17 obj.element().addEventListener('blur', function (e) {
Akrone4961b12017-05-10 21:04:46 +020018 this.menu.hide();
Nils Diewald7148c6f2015-05-04 15:07:53 +000019 });
Akrone4961b12017-05-10 21:04:46 +020020
Nils Diewald7148c6f2015-05-04 15:07:53 +000021 return obj;
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000022 },
Nils Diewald4c221252015-04-21 20:19:25 +000023
Akronddc98a72018-04-06 17:33:52 +020024
Nils Diewald4c221252015-04-21 20:19:25 +000025 /**
26 * Register callback for click event.
27 */
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000028 released : function (cb) {
29 this._cb = cb;
30 },
Nils Diewald4c221252015-04-21 20:19:25 +000031
Akronddc98a72018-04-06 17:33:52 +020032
Nils Diewald4c221252015-04-21 20:19:25 +000033 /**
34 * A click event was released
35 */
36 release : function (key, type) {
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000037 if (this._cb !== undefined)
Akrone4961b12017-05-10 21:04:46 +020038 this._cb(key, type);
Akronddc98a72018-04-06 17:33:52 +020039 },
40
41 /**
42 * Return a key type based on a key.
43 * This is a linear search, but should work okay for small
44 * VCs and small key lists.
45 */
46 typeOf : function (key) {
Akron678c26f2020-10-09 08:52:50 +020047 const found = this._items.find(i => i.key() === key);
48 if (found)
49 return found.type();
Nils Diewald0e6992a2015-04-14 20:13:52 +000050 }
51 };
52});