blob: 0f0d92a0e06cfdfe2e0f99ac0dff999a56322d37 [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) {
47 for (i in this._items) {
48 if (this._items[i].key() === key) {
49 return this._items[i].type();
50 }
51 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000052 }
53 };
54});