Introduce select list replacement
diff --git a/dev/js/runner/menu.html b/dev/js/runner/menu.html
index acf96d4..4d2bffa 100644
--- a/dev/js/runner/menu.html
+++ b/dev/js/runner/menu.html
@@ -18,8 +18,9 @@
}
});
require([
- 'lib/domReady!',
- 'spec/menuSpec'
+ 'lib/domReady!',
+ 'spec/menuSpec',
+ 'spec/selectMenuSpec'
],
function () {
if (jsApiReporter.finished === true)
diff --git a/dev/js/spec/selectMenuSpec.js b/dev/js/spec/selectMenuSpec.js
new file mode 100644
index 0000000..3be39fd
--- /dev/null
+++ b/dev/js/spec/selectMenuSpec.js
@@ -0,0 +1,50 @@
+define(
+ ['selectMenu'],
+ function (selectMenuClass) {
+
+ describe('KorAP.SelectMenu', function () {
+ var list = [
+ {
+ content : 'Poliqarp',
+ value : 'poliqarp',
+ desc : 'The Polish National Corpus QL'
+ },
+ {
+ content : 'Cosmas II',
+ value : 'cosmas2',
+ desc : 'The Polish National Corpus QL'
+ },
+ {
+ content : 'Annis',
+ value : 'annis'
+ },
+ {
+ content : 'CQL v1.2',
+ value : 'cql'
+ }
+ ];
+
+ it('should replace a select element', function () {
+ var div = document.createElement('div');
+ var element = div.appendChild(document.createElement('select'));
+ for (i in list) {
+ var opt = element.appendChild(document.createElement('option'));
+ opt.setAttribute('value', list[i].value);
+ opt.appendChild(document.createTextNode(list[i].content));
+ };
+
+ var menu = selectMenuClass.create(element);
+
+ expect(element.style.display).toEqual('none');
+
+ menu.show();
+
+ expect(menu.item(0).active()).toBe(true);
+ expect(menu.item(0).noMore()).toBe(true);
+
+ // TODO: Improve lcfield!!!!!!
+ expect(menu.shownItem(0).lcField()).toEqual(' poliqarp');
+ });
+ });
+ }
+);
diff --git a/dev/js/src/selectMenu.js b/dev/js/src/selectMenu.js
new file mode 100644
index 0000000..d51c31a
--- /dev/null
+++ b/dev/js/src/selectMenu.js
@@ -0,0 +1,43 @@
+define(
+ ['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'],
+ function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
+
+ return {
+ create : function (element) {
+ var obj = Object.create(menuClass);
+
+ obj._shadow = element;
+
+ var list = [];
+ var options = element.getElementsByTagName('option');
+
+ for (var i = 0; i < options.length; i++) {
+
+ var item = options.item(i);
+ var opt = [
+ item.textContent,
+ item.getAttribute('value')
+ ];
+
+ if (item.hasAttribute('desc'))
+ opt.push(item.getAttribute('desc'));
+
+ list.push(opt);
+ };
+
+
+ obj = obj.upgradeTo(this)
+ ._init(menuItemClass, prefixClass, lengthFieldClass, list);
+
+ obj._firstActive = true;
+
+ element.style.display = 'none';
+
+ if (element.parentNode)
+ element.parentNode.appendChild(obj.element());
+
+ return obj;
+ }
+ }
+ }
+);