Make variables in menuSpec scope dependent
Change-Id: I745a772063afde9bb55f5ded1a67d4dcb65c19d0
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 47adfd3..5ef5efc 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -3,9 +3,9 @@
function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
// The OwnMenu item
- KorAP.OwnMenuItem = {
+ const OwnMenuItem = {
create : function (params) {
- return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
+ return Object.create(menuItemClass).upgradeTo(this)._init(params);
},
content : function (content) {
if (arguments.length === 1) {
@@ -25,20 +25,20 @@
};
// The OwnMenu
- KorAP.OwnMenu = {
+ const OwnMenu = {
create : function (list) {
return Object.create(menuClass)
- .upgradeTo(KorAP.OwnMenu)
- ._init(list, { itemClass : KorAP.OwnMenuItem });
+ .upgradeTo(this)
+ ._init(list, { itemClass : OwnMenuItem });
}
};
// HintMenuItem
- KorAP.HintMenuItem = {
+ const HintMenuItem = {
create : function (params) {
return Object.create(menuItemClass)
- .upgradeTo(KorAP.HintMenuItem)
+ .upgradeTo(this)
._init(params);
},
content : function (content) {
@@ -99,11 +99,11 @@
// HintMenu
- KorAP.HintMenu = {
+ const HintMenu = {
create : function (context, list) {
var obj = Object.create(menuClass)
- .upgradeTo(KorAP.HintMenu)
- ._init(list, {itemClass : KorAP.HintMenuItem});
+ .upgradeTo(this)
+ ._init(list, {itemClass : HintMenuItem});
obj._context = context;
return obj;
}
@@ -111,10 +111,10 @@
// The ComplexMenuItem
- KorAP.ComplexMenuItem = {
+ const ComplexMenuItem = {
create : function (params) {
return Object.create(menuItemClass)
- .upgradeTo(KorAP.ComplexMenuItem)
+ .upgradeTo(this)
._init(params);
},
content : function (content) {
@@ -149,21 +149,21 @@
).toThrow(new Error("Missing parameters"));
expect(
- function() { KorAP.OwnMenuItem.create([]) }
+ function() { OwnMenuItem.create([]) }
).toThrow(new Error("Missing parameters"));
- var mi = KorAP.OwnMenuItem.create(["Baum"]);
+ var mi = OwnMenuItem.create(["Baum"]);
expect(mi.element().firstChild.nodeValue).toEqual('Baum');
expect(mi.lcField()).toEqual(' baum');
});
it('shouldn\'t have a reference to the menu', function () {
- var menuItem = KorAP.OwnMenuItem.create(['Test']);
+ var menuItem = OwnMenuItem.create(['Test']);
expect(menuItem.menu()).toBe(undefined);
});
it('should be activatable and deactivateable by class', function () {
- var menuItem = KorAP.OwnMenuItem.create(['Test']);
+ var menuItem = OwnMenuItem.create(['Test']);
expect(menuItem.active()).toBe(false);
expect(menuItem.element().getAttribute("class")).toBe(null);
@@ -177,7 +177,7 @@
expect(menuItem.active()).toBe(true);
expect(menuItem.element().getAttribute("class")).toEqual("active");
- menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
+ menuItem = OwnMenuItem.create(['Spiegel']);
expect(menuItem.active()).toBe(false);
expect(menuItem.element().getAttribute("class")).toBe(null);
menuItem.active(false); // Is not active
@@ -186,7 +186,7 @@
});
it('should be set to boundary', function () {
- var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
+ var menuItem = OwnMenuItem.create(['CoreNLP']);
expect(menuItem.active()).toBe(false);
expect(menuItem.element().getAttribute("class")).toBe(null);
@@ -225,7 +225,7 @@
it('should be highlightable', function () {
// Highlight in the middle
- var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
+ var menuItem = OwnMenuItem.create(['CoreNLP']);
menuItem.highlight("ren");
expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
@@ -235,7 +235,7 @@
var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
// Starting highlight
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
menuItem.highlight("cor");
expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
@@ -243,7 +243,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Starting highlight - short
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
menuItem.highlight("c");
expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
@@ -251,7 +251,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight at the end
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
menuItem.highlight("nlp");
expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
@@ -259,7 +259,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight at the end - short
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
menuItem.highlight("p");
expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
@@ -267,7 +267,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// No highlight
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
menuItem.highlight("xp");
expect(menuItem.element().innerHTML).toEqual(plain);
@@ -275,7 +275,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight in the middle - first
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
menuItem.highlight("ren");
expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>");
@@ -285,7 +285,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight in the middle - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
menuItem.highlight("ampl");
expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
@@ -293,7 +293,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight in the middle - both
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
menuItem.highlight("e");
expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
@@ -302,7 +302,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight in the end - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
menuItem.highlight("le");
expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
@@ -310,7 +310,7 @@
expect(menuItem.element().innerHTML).toEqual(plain);
// Highlight at the beginning - second
- menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
+ menuItem = ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
menuItem.highlight("this");
expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
@@ -373,10 +373,10 @@
["Syntax"]
];
- var menu = KorAP.OwnMenu.create(list);
+ var menu = OwnMenu.create(list);
expect(menu.dontHide).toBe(false);
menu._firstActive = true;
- expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
+ expect(menu.itemClass()).toEqual(OwnMenuItem);
expect(menu.element().nodeName).toEqual('UL');
expect(menu.element().classList.contains('visible')).toBeFalsy();
expect(menu.limit()).toEqual(8);
@@ -404,15 +404,15 @@
});
it('should have a reference to the menu', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
expect(menu.item(0).menu()).toEqual(menu);
- menu = KorAP.HintMenu.create("cnx/", list);
+ menu = HintMenu.create("cnx/", list);
expect(menu.element().menu).toEqual(menu);
});
it('should only remove direct descendants with removeItems', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
var newUL = document.createElement("ul");
var newLI = document.createElement("li");
newUL.appendChild(newLI);
@@ -428,7 +428,7 @@
it('should be visible', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
expect(menu.removeItems()).toBe(undefined);
menu.limit(3);
@@ -447,7 +447,7 @@
});
it('should be filterable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(3);
expect(menu.prefix("o").show()).toBe(true);
expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
@@ -492,7 +492,7 @@
});
it('should be nextable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu._firstActive = true;
// Show only 3 items
@@ -569,7 +569,7 @@
});
it('should be nextable without active field', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(3);
expect(menu.show()).toBe(true);
menu.next();
@@ -578,7 +578,7 @@
it('should be prevable', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu._firstActive = true;
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -666,7 +666,7 @@
});
it('should be prevable without active field', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(3);
expect(menu.show()).toBe(true);
menu.prev();
@@ -675,7 +675,7 @@
});
it('should be navigatable and filterable (prefix = "o")', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu._firstActive = true;
menu.limit(2);
@@ -730,7 +730,7 @@
it('should be navigatable and filterable (prefix = "ex", "e")', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu._firstActive = true;
menu.limit(2);
@@ -817,7 +817,7 @@
});
it('should be filterable (multiple prefix = "pro sin")', function () {
- var menu = KorAP.HintMenu.create("drukola/p=", listMultiPrefix);
+ var menu = HintMenu.create("drukola/p=", listMultiPrefix);
menu._firstActive = true;
menu.limit(2);
@@ -836,7 +836,7 @@
});
it('should be filterable (trimming = " p")', function () {
- var menu = KorAP.HintMenu.create("/p=", listMultiPrefix);
+ var menu = HintMenu.create("/p=", listMultiPrefix);
// menu._firstActive = true;
menu.limit(2);
@@ -854,7 +854,7 @@
it('should choose prefix with failing prefix (1)', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(2);
expect(menu.prefix("exit").show()).toBe(true);
expect(menu.element().querySelector('li')).toBe(null);
@@ -864,7 +864,7 @@
it('should choose prefix with failing prefix (2)', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(2);
expect(menu.show()).toBe(true);
expect(menu.prefix("exit").show()).toBe(true);
@@ -874,7 +874,7 @@
});
it('should ignore navigation with failing prefix', function () {
- var menu = KorAP.HintMenu.create("cnx/", list);
+ var menu = HintMenu.create("cnx/", list);
menu.limit(2);
expect(menu.show()).toBe(true);
@@ -894,7 +894,7 @@
});
it('should be navigatable with prefix', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
+ var menu = HintMenu.create("cnx/", demolist);
menu._firstActive = true;
menu.limit(3);
@@ -1031,7 +1031,7 @@
it('should be navigatable with a prefix (1)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
+ var menu = HintMenu.create("cnx/", demolist);
menu._firstActive = true;
menu.limit(3);
@@ -1093,7 +1093,7 @@
it('should be navigatable with a prefix (2)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
+ var menu = HintMenu.create("cnx/", demolist);
menu._firstActive = true;
menu.limit(3);
@@ -1138,7 +1138,7 @@
});
it('should be navigatable with a prefix (3)', function () {
- var menu = KorAP.HintMenu.create("cnx/", demolist);
+ var menu = HintMenu.create("cnx/", demolist);
menu._firstActive = true;
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -1183,7 +1183,7 @@
});
it('should show screens by offset', function () {
- var menu = KorAP.HintMenu.create('cnx/', demolist);
+ var menu = HintMenu.create('cnx/', demolist);
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -1242,7 +1242,7 @@
});
it('should show screens by offset when prefixed', function () {
- var menu = KorAP.HintMenu.create('cnx/', demolist);
+ var menu = HintMenu.create('cnx/', demolist);
menu.limit(3);
expect(menu.prefix("e").show()).toBe(true);
expect(menu.shownItem(0).active()).toBe(false);
@@ -1256,7 +1256,7 @@
it('should be page downable', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu.limit(3);
expect(menu.show(0)).toBe(true);
@@ -1291,7 +1291,7 @@
});
it('should be page downable with prefix', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu.limit(3);
expect(menu.prefix('e').show(0)).toBe(true);
@@ -1326,7 +1326,7 @@
it('should be page upable', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu.limit(3);
// Choose the final value
@@ -1362,7 +1362,7 @@
});
it('should be page upable with prefix', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu.limit(3);
// Choose the final value
@@ -1397,7 +1397,7 @@
});
it('should be view upable and downable (1)', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu.limit(7);
// Choose the final value
@@ -1441,7 +1441,7 @@
it('should be view upable and downable (2)', function () {
// List is longer than limit
- var menu = KorAP.OwnMenu.create(demolist);
+ var menu = OwnMenu.create(demolist);
menu.limit(7);
// Choose the final value
@@ -1471,7 +1471,7 @@
it('should scroll to a chosen value (1)', function () {
- var menu = KorAP.OwnMenu.create(demolist);
+ var menu = OwnMenu.create(demolist);
menu.limit(3);
// Choose value 1
@@ -1494,7 +1494,7 @@
});
it('should scroll to a chosen value (2)', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
// Choose value 3
expect(menu.limit(3).show(3)).toBe(true);
@@ -1645,7 +1645,7 @@
["Syntax"]
];
- var menu = KorAP.OwnMenu.create(list);
+ var menu = OwnMenu.create(list);
expect(menu.lengthField().element().children.length).toEqual(5);
});
@@ -1674,7 +1674,7 @@
["Syntax"]
];
- var menu = KorAP.OwnMenu.create(list);
+ var menu = OwnMenu.create(list);
menu._firstActive = true;
menu.limit(3);
@@ -1697,7 +1697,7 @@
["Syntax"]
];
- var menu = KorAP.OwnMenu.create(list);
+ var menu = OwnMenu.create(list);
menu._firstActive = true;
menu.limit(3);
@@ -1743,7 +1743,7 @@
});
it('should correctly resize on prefixing', function () {
- var menu = KorAP.OwnMenu.create(demolonglist);
+ var menu = OwnMenu.create(demolonglist);
menu._firstActive = true;
menu.limit(3);
@@ -1774,7 +1774,7 @@
["Syntax"]
];
- var menu = KorAP.OwnMenu.create(list);
+ var menu = OwnMenu.create(list);
menu._firstActive = true;
menu.limit(3);