New menu class that has an entry at the very end, similar to the input
text prefix, that is always available
Change-Id: I03d8f689e37021d3daac6bf34f7d35f0e4d71999
diff --git a/dev/js/runner/all.html b/dev/js/runner/all.html
index 99d4799..52f996f 100644
--- a/dev/js/runner/all.html
+++ b/dev/js/runner/all.html
@@ -39,6 +39,7 @@
'spec/buttongroupSpec',
'spec/datepickerSpec',
'spec/menuSpec',
+ 'spec/alwaysMenuSpec',
'spec/selectMenuSpec',
'spec/panelSpec',
'spec/viewSpec',
diff --git a/dev/js/runner/alwaysMenu.html b/dev/js/runner/alwaysMenu.html
new file mode 100644
index 0000000..533e4da
--- /dev/null
+++ b/dev/js/runner/alwaysMenu.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Spec Runner for Menu Helper</title>
+ <link rel="shortcut icon" type="image/png" href="../lib/jasmine-2.1.1/jasmine_favicon.png">
+ <link rel="stylesheet" href="../lib/jasmine-2.1.1/jasmine.css">
+ <script src="../lib/require.js"></script>
+ <script>
+ require.config({
+ baseUrl: "../src",
+ paths: {
+ "lib" : "../lib",
+ "spec" : "../spec",
+ "jlib" : "lib/jasmine-2.1.1",
+ "jasmine" : ['../lib/jasmine-2.1.1/jasmine'],
+ "jasmine-html": ['../lib/jasmine-2.1.1/jasmine-html'],
+ "jasmine-boot": ['../lib/jasmine-2.1.1/boot']
+ },
+ shim : {
+ 'jasmine-html' : {
+ deps : ['jasmine']
+ },
+ 'jasmine-boot' : {
+ deps : ['jasmine','jasmine-html']
+ }
+ }
+ });
+ require(['jasmine-boot'], function () {
+ require([
+ 'spec/alwaysMenuSpec'
+ ],
+ function () {
+ window.onload();
+ });
+ });
+ </script>
+</head>
+<body>
+</body>
+</html>
diff --git a/dev/js/spec/alwaysMenuSpec.js b/dev/js/spec/alwaysMenuSpec.js
new file mode 100644
index 0000000..f849ebd
--- /dev/null
+++ b/dev/js/spec/alwaysMenuSpec.js
@@ -0,0 +1,1469 @@
+define(
+ ['alwaysmenu', 'menu/item', 'menu/prefix', 'menu/lengthField', 'alwaysentry'],
+ function (alwaysMenuClass, menuItemClass, prefixClass, lengthFieldClass, alwaysEntryClass) {
+
+ //These class definitions were taken from menuSpec for a guideline on how to procede
+
+ // The OwnAlwaysMenu item
+ const OwnAlwaysMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass).upgradeTo(OwnAlwaysMenuItem)._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ this._content = document.createTextNode(params[0]);
+ this._lcField = ' ' + this.content().textContent.toLowerCase();
+
+ return this;
+ }
+ };
+
+ // The OwnAlwaysMenu
+ let OwnAlwaysMenu = {
+ create : function (list) {
+ return alwaysMenuClass.create(list, { itemClass : OwnAlwaysMenuItem } )
+ .upgradeTo(OwnAlwaysMenu);
+ }
+ };
+
+
+
+ // HintMenuItem
+ const HintMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass)
+ .upgradeTo(HintMenuItem)
+ ._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined || params[1] === undefined)
+ throw new Error("Missing parameters");
+
+ this._name = params[0];
+ this._action = params[1];
+ this._lcField = ' ' + this._name.toLowerCase();
+
+ if (params.length > 2) {
+ this._desc = params[2];
+ this._lcField += " " + this._desc.toLowerCase();
+ };
+
+ return this;
+ },
+
+ name : function () {
+ return this._name;
+ },
+ action : function () {
+ return this._action;
+ },
+ desc : function () {
+ return this._desc;
+ },
+ element : function () {
+ // already defined
+ if (this._el !== undefined)
+ return this._el;
+
+ // Create list item
+ var li = document.createElement("li");
+ li.setAttribute("data-action", this._action);
+
+ // Create title
+ var name = document.createElement("strong");
+ name.appendChild(document.createTextNode(this._name));
+
+ li.appendChild(name);
+
+ // Create description
+ if (this._desc !== undefined) {
+ var desc = document.createElement("span");
+ desc.appendChild(document.createTextNode(this._desc));
+ li.appendChild(desc);
+ };
+ return this._el = li;
+ }
+ };
+
+
+ // HintMenu
+ const HintMenu = {
+ create : function (context, list) {
+ var obj = alwaysMenuClass.create(list, {itemClass : HintMenuItem} )
+ .upgradeTo(HintMenu);
+ obj._context = context;
+ return obj;
+ }
+ };
+
+
+ // The ComplexMenuItem
+ const ComplexMenuItem = {
+ create : function (params) {
+ return Object.create(menuItemClass)
+ .upgradeTo(ComplexMenuItem)
+ ._init(params);
+ },
+ content : function (content) {
+ if (arguments.length === 1) {
+ this._content = content;
+ };
+ return this._content;
+ },
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ var r = document.createElement('div');
+ for (var i = 1; i <= params.length; i++) {
+ var h = document.createElement('h' + i);
+ h.appendChild(document.createTextNode(params[i-1]));
+ r.appendChild(h);
+ };
+
+ this._content = r;
+ this._lcField = ' ' + this.content().textContent.toLowerCase();
+
+ return this;
+ }
+ };
+
+
+ describe('KorAP.AlwaysMenu', function () {
+ var list = [
+ ["Constituency", "c=", "Example 1"],
+ ["Lemma", "l="],
+ ["Morphology", "m=", "Example 2"],
+ ["Part-of-Speech", "p="],
+ ["Syntax", "syn="]
+ ];
+
+ var listMultiPrefix = [
+ ["PP","PP ","Personal Pronoun"],
+ ["PPP","PPP ","Personal Pronoun, Plural"],
+ ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."],
+ ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"],
+ ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"],
+ ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"],
+ ["PPS","PPS ","Personal Pronoun, Singular"],
+ ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"],
+ ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"],
+ ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"],
+ ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"],
+ ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"]
+ ];
+
+ var demolist = [
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author']
+ ];
+
+ var demolonglist = [
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author'],
+ ['Genre', 'genre'],
+ ['corpusID', 'corpusID'],
+ ['docID', 'docID'],
+ ['textID', 'textID'],
+ ];
+
+ it('should be initializable', function () {
+ var list = [
+ ["Constituency"],
+ ["Lemma"],
+ ["Morphology"],
+ ["Part-of-Speech"],
+ ["Syntax"]
+ ];
+
+ var menu = OwnAlwaysMenu.create(list);
+ menu._firstActive = true;
+ expect(menu.itemClass()).toEqual(OwnAlwaysMenuItem);
+ expect(menu._notItemElements).toEqual(4);
+ expect(menu.element().getElementsByClassName("pref").length).toEqual(2); //TODO: new scss = new class
+ expect(menu.element().getElementsByClassName("pref")[1].innerHTML).toEqual("Speichern");
+ expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
+ //expect(menu.element().childNodes[3].innerHTML).toEqual("Speichern"); //?
+ // getElementsByClassName funktioniert bei allen Kindern.
+
+
+ // view
+ menu.show();
+
+ expect(menu.alwaysEntry().active()).toBe(false);
+ });
+
+ it('should be visible', function () {
+ var menu = HintMenu.create("cnx/", list);
+ expect(menu.removeItems()).toBe(undefined);
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.element().getElementsByTagName("li")[1].getAttribute("data-action")).toEqual("l=");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].classList.contains("no-more")).toBe(false);
+ });
+
+ it('should be filterable', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu.limit(3);
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o");
+ expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
+ expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].classList.contains("no-more")).toBe(true);
+
+ menu.limit(2);
+
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o");
+ expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
+ expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.element().getElementsByTagName("li")[2]).toBe(undefined);
+
+ // Check boundaries
+ expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2]).toBe(undefined);
+
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toEqual("e");
+ expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e");
+ expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.element().getElementsByTagName("li")[2]).toBe(undefined);
+
+ menu.limit(5);
+ expect(menu.prefix("a").show()).toBe(true);
+ expect(menu.alwaysEntryValue("a").alwaysEntryValue()).toEqual("a");
+ expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a");
+ expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
+ expect(menu.element().getElementsByTagName("li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
+ expect(menu.element().getElementsByTagName("li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
+ expect(menu.element().getElementsByTagName("li")[5]).toBe(undefined);
+ });
+
+
+ it('should be nextable', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu._firstActive = true;
+
+ expect(menu._prefix.active()).toBe(false);
+
+ // Show only 3 items
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (1)
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (2)
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (3)
+ // scroll!
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (4)
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (5) - Entry / Speichern
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(true);
+
+ // Activate next (6) - ROLL
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Active next (7)
+ menu.next();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ expect(menu._prefix.active()).toBe(false);
+ });
+
+ it('should be nextable without active field', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ menu.next();
+ expect(menu.shownItem(0).active()).toEqual(true);
+ });
+
+
+ it('should be prevable', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu._firstActive = true;
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntryValue()).toBe("");
+
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+
+ // Activate prev (1) - roll to bottom
+ menu.prev();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(true);
+
+ // Activate prev (2)
+ menu.prev();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate prev (3)
+ menu.prev();
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate prev (4)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Syntax");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate prev (5)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Lemma");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate prev (6)
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Lemma");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Morphology");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate next (7)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Lemma");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).name()).toEqual("Morphology");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Activate prev (8)
+ menu.prev();
+
+ // Activate prev (9) - Roll again
+ menu.prev();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Lemma");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Morphology");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(true);
+
+ // Activate prev (10)
+ menu.prev()
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Syntax");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined);
+ expect(menu.alwaysEntry().active()).toBe(false);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntryValue()).toBe("");
+ expect(menu.alwaysEntry().element().innerHTML).toBe("Speichern");
+
+ });
+
+ it('should be prevable without active field', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ menu.prev();
+ expect(menu.alwaysEntry().active()).toBe(true);
+ expect(menu.shownItem(2).active()).toEqual(false);
+ expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
+ menu.prev()
+ expect(menu.shownItem(2).active()).toEqual(true);
+ expect(menu.shownItem(2).lcField()).toEqual(' syntax');
+ });
+
+ it('should be navigatable and filterable (prefix = "o")', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu._firstActive = true;
+ menu.limit(2);
+
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (2)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (3) - to prefix
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Next (4) - to entry
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(true);
+
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ expect(menu.prefix("o").show()).toBe(true);
+ expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+ });
+
+
+ it('should be navigatable and filterable (prefix = "ex", "e")', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu._firstActive = true;
+
+ menu.limit(2);
+ expect(menu.prefix("ex").show()).toBe(true);
+ expect(menu.alwaysEntryValue("ex").alwaysEntryValue()).toBe("ex");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu.alwaysEntryValue()).toBe("ex");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Next (2)
+ menu.next();
+
+ expect(menu.prefix()).toEqual('ex');
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu.alwaysEntryValue()).toBe("ex");
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Reset limit
+ menu.limit(5);
+
+ // Change show
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toBe("e");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Next (1)
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.prefix()).toEqual('e');
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Next (2)
+ menu.next();
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu.alwaysEntry().active()).toBe(false);
+
+ // Next (2.5)
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(true);
+
+ // Next (3)
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("Constituency");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Morphology");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ expect(menu.alwaysEntryValue()).toBe("e");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+ });
+
+ it('should be filterable (multiple prefix = "pro sin")', function () {
+ var menu = HintMenu.create("drukola/p=", listMultiPrefix);
+ menu._firstActive = true;
+
+ menu.limit(2);
+ expect(menu.prefix("pro sin").show()).toBe(true);
+ expect(menu.alwaysEntryValue("pro sin").alwaysEntryValue()).toBe("pro sin");
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu.alwaysEntry().active()).toBe(false);
+ expect(menu.shownItem(0).name()).toEqual("PPS");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual(
+ "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>"
+ );
+
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("PPSA");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>");
+ expect(menu.shownItem(1).active()).toBe(false);
+
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+ it('should be filterable (trimming = " p")', function () {
+ var menu = HintMenu.create("/p=", listMultiPrefix);
+ // menu._firstActive = true;
+
+ menu.limit(2);
+ expect(menu.show()).toBe(true);
+ menu._prefix.add(" ");
+ menu._entry.add(" ")
+ expect(menu.show()).toBe(true);
+ menu._prefix.add("p")
+ menu._entry.add("p")
+ expect(menu.alwaysEntryValue()).toBe(" p");
+ expect(menu.show()).toBe(true);
+ expect(menu.shownItem(0).name()).toEqual("PP");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual(
+ "<strong><mark>P</mark><mark>P</mark></strong>"+
+ "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>"
+ );
+ });
+
+
+
+ it('should ignore navigation with failing prefix', function () {
+ var menu = HintMenu.create("cnx/", list);
+ menu.limit(2);
+ expect(menu.show()).toBe(true);
+
+ menu.next();
+
+ expect(menu.prefix("exit").show()).toBe(true);
+ expect(menu.element().querySelector('li')).toBe(null);
+ expect(menu.shownItem(0)).toBeUndefined();
+ expect(menu._prefix.active()).toBe(true);
+
+ menu.next();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(true);
+
+ menu.next();
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu._entry.active()).toBe(false);
+
+ menu.prev();
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(true);
+
+ menu.prev();
+ expect(menu._prefix.active()).toBe(true);
+ expect(menu._entry.active()).toBe(false);
+
+ });
+
+ it('should be navigatable with prefix', function () {
+ var menu = HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+
+ menu._prefix.add('a');
+ menu._entry.add('a');
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("a");
+ expect(menu.alwaysEntryValue()).toEqual("a");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
+
+ menu._prefix.add('u');
+ menu._entry.add('u');
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("au");
+ expect(menu.alwaysEntryValue()).toEqual("au");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
+
+ menu._prefix.chop();
+ menu._entry.chop();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("a");
+ expect(menu.alwaysEntryValue()).toEqual("a");
+ expect(menu.shownItem(0).name()).toEqual("Autor");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
+
+ menu._prefix.chop();
+ menu._entry.chop();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu._prefix.chop();
+ menu._entry.chop();
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Länge");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Länge</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Länge");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Autor");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>");
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu.shownItem(3)).toBe(undefined);
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Länge");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Autor");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(true);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
+ expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
+ expect(menu.shownItem(2).active()).toBe(false);
+ });
+
+
+ it('should be navigatable with a prefix (1)', function () {
+ var menu = HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ expect(menu.alwaysEntryValue()).toEqual("");
+
+ // Add prefix in uppercase - but check in lowercase
+ menu.prefix('El');
+ menu.alwaysEntryValue('El');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(true);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ menu.prev()
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu.prefix()).toEqual("El");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("El");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+
+ it('should be navigatable with a prefix (2)', function () {
+ var menu = HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ menu.prefix('el');
+ expect(menu.alwaysEntryValue()).toEqual("");
+ menu.alwaysEntryValue('el');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntryValue()).toEqual("el");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(true);
+
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu._entry.active()).toEqual(false);
+
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+ it('should be navigatable with a prefix (3)', function () {
+ var menu = HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+ expect(menu.prefix()).toEqual("");
+ menu.prefix('el');
+ expect(menu.alwaysEntryValue()).toEqual("");
+ expect(menu.alwaysEntry().value()).toEqual("");
+ menu.alwaysEntryValue('el');
+ expect(menu.show()).toBe(true);
+
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu.alwaysEntry().value()).toEqual("el");
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(true);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Backward
+ menu.prev();
+ expect(menu._prefix.active()).toEqual(true);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(true);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+
+ // Forward
+ menu.next();
+ expect(menu.prefix()).toEqual("el");
+ expect(menu._prefix.active()).toEqual(false);
+ expect(menu._entry.active()).toEqual(false);
+ expect(menu.shownItem(0).name()).toEqual("Titel");
+ expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).name()).toEqual("Untertitel");
+ expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2)).toBe(undefined);
+ });
+
+
+
+ xit('should scroll to a chosen value after prefixing, if the chosen value is live');
+ });
+
+ describe('KorAP.AlwaysMenu.Entry', function () {
+ it('should be initializable', function () {
+ var p = alwaysEntryClass.create();
+ expect(p.element().classList.contains('pref')).toBeTruthy();
+ expect(p.isSet()).not.toBeTruthy();
+ expect(p.element().innerHTML).toEqual("Speichern");
+ expect(p.value()).toEqual("");
+
+ /*
+ expect(mi.lcField()).toEqual(' baum');
+ */
+
+ });
+
+ it('should be initializable with a different name', function () {
+ var p = alwaysEntryClass.create("Save");
+ expect(p.element().classList.contains('pref')).toBeTruthy();
+ expect(p.isSet()).not.toBeTruthy();
+ expect(p.element().innerHTML).toEqual("Save");
+ expect(p.value()).toEqual("");
+
+ /*
+ expect(mi.lcField()).toEqual(' baum');
+ */
+
+ });
+
+ it('should be modifiable', function () {
+ var p = alwaysEntryClass.create();
+ expect(p.value()).toEqual('');
+ expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
+
+ // Set string
+ expect(p.value('Test')).toEqual('Test');
+ expect(p.value()).toEqual('Test');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ // Add string
+ expect(p.add('ified')).toEqual('Testified');
+ expect(p.value()).toEqual('Testified');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ // Clear string
+ p.clear();
+ expect(p.value()).toEqual('');
+ expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
+
+ // Set string
+ expect(p.value('Test')).toEqual('Test');
+ expect(p.value()).toEqual('Test');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ expect(p.chop()).toEqual('Tes');
+ expect(p.value()).toEqual('Tes');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ expect(p.chop()).toEqual('Te');
+ expect(p.value()).toEqual('Te');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ expect(p.chop()).toEqual('T');
+ expect(p.value()).toEqual('T');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ expect(p.chop()).toEqual('');
+ expect(p.value()).toEqual('');
+ expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
+ });
+
+ it('should be activatable', function () {
+ var p = alwaysEntryClass.create();
+ expect(p.value()).toEqual('');
+ expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
+
+ expect(p.value('Test')).toEqual('Test');
+ expect(p.element().firstChild.nodeValue).toEqual('Speichern');
+
+ expect(p.active()).not.toBeTruthy();
+ expect(p.element().classList.contains('active')).not.toBeTruthy();
+
+ p.active(true);
+ expect(p.active()).toBeTruthy();
+ expect(p.element().classList.contains('active')).toBeTruthy();
+ });
+ });
+
+ describe('KorAP.AlwaysMenu.Slider', function () {
+
+ var demolonglist = [
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author'],
+ ['Genre', 'genre'],
+ ['corpusID', 'corpusID'],
+ ['docID', 'docID'],
+ ['textID', 'textID'],
+ ];
+
+ it('should correctly be initializable', function () {
+ var list = [
+ ["Constituency"],
+ ["Lemma"],
+ ["Morphology"],
+ ["Part-of-Speech"],
+ ["Syntax"]
+ ];
+
+ var menu = OwnAlwaysMenu.create(list);
+
+ menu._firstActive = true;
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(0);
+ expect(menu.position).toEqual(0);
+ });
+
+ it('should correctly move on arrow keys', function () {
+ var list = [
+ ["Constituency"],
+ ["Lemma"],
+ ["Morphology"],
+ ["Part-of-Speech"],
+ ["Syntax"]
+ ];
+
+ var menu = OwnAlwaysMenu.create(list);
+
+ menu._firstActive = true;
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(0);
+ expect(menu.position).toEqual(1);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(0);
+ expect(menu.position).toEqual(2);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(1);
+ expect(menu.position).toEqual(3);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(true);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(2);
+ expect(menu.position).toEqual(4);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(true);
+ expect(menu.slider().offset()).toEqual(2);
+ expect(menu.position).toEqual(7);
+
+ menu.next();
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu._prefix.active()).toBe(false);
+ expect(menu._entry.active()).toBe(false);
+ expect(menu.slider().offset()).toEqual(0);
+ expect(menu.position).toEqual(0);
+
+ expect(menu.slider()._slider.style.height).toEqual('60%');
+ });
+
+ });
+
+ describe('KorAP.AlwaysMenu.Benchmark', function () {
+ var menu = alwaysMenuClass.create([
+ ['Titel', 'title'],
+ ['Untertitel', 'subTitle'],
+ ['Veröffentlichungsdatum', 'pubDate'],
+ ['Länge', 'length'],
+ ['Autor', 'author']
+ ]);
+
+ menu.limit(3).show();
+
+ // Some actions
+ menu.next();
+ menu.next();
+ menu.prev();
+ menu.prev();
+ menu.prev();
+
+ menu.pageDown();
+ menu.pageUp();
+
+ // There is no fourth item in the list!
+ menu.prefix('e').show(4);
+ menu.next();
+ menu.next();
+ menu.prev();
+ menu.prev();
+ menu.prev();
+ });
+ });
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 22f3c77..c24a75b 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -380,6 +380,7 @@
expect(menu.element().nodeName).toEqual('UL');
expect(menu.element().classList.contains('visible')).toBeFalsy();
expect(menu.limit()).toEqual(8);
+ expect(menu._notItemElements).toEqual(3);
menu.limit(9);
expect(menu.limit()).toEqual(9);
diff --git a/dev/js/src/alwaysentry.js b/dev/js/src/alwaysentry.js
new file mode 100644
index 0000000..f3f7b42
--- /dev/null
+++ b/dev/js/src/alwaysentry.js
@@ -0,0 +1,43 @@
+/**
+ * An entry in menus that is always
+ * displayed, with a string and onClick functionality
+ * uses menu/prefix.js as prototype and doesn't change much, all
+ * functionality comes from the alwaysmenu
+ *
+ *
+ * @author Leo Repp
+ */
+
+
+"use strict";
+
+define([
+ 'menu/prefix'
+], function (prefixClass) {
+
+ return {
+
+ /**
+ * Create new always visible menu entry object.
+ * Like a prefix Object, always visible, for some defined action
+ */
+ create : function (text) {
+ const obj = prefixClass.create()
+ .upgradeTo(this)
+ ._init();
+ obj._el.innerHTML = text || "Speichern";
+ //dont forget to adjust alwaysMenuSpec - alwaysEntry!
+ return obj;
+ },
+
+ _update : function () {
+ if (this._string.length!==0){ // I assume that this is a sufficient criterium for infering that the prefix is active
+ this._el.style.bottom="-27px";
+ } else if (this._string.length===0) {
+ this._el.style.bottom="0px";
+ }
+ return this._string; // No need to change the text (=innerHTML)
+ },
+
+ };
+});
diff --git a/dev/js/src/alwaysmenu.js b/dev/js/src/alwaysmenu.js
new file mode 100644
index 0000000..4bcf9da
--- /dev/null
+++ b/dev/js/src/alwaysmenu.js
@@ -0,0 +1,546 @@
+/**
+ *
+ * A Version of the menu class, that
+ * has an always displayed entry that can be
+ * clicked and contains text
+ *
+ * This entry button may or may not be displayed on top of objects
+ * lying under (>y) this menu. See alwaysentry update: negative absolute
+ * y coordinate.
+ *
+ * @author Leo Repp
+ */
+
+"use strict";
+define([
+ 'menu',
+ 'menu/item',
+ 'menu/prefix',
+ 'menu/lengthField',
+ 'alwaysentry',
+ 'util'
+], function (
+ menuClass,
+ defaultItemClass,
+ defaultPrefixClass,
+ defaultLengthFieldClass,
+ defaultAlwaysEntryClass) {
+
+ return {
+
+ /**
+ * Create new menu with an always visible entry.
+ * @this {AlwaysMenu}
+ * @constructor
+ * @param {Object["like this"]} params Object with attributes prefixCLass, itemClass, lengthFieldClass, alwaysEntryClass
+ * @param {Array.<Array.<string>>} list list of menu items
+ */
+ create : function (list, params) {
+ const obj = menuClass.create(list,params)
+ .upgradeTo(this)
+ ._init(list, params);
+
+ obj._el.classList.add('alwaysmenu');
+
+ //add entry object and allow for own entryClasses
+ if (params!==undefined && params["alwaysEntryClass"] !== undefined) {
+ obj._entry = params["alwaysEntryClass"].create();
+ } else {
+ obj._entry=defaultAlwaysEntryClass.create();
+ }
+ obj._entry._menu=obj;
+ obj._notItemElements=4;
+ // add entry to HTML element
+ obj._el.appendChild(obj._entry.element());
+
+ return obj;
+ },
+
+
+ /**
+ * Destroy this menu
+ * (in case you don't trust the
+ * mark and sweep GC)!
+ */
+ destroy : function () {
+ //based on menu.js
+ const t = this;
+
+ // Remove circular reference to "this" in menu
+ if (t._el != undefined)
+ delete t._el["menu"];
+
+ // Remove circular reference to "this" in items
+ t._items.forEach(function(i) {
+ delete i["_menu"];
+ });
+
+ // Remove circular reference to "this" in prefix
+ delete t._prefix['_menu'];
+ delete t._lengthField['_menu'];
+ delete t._slider['_menu'];
+ delete t._entry['_menu'];
+ },
+
+
+ // Arrow key and prefix treatment
+ _keydown : function (e) {
+ //based on menu.js
+ const t = this;
+
+ switch (_codeFromEvent(e)) {
+
+ case 27: // 'Esc'
+ e.halt();
+ t.hide();
+ break;
+
+ case 38: // 'Up'
+ e.halt();
+ t.prev();
+ break;
+
+ case 33: // 'Page up'
+ e.halt();
+ t.pageUp();
+ break;
+
+ case 40: // 'Down'
+ e.halt();
+ t.next();
+ break;
+
+ case 34: // 'Page down'
+ e.halt();
+ t.pageDown();
+ break;
+
+ case 39: // 'Right'
+ // "Use" this item
+ if (t._prefix.active())
+ break;
+
+
+ else if (t._entry.active()){
+ break;
+ };
+
+ const item = t.liveItem(t.position);
+
+ if (item["further"] !== undefined) {
+ item["further"].bind(item).apply();
+ };
+
+ e.halt();
+ break;
+
+ case 13: // 'Enter'
+ // Click on prefix
+ if (t._prefix.active())
+ t._prefix.onclick(e);
+ //Click on entry
+ else if (t._entry.active())
+ t._entry.onclick(e);
+ // Click on item
+ else
+ t.liveItem(t.position).onclick(e);
+ e.halt();
+ break;
+
+ case 8: // 'Backspace'
+ t._prefix.chop();
+ t._entry.chop();
+ t.show();
+ e.halt();
+ break;
+ };
+ },
+
+ // Add characters to prefix
+ _keypress : function (e) {
+ if (e.charCode !== 0) {
+ e.halt();
+
+ // Add prefix
+ this._prefix.add(
+ String.fromCharCode(_codeFromEvent(e))
+ );
+ this._entry.add(
+ String.fromCharCode(_codeFromEvent(e))
+ );
+
+ this.show();
+ };
+ },
+
+ /**
+ * Filter the list and make it visible.
+ * This is always called once the prefix changes.
+ *
+ * @param {string} Prefix for filtering the list
+ */
+ show : function (active) {
+ //only two new lines compared to menu.js show method (see NEW LINE)
+ const t = this;
+
+ // show menu based on initial offset
+ t._unmark(); // Unmark everything that was marked before
+ t.removeItems();
+
+ // Initialize the list
+ if (!t._initList()) {
+
+ // The prefix is not active
+ t._prefix.active(true);
+ //FIRST NEW LINE
+ t._entry.active(false);
+
+ // finally show the element
+ t._el.classList.add('visible');
+
+ return true;
+ };
+
+ let offset = 0;
+
+ // Set a chosen value to active and move the viewport
+ if (arguments.length === 1) {
+
+ // Normalize active value
+ if (active < 0) {
+ active = 0;
+ }
+ else if (active >= t.liveLength()) {
+ active = t.liveLength() - 1;
+ };
+
+ // Item is outside the first viewport
+ if (active >= t._limit) {
+ offset = active;
+ const newOffset = t.liveLength() - t._limit;
+ if (offset > newOffset) {
+ offset = newOffset;
+ };
+ };
+
+ t.position = active;
+ }
+
+ // Choose the first item
+ else if (t._firstActive) {
+ t.position = 0;
+ }
+
+ // Choose no item
+ else {
+ t.position = -1;
+ };
+
+ t.offset = offset;
+ t._showItems(offset); // Show new item list
+
+ // Make chosen value active
+ if (t.position !== -1) {
+ t.liveItem(t.position).active(true);
+ };
+
+ // The prefix is not active
+ t._prefix.active(false);
+ //SECOND NEW LINE
+ t._entry.active(false);
+
+ // finally show the element
+ t._el.classList.add('visible');
+
+ // Add classes for rolling menus
+ t._boundary(true);
+
+ return true;
+ },
+
+ /**
+ * Hide the menu and call the onHide callback.
+ */
+ hide : function () {
+ if (!this.dontHide) {
+ this.removeItems();
+ this._prefix.clear();
+ this._entry.clear();
+ this.onHide();
+ this._el.classList.remove('visible');
+ }
+ // this._el.blur();
+ },
+
+
+ /**
+ * The alwaysEntry object
+ * the menu is attached to.
+ */
+ alwaysEntry : function () {
+ return this._entry;
+ },
+
+ /**
+ * Get/Set the alwaysEntry Text
+ */
+ alwaysEntryValue : function (value) {
+ if (arguments.length === 1) {
+ this._entry.value(value);
+ return this;
+ };
+ return this._entry.value();
+ },
+
+ /**
+ * Delete all visible items from the menu element
+ */
+
+ /**
+ * Make the next item in the filtered menu active
+ */
+ next : function () {
+ //Hohe zyklomatische Komplexität
+ const t = this;
+ // Activate prefix and entry
+ const prefix = this._prefix;
+ const entry = this._entry;
+
+ // No list
+ if (t.liveLength() === 0){ //switch between entry and prefix
+ if (!prefix.isSet()){//It is entry and it will stay entry
+ entry.active(true);
+ prefix.active(false);//Question: do we need to activate entry?
+ return;
+ };
+ if (prefix.active() && !entry.active()){
+ t.position = 2; // ?
+ prefix.active(false);
+ entry.active(true); //activate entry
+ return;
+ }
+ else if (!prefix.active() && entry.active()){
+ t.position = 1; // ?
+ prefix.active(true); //activate prefix
+ entry.active(false);
+ return;
+ };
+ //otherwise: confusion
+ return;
+ };
+
+ // liveLength!=0
+ // Deactivate old item
+ if (t.position !== -1 && !t._prefix.active() && !t._entry.active()) {
+ t.liveItem(t.position).active(false);
+ };
+
+ // Get new active item
+ t.position++;
+ let newItem = t.liveItem(t.position);
+
+ // The next element is undefined - roll to top or to prefix or to entry
+ if (newItem === undefined) {
+
+ if ( !entry.active() ){ //if entry is active we definetly go to first item next
+ if (prefix.isSet() && !prefix.active()){ //prefix is next and exists
+ t.position=t.liveLength()+1;
+ prefix.active(true); //activate prefix
+ entry.active(false);
+ return;
+ }
+ else if ( (prefix.isSet() && prefix.active()) || // we had prefix
+ (!prefix.isSet() && !prefix.active()) ){ //or it isnt there
+ t.position=t.liveLength()+2;
+ prefix.active(false);
+ entry.active(true); //activate entry
+ return;
+ };
+ }
+
+ // Choose first item
+ else {
+ newItem = t.liveItem(0);
+ // choose first item
+ t.position = 0;
+ t._showItems(0);
+ // we reach point A from here
+ };
+ }
+
+ // The next element is after the viewport - roll down
+ else if (t.position >= (t.limit() + t.offset)) {
+ t.screen(t.position - t.limit() + 1);
+ }
+
+ // The next element is before the viewport - roll up
+ else if (t.position <= t.offset) {
+ t.screen(t.position);
+ };
+
+ //Point A
+ t._prefix.active(false);
+ t._entry.active(false);
+ newItem.active(true);
+ },
+
+
+ /*
+ * Make the previous item in the menu active
+ */
+ prev : function () {
+ const t = this;
+ // Activate prefix and entry
+ const prefix = this._prefix;
+ const entry = this._entry;
+
+ // No list
+ if (t.liveLength() === 0){ //switch between entry and prefix
+ if (!prefix.isSet()){//It is entry and it will stay entry
+ entry.active(true);
+ prefix.active(false);//Question: do we need to activate entry?
+ return;
+ };
+
+ if (prefix.active() && !entry.active()){
+ t.position = 2; // ?
+ prefix.active(false);
+ entry.active(true); //activate entry
+ return;
+ }
+ else if (!prefix.active() && entry.active()){
+ t.position = 1; // ?
+ prefix.active(true); //activate prefix
+ entry.active(false);
+ return;
+ };
+ //otherwise: confusion
+ };
+
+ // Deactivate old item
+ if (!prefix.active() && !entry.active()) {
+
+ // No active element set
+ if (t.position === -1) {
+ t.position = t.liveLength();
+ }
+
+ // deactivate active element
+ else {
+ t.liveItem(t.position--).active(false); //returns before decrement
+ };
+ };
+
+ // Get new active item
+ let newItem = t.liveItem(t.position);
+
+ // The previous element is undefined - roll to bottom
+ if (newItem === undefined) {
+
+
+ let offset = t.liveLength() - t.limit();
+
+ // Normalize offset
+ offset = offset < 0 ? 0 : offset;
+
+ // Choose the last item
+ t.position = t.liveLength() - 1;
+
+ if(!entry.active()){
+ if (prefix.isSet() && prefix.active()){
+ // we were on prefix and now choose last item
+ newItem = t.liveItem(t.position);
+ t._showItems(offset);
+ }
+ else if(!prefix.active()){
+ // we need to loop around: pick entry
+ t.position=t.liveLength()+2;
+ prefix.active(false);
+ entry.active(true); //activate entry
+ return;
+ };
+ //otherwise confusion
+ } else {
+ if(prefix.isSet()){ // we had entry and thus now need prefix
+ t.position=t.liveLength()+1;
+ prefix.active(true); //activate prefix
+ entry.active(false);
+ return;
+ } else { // we had entry but there is no prefix
+ newItem = t.liveItem(t.position);
+ t._showItems(offset); // Choose last item
+ };
+ };
+ }
+
+ // The previous element is before the view - roll up
+ else if (t.position < t.offset) {
+ t.screen(t.position);
+ }
+
+ // The previous element is after the view - roll down
+ else if (t.position >= (t.limit() + t.offset)) {
+ t.screen(t.position - t.limit() + 2);
+ };
+
+ t._prefix.active(false);
+ t._entry.active(false);
+ newItem.active(true);
+ },
+// Append Items that should be shown
+_showItems : function (off) {
+ const t = this;
+
+ // optimization: scroll down one step
+ if (t.offset === (off - 1)) {
+ t.offset = off;
+
+ // Remove the HTML node from the first item
+ // leave lengthField/prefix/slider
+ t._el.removeChild(t._el.children[this._notItemElements]);
+
+ t._append(
+ t._list[t.offset + t.limit() - 1]
+ );
+ }
+
+ // optimization: scroll up one step
+ else if (t.offset === (off + 1)) {
+ t.offset = off;
+
+ // Remove the HTML node from the last item
+ t._el.removeChild(t._el.lastChild);
+
+ t._prepend(t._list[t.offset]);
+ }
+
+ else {
+ t.offset = off;
+
+ // Remove all items
+ t.removeItems();
+
+ // Use list
+ let shown = 0;
+
+ for (let i = 0; i < t._list.length; i++) {
+
+ // Don't show - it's before offset
+ shown++;
+ if (shown <= off)
+ continue;
+
+ t._append(t._list[i]);
+
+ if (shown >= (t.limit() + off))
+ break;
+ };
+ };
+
+ // set the slider to the new offset
+ t._slider.offset(t.offset);
+},
+
+
+ };
+});
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 01bf7d8..088618b 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -60,6 +60,7 @@
params = {};
const t = this;
+ t._notItemElements=3;
t._itemClass = params["itemClass"] || defaultItemClass;
@@ -127,7 +128,7 @@
t._limit = menuLimit;
- t._items = new Array();
+ t._items = new Array(); //all childNodes, i.e. ItemClass, prefixClass
// TODO:
// Make this separate from _init
@@ -142,7 +143,7 @@
readItems : function (list) {
const t = this;
- t._list = undefined;
+ t._list = undefined; //filtered List containing all itemClass items
// Remove circular reference to "this" in items
for (let i = 0; i < t._items.length; i++) {
@@ -179,6 +180,7 @@
// Initialize the item list
_initList : function () {
+ // Upon change also update alwaysmenu.js please
const t = this;
// Create a new list
@@ -258,6 +260,7 @@
* mark and sweep GC)!
*/
destroy : function () {
+ // Upon change also update alwaysmenu.js please
const t = this;
// Remove circular reference to "this" in menu
@@ -327,6 +330,7 @@
// Arrow key and prefix treatment
_keydown : function (e) {
+ //Upon change also update alwaysmenu.js please
const t = this;
switch (_codeFromEvent(e)) {
@@ -489,6 +493,7 @@
* @param {string} Prefix for filtering the list
*/
show : function (active) {
+ //Upon change please also update alwaysmenu.js (only two lines new there)
const t = this;
// show menu based on initial offset
@@ -623,6 +628,7 @@
this._el.removeChild(liElements[0]);
};
},
+
/**
@@ -686,6 +692,7 @@
* Make the next item in the filtered menu active
*/
next : function () {
+ //Upon change please update alwaysmenu.js next
const t = this;
// No list
@@ -742,6 +749,7 @@
* Make the previous item in the menu active
*/
prev : function () {
+ //Upon Change please update alwaysmenu.js prev
const t = this;
// No list
@@ -870,7 +878,7 @@
// Remove the HTML node from the first item
// leave lengthField/prefix/slider
- t._el.removeChild(t._el.children[3]);
+ t._el.removeChild(t._el.children[this._notItemElements]);
t._append(
t._list[t.offset + t.limit() - 1]
@@ -943,7 +951,7 @@
// Append element after lengthField/prefix/slider
e.insertBefore(
item.element(),
- e.children[3]
+ e.children[this._notItemElements]
);
}
};