blob: 9f6fc0685fbbead0d49bbf514611b195c8bdc82d [file] [log] [blame]
Akron48b1e4d2015-06-17 18:47:01 +02001define(['menu/item', 'util'], function (itemClass) {
2
3 var loc = KorAP.Locale;
4
5 return {
6
7 /**
8 * Create new menu item.
9 * Pass two parameters: value and type.
10 * the value may be localized by a name in
11 * KorAP.Locale with the prefix 'VC_',
12 * e.g. 'VC_subTitle'.
13 */
14 create : function (params) {
15 return Object.create(itemClass)
Akrone4961b12017-05-10 21:04:46 +020016 .upgradeTo(this)
17 ._init(params);
Akron48b1e4d2015-06-17 18:47:01 +020018 },
19
20 // Initialize item object
21 _init : function (params) {
22 if (params[0] === undefined)
Akrone4961b12017-05-10 21:04:46 +020023 throw new Error("Missing parameters");
Akron48b1e4d2015-06-17 18:47:01 +020024
25 this._id = params[0];
26 this._name = params[1];
27 this._desc = params[2];
28
29 this._lcField = ' ' + this._name.toLowerCase();
30 this._lcField += ' ' + this._desc.toLowerCase();
31
32 return this;
33 },
34
35 /**
36 * Override click event by passing all clicks
37 * to the menu object.
38 */
39 onclick : function (e) {
40 this.menu().release(
Akrone4961b12017-05-10 21:04:46 +020041 this._id,
42 this._name
Akron48b1e4d2015-06-17 18:47:01 +020043 );
44 e.halt();
45 },
46
47 /**
48 * Get the name of the item.
49 */
50 name : function () {
51 return this._name;
52 },
53
54 /**
55 * Get the identifier of the item.
56 */
57 id : function () {
58 return this._id;
59 },
60
61 /**
62 * Get the description of the item.
63 */
64 desc : function () {
65 return this._desc;
66 },
67
68 /**
69 * Get the HTML element associated with the item.
70 */
71 element : function () {
72
73 // already defined
74 if (this._element !== undefined)
Akrone4961b12017-05-10 21:04:46 +020075 return this._element;
Akron48b1e4d2015-06-17 18:47:01 +020076
77 // Create list item
78 var li = document.createElement("li");
79 li.setAttribute("data-type", this._type);
80 li.setAttribute("data-key", this._key);
81
82 // Connect action
83 li["onclick"] = this.onclick.bind(this);
84
Akron0b489ad2018-02-02 16:49:32 +010085 li.addT(this._name);
Akron48b1e4d2015-06-17 18:47:01 +020086 return this._element = li;
87 }
88 }
89});