Fix selectMenu test suite
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index eafb021..90592ec 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -140,9 +140,12 @@
};
// Replace QL select menus with KorAP menus
- selectMenuClass.create(
- document.getElementById('ql-field').parentNode
- ).limit(5);
+ var qlField = document.getElementById('ql-field');
+ if (qlField !== null) {
+ selectMenuClass.create(
+ document.getElementById('ql-field').parentNode
+ ).limit(5);
+ };
var result = document.getElementById('resultinfo');
var resultButton = null;
diff --git a/dev/js/src/selectMenu.js b/dev/js/src/selectMenu.js
index db5a52b..d8db4cd 100644
--- a/dev/js/src/selectMenu.js
+++ b/dev/js/src/selectMenu.js
@@ -5,88 +5,106 @@
return {
create : function (element) {
- var select = element.getElementsByTagName('select')[0];
+ var select = element.getElementsByTagName('select')[0];
- // Prepare list before object upgras
- var list = [];
- var options = select.getElementsByTagName('option');
+ if (select === null)
+ return;
- for (var i = 0; i < options.length; i++) {
+ // Prepare list before object upgras
+ var list = [];
+ var options = select.getElementsByTagName('option');
- var item = options.item(i);
- var opt = [
- item.textContent,
- item.getAttribute('value')
- ];
+ // Iterate through options list
+ for (var i = 0; i < options.length; i++) {
- if (item.hasAttribute('desc'))
- opt.push(item.getAttribute('desc'));
+ // Get option item and add to list
+ var item = options.item(i);
+ var opt = [
+ item.textContent,
+ item.getAttribute('value')
+ ];
- list.push(opt);
- };
+ // If the item has an attribute - list
+ if (item.hasAttribute('desc'))
+ opt.push(item.getAttribute('desc'));
- // Create object with list
- var obj = Object.create(menuClass).upgradeTo(this)
- ._init(list, {
- itemClass : selectMenuItemClass
- });
+ list.push(opt);
+ };
- obj._container = element;
- obj._select = select;
- obj._select.style.display = 'none';
+ // Create object with list
+ var obj = Object.create(menuClass).upgradeTo(this)
+ ._init(list, {
+ itemClass : selectMenuItemClass
+ });
- // Create title
- obj._title = obj._container.appendChild(document.createElement('span'));
- obj._title.appendChild(document.createTextNode(''));
- obj._container.appendChild(obj.element());
+ obj._container = element;
+ obj._select = select;
+ obj._select.style.display = 'none';
- obj._container.addEventListener('click', obj.showSelected.bind(obj));
+ // Create title
+ obj._title = obj._container.appendChild(document.createElement('span'));
+ obj._title.appendChild(document.createTextNode(''));
+ obj._container.appendChild(obj.element());
- // Add index information to each item
- for (i in obj._items) {
- obj._items[i]._index = i;
- };
+ // Show the menu
+ obj._container.addEventListener('click', obj.showSelected.bind(obj));
- // This is only domspecific
- obj.element().addEventListener('blur', function (e) {
- this.menu.hide();
- this.menu.showTitle();
- });
+ // Add index information to each item
+ for (i in obj._items) {
+ obj._items[i]._index = i;
+ };
+ // This is only domspecific
+ obj.element().addEventListener('blur', function (e) {
+ this.menu.hide();
+ this.menu.showTitle();
+ });
- // In case another tool changes
- // the option via JS - this needs
- // to be reflected!
- select.addEventListener('change', function (e) {
- this.showTitle();
- }.bind(obj));
+ // In case another tool changes
+ // the option via JS - this needs
+ // to be reflected!
+ select.addEventListener('change', function (e) {
+ this.showTitle();
+ }.bind(obj));
- obj.showTitle();
- return obj;
+ // Show the title
+ obj.showTitle();
+ return obj;
},
+ /**
+ * Get or set the selection index
+ */
select : function (index) {
- if (arguments.length > 0) {
- this._selected = index;
- this._select.selectedIndex = index;
- };
+ if (arguments.length > 0) {
+ this._selected = index;
+ this._select.selectedIndex = index;
+ };
- return this._selected || 0;
+ return this._selected || 0;
},
+ /**
+ * Show the select menu
+ */
showSelected : function () {
- this._title.style.display = 'none';
- this._selected = this._select.selectedIndex;
- this.show(this._selected);
- this.focus();
+ this._title.style.display = 'none';
+ this._selected = this._select.selectedIndex;
+ this.show(this._selected);
+ this.focus();
},
+ /**
+ * Show the title
+ */
showTitle : function () {
- var s = this.select();
- this._title.textContent = this.item(
- this.select()
- ).title();
- this._title.style.display = 'inline';
+
+ // Get the selection context
+ var s = this.select();
+ this._title.textContent = this.item(
+ this.select()
+ ).title();
+ this._title.style.display = 'inline';
}
}
}
diff --git a/dev/js/src/selectMenu/item.js b/dev/js/src/selectMenu/item.js
index cc6cdf0..75003b8 100644
--- a/dev/js/src/selectMenu/item.js
+++ b/dev/js/src/selectMenu/item.js
@@ -11,7 +11,7 @@
*/
create : function (params) {
return Object.create(itemClass)
- .upgradeTo(this)._init(params);
+ .upgradeTo(this)._init(params);
},
/**