Added lengthFieldClass indirection
diff --git a/Changes b/Changes
index eb4d59c..985c69e 100755
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
-0.19 2016-04-20
+0.19 2016-04-28
- Improved datepicker to enter date strings.
+ - Improved menus to have fixed length depending
+ on entry list.
0.18 2016-02-29
- Support for dashes in identifiers.
diff --git a/dev/demo/menudemo.js b/dev/demo/menudemo.js
index 2d66de9..10bbe06 100644
--- a/dev/demo/menudemo.js
+++ b/dev/demo/menudemo.js
@@ -2,12 +2,14 @@
baseUrl: '../js/src'
});
-require(['menu','menu/item', 'menu/prefix'], function (menuClass, itemClass, prefixClass) {
+require(['menu','menu/item', 'menu/prefix', 'menu/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) {
var OwnMenuItemClass = {
+
create : function (params) {
return Object.create(itemClass).upgradeTo(this)._init(params);
},
+
content : function (content) {
if (arguments.length === 1) {
this._content = content;
@@ -51,7 +53,7 @@
create : function (params) {
var obj = Object.create(menuClass)
.upgradeTo(this)
- ._init(OwnMenuItemClass, OwnPrefixClass, params);
+ ._init(OwnMenuItemClass, OwnPrefixClass, lengthFieldClass, params);
obj._firstActive = true;
return obj;
}
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 30bf793..65fcc82 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -2,9 +2,9 @@
var menuItemClass = require('menu/item');
var prefixClass = require('menu/prefix');
- var menuClass = require('menu');
var lengthFieldClass = require('menu/lengthField');
-
+ var menuClass = require('menu');
+
// The OwnMenu item
KorAP.OwnMenuItem = {
create : function (params) {
@@ -32,7 +32,7 @@
create : function (params) {
return Object.create(menuClass)
.upgradeTo(KorAP.OwnMenu)
- ._init(KorAP.OwnMenuItem, undefined, params);
+ ._init(KorAP.OwnMenuItem, undefined, undefined, params);
}
};
@@ -106,7 +106,7 @@
create : function (context, params) {
var obj = Object.create(menuClass)
.upgradeTo(KorAP.HintMenu)
- ._init(KorAP.HintMenuItem, undefined, params);
+ ._init(KorAP.HintMenuItem, undefined, undefined, params);
obj._context = context;
return obj;
}
@@ -1158,14 +1158,14 @@
it('should be extensible', function () {
var l = lengthFieldClass.create();
- l.add('Baum');
+ l.add(['Baum']);
expect(l.element().children.length).toEqual(1);
expect(l.element().children[0].nodeName).toEqual('SPAN');
- expect(l.element().children[0].textContent).toEqual('Baum-');
- l.add('Fragezeichen');
+ expect(l.element().children[0].textContent).toEqual('Baum--');
+ l.add(['Fragezeichen']);
expect(l.element().children.length).toEqual(2);
expect(l.element().children[1].nodeName).toEqual('SPAN');
- expect(l.element().children[1].textContent).toEqual('Fragezeichen-');
+ expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
});
it('should be correctly initializable', function () {
diff --git a/dev/js/src/hint/lengthField.js b/dev/js/src/hint/lengthField.js
new file mode 100644
index 0000000..0662b89
--- /dev/null
+++ b/dev/js/src/hint/lengthField.js
@@ -0,0 +1,25 @@
+define(['menu/lengthField'], function (lengthFieldClass) {
+ return {
+
+ /**
+ * Create lengthField object for the hint helper menu.
+ */
+ create : function () {
+ return Object.create(lengthFieldClass).
+ upgradeTo(this)._init();
+ },
+
+ /**
+ * Override the prefix action.
+ */
+ add : function (param) {
+ this._element.appendChild(document.createElement('span'))
+ .appendChild(document.createTextNode(param[0] + '--'));
+
+ var desc = this._element.appendChild(document.createElement('span'));
+ desc.classList.add("desc");
+ desc.appendChild(document.createTextNode(param[2] + '--'));
+ this._element.appendChild(desc);
+ }
+ };
+});
diff --git a/dev/js/src/hint/menu.js b/dev/js/src/hint/menu.js
index 4704bd2..7d89e51 100644
--- a/dev/js/src/hint/menu.js
+++ b/dev/js/src/hint/menu.js
@@ -1,7 +1,10 @@
/**
* Hint menu
*/
-define(['menu', 'hint/item', 'hint/prefix'], function (menuClass, itemClass, prefixClass) {
+define(['menu',
+ 'hint/item',
+ 'hint/prefix',
+ 'hint/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) {
return {
/**
@@ -10,7 +13,7 @@
create : function (hint, context, params) {
var obj = Object.create(menuClass)
.upgradeTo(this)
- ._init(itemClass, prefixClass, params);
+ ._init(itemClass, prefixClass, lengthFieldClass, params);
obj._context = context;
obj._element.classList.add('hint');
obj._hint = hint;
diff --git a/dev/js/src/match/treemenu.js b/dev/js/src/match/treemenu.js
index 16f6306..fec7703 100644
--- a/dev/js/src/match/treemenu.js
+++ b/dev/js/src/match/treemenu.js
@@ -18,7 +18,7 @@
create : function (info, params) {
var obj = Object.create(menuClass)
.upgradeTo(this)
- ._init(itemClass, undefined, params);
+ ._init(itemClass, undefined, undefined, params);
obj.limit(6);
obj._info = info;
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index a8cf26a..420d0bc 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -15,7 +15,7 @@
'util'
], function (defaultItemClass,
defaultPrefixClass,
- lengthFieldClass) {
+ defaultLengthFieldClass) {
// Default maximum number of menu items
var menuLimit = 8;
@@ -154,7 +154,7 @@
},
// Initialize list
- _init : function (itemClass, prefixClass, params) {
+ _init : function (itemClass, prefixClass, lengthFieldClass, params) {
var that = this;
this._itemClass = itemClass || defaultItemClass;
@@ -168,7 +168,12 @@
this._prefix._menu = this;
// Add lengthField object
- this._lengthField = lengthFieldClass.create();
+ if (lengthFieldClass !== undefined) {
+ this._lengthField = lengthFieldClass.create();
+ }
+ else {
+ this._lengthField = defaultLengthFieldClass.create();
+ };
this._lengthField._menu = this;
@@ -223,7 +228,7 @@
// This may become circular
obj["_menu"] = this;
- this._lengthField.add(params[i][0]);
+ this._lengthField.add(params[i]);
this._items.push(obj);
};
diff --git a/dev/js/src/menu/lengthField.js b/dev/js/src/menu/lengthField.js
index 76958e4..b05221f 100644
--- a/dev/js/src/menu/lengthField.js
+++ b/dev/js/src/menu/lengthField.js
@@ -15,11 +15,16 @@
},
/**
- * Add string to lengthField.
+ * Upgrade this object to another object,
+ * while private data stays intact.
+ *
+ * @param {Object} An object with properties.
*/
- add : function (string) {
- this._element.appendChild(document.createElement('span'))
- .appendChild(document.createTextNode(string + '-'));
+ upgradeTo : function (props) {
+ for (var prop in props) {
+ this[prop] = props[prop];
+ };
+ return this;
},
/**
@@ -27,5 +32,13 @@
*/
element : function () {
return this._element;
+ },
+
+ /**
+ * Add string to lengthField.
+ */
+ add : function (param) {
+ this._element.appendChild(document.createElement('span'))
+ .appendChild(document.createTextNode(param[0] + '--'));
}
});
diff --git a/dev/js/src/vc/chooseitem.js b/dev/js/src/vc/chooseitem.js
index 81ee4ca..b2d3c1b 100644
--- a/dev/js/src/vc/chooseitem.js
+++ b/dev/js/src/vc/chooseitem.js
@@ -82,7 +82,7 @@
// Connect action
li["onclick"] = this.onclick.bind(this);
- li.ap pendChild(document.createTextNode(this._name));
+ li.appendChild(document.createTextNode(this._name));
return this._element = li;
}
}
diff --git a/dev/js/src/vc/choosemenu.js b/dev/js/src/vc/choosemenu.js
index 7e00d44..2ecb3b7 100644
--- a/dev/js/src/vc/choosemenu.js
+++ b/dev/js/src/vc/choosemenu.js
@@ -7,7 +7,7 @@
create : function (params) {
return Object.create(menuClass)
.upgradeTo(this)
- ._init(itemClass, undefined, params);
+ ._init(itemClass, undefined, undefined, params);
},
/**
diff --git a/dev/js/src/vc/menu.js b/dev/js/src/vc/menu.js
index 17ad073..fddb3f0 100644
--- a/dev/js/src/vc/menu.js
+++ b/dev/js/src/vc/menu.js
@@ -6,7 +6,7 @@
create : function (params) {
var obj = Object.create(menuClass)
.upgradeTo(this)
- ._init(itemClass, undefined, params);
+ ._init(itemClass, undefined, undefined, params);
obj.limit(6);
// This is only domspecific
diff --git a/dev/scss/header/menu.scss b/dev/scss/header/menu.scss
index 3652231..0016420 100644
--- a/dev/scss/header/menu.scss
+++ b/dev/scss/header/menu.scss
@@ -44,7 +44,6 @@
line-height: 0;
color: transparent;
}
- background-color: blue;
}
ul.menu > li,