Finished vc builder (although the value change needs finetuning and there are no tests for the menu)
diff --git a/dev/js/src/vc/item.js b/dev/js/src/vc/item.js
index 7922bbd..c05fbad 100644
--- a/dev/js/src/vc/item.js
+++ b/dev/js/src/vc/item.js
@@ -1,43 +1,79 @@
// Field menu item
-define(['menu/item'], function (itemClass) {
+define(['menu/item', 'util'], function (itemClass) {
+
+ var loc = KorAP.Locale;
+
return {
+
+ /**
+ * Create new menu item.
+ * Pass two parameters: value and type.
+ * the value may be localized by a name in
+ * KorAP.Locale with the prefix 'VC_',
+ * e.g. 'VC_subTitle'.
+ */
create : function (params) {
return Object.create(itemClass)
.upgradeTo(this)
._init(params);
},
+ // Initialize item object
_init : function (params) {
if (params[0] === undefined)
throw new Error("Missing parameters");
- this._name = params[0];
- this._value = params[1];
- this._type = params[2];
+ this._key = params[0];
+ this._type = params[1];
+
+ var k = this._key;
+ this._name = loc["VC_" + k] ? loc["VC_" + k] : k;
this._lcField = ' ' + this._name.toLowerCase();
return this;
},
+ /**
+ * Override click event by passing all clicks
+ * to the menu object.
+ */
onclick : function (e) {
this.menu().release(
- this._name,
- this._value,
+ this._key,
this._type
);
e.halt();
},
+ /**
+ * Get the name of the item.
+ * This is a potential localized version
+ * of the value.
+ */
name : function () {
return this._name;
},
+ /**
+ * Get the type of the item.
+ */
type : function () {
return this._type;
},
+ /**
+ * Get the key of the item.
+ */
+ key : function () {
+ return this._key;
+ },
+
+ /**
+ * Get the HTML element associated with the item.
+ */
element : function () {
+
// already defined
if (this._element !== undefined)
return this._element;
@@ -45,7 +81,7 @@
// Create list item
var li = document.createElement("li");
li.setAttribute("data-type", this._type);
- li.setAttribute("data-value", this._value);
+ li.setAttribute("data-key", this._key);
// Connect action
li["onclick"] = this.onclick.bind(this);