blob: 40dbab0e2ff4805d4be6da75b293008bfc3a5dc3 [file] [log] [blame]
Nils Diewald4c221252015-04-21 20:19:25 +00001/**
2 * Menu showing all key fields.
3 */
Akron88d237e2020-10-21 08:05:18 +02004"use strict";
5
6define([
7 'menu',
8 'vc/item',
9 'vc/prefix'
10], function (
11 menuClass,
12 itemClass,
13 prefixClass) {
Akron0b489ad2018-02-02 16:49:32 +010014
Nils Diewald0e6992a2015-04-14 20:13:52 +000015 return {
Akron88d237e2020-10-21 08:05:18 +020016
Nils Diewald0e6992a2015-04-14 20:13:52 +000017 create : function (params) {
Akron88d237e2020-10-21 08:05:18 +020018 const obj = Object.create(menuClass)
19 .upgradeTo(this)
20 ._init(params, {
21 itemClass : itemClass,
22 prefixClass : prefixClass
23 });
Nils Diewald7148c6f2015-05-04 15:07:53 +000024 obj.limit(6);
25
26 // This is only domspecific
Akron88d237e2020-10-21 08:05:18 +020027 obj.element().addEventListener(
28 'blur', function (e) {
29 this.menu.hide();
30 }
31 );
Akrone4961b12017-05-10 21:04:46 +020032
Nils Diewald7148c6f2015-05-04 15:07:53 +000033 return obj;
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000034 },
Nils Diewald4c221252015-04-21 20:19:25 +000035
Akronddc98a72018-04-06 17:33:52 +020036
Nils Diewald4c221252015-04-21 20:19:25 +000037 /**
38 * Register callback for click event.
39 */
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000040 released : function (cb) {
41 this._cb = cb;
42 },
Nils Diewald4c221252015-04-21 20:19:25 +000043
Akronddc98a72018-04-06 17:33:52 +020044
Nils Diewald4c221252015-04-21 20:19:25 +000045 /**
46 * A click event was released
47 */
48 release : function (key, type) {
Nils Diewald1fcb2ad2015-04-20 19:19:18 +000049 if (this._cb !== undefined)
Akrone4961b12017-05-10 21:04:46 +020050 this._cb(key, type);
Akronddc98a72018-04-06 17:33:52 +020051 },
52
Akron88d237e2020-10-21 08:05:18 +020053
Akronddc98a72018-04-06 17:33:52 +020054 /**
55 * Return a key type based on a key.
56 * This is a linear search, but should work okay for small
57 * VCs and small key lists.
58 */
59 typeOf : function (key) {
Akron678c26f2020-10-09 08:52:50 +020060 const found = this._items.find(i => i.key() === key);
Akron88d237e2020-10-21 08:05:18 +020061
Akron678c26f2020-10-09 08:52:50 +020062 if (found)
63 return found.type();
Nils Diewald0e6992a2015-04-14 20:13:52 +000064 }
65 };
66});