Fixed test suite and vc query integration
diff --git a/dev/js/spec/matchSpec.js b/dev/js/spec/matchSpec.js
index 28eb844..1af080f 100644
--- a/dev/js/spec/matchSpec.js
+++ b/dev/js/spec/matchSpec.js
@@ -564,7 +564,7 @@
expect(menu.element().style.opacity).toEqual("0");
expect(menu.limit()).toEqual(6);
menu.show();
- expect(menu.item(0).active()).toBe(true);
+ expect(menu.item(0).active()).toBe(false);
});
});
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 999ec2b..00fb8af 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -360,6 +360,7 @@
];
var menu = KorAP.OwnMenu.create(list);
+ menu._firstActive = true;
expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
expect(menu.element().nodeName).toEqual('UL');
expect(menu.element().style.opacity).toEqual("0");
@@ -462,6 +463,7 @@
it('should be nextable', function () {
var menu = KorAP.HintMenu.create("cnx/", list);
+ menu._firstActive = true;
// Show only 3 items
menu.limit(3);
@@ -538,6 +540,7 @@
it('should be prevable', function () {
var menu = KorAP.HintMenu.create("cnx/", list);
+ menu._firstActive = true;
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -626,6 +629,7 @@
it('should be navigatable and filterable (prefix = "o")', function () {
var menu = KorAP.HintMenu.create("cnx/", list);
+ menu._firstActive = true;
menu.limit(2);
expect(menu.prefix("o").show()).toBe(true);
@@ -680,6 +684,7 @@
it('should be navigatable and filterable (prefix = "ex", "e")', function () {
var menu = KorAP.HintMenu.create("cnx/", list);
+ menu._firstActive = true;
menu.limit(2);
expect(menu.prefix("ex").show()).toBe(true);
@@ -773,6 +778,8 @@
it('should be navigatable with prefix', function () {
var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -908,6 +915,8 @@
it('should be navigatable with a prefix (1)', function () {
var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -967,6 +976,8 @@
it('should be navigatable with a prefix (2)', function () {
var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
+
menu.limit(3);
expect(menu.show()).toBe(true);
expect(menu.prefix()).toEqual("");
@@ -1010,6 +1021,7 @@
it('should be navigatable with a prefix (3)', function () {
var menu = KorAP.HintMenu.create("cnx/", demolist);
+ menu._firstActive = true;
menu.limit(3);
expect(menu.show()).toBe(true);
expect(menu.prefix()).toEqual("");
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 9354917..c960ec2 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -46,7 +46,7 @@
* Replace Virtual Collection field
*/
var vcname;
- var input = document.getElementById('vc');
+ var input = document.getElementById('collection');
if (input) {
input.style.display = 'none';
vcname = document.createElement('span');
@@ -122,18 +122,8 @@
// The vc is not visible
else {
- // The vc is not rendered yet
- if (vc === undefined) {
- vc = vcClass.create([
- ['title', 'string'],
- ['subTitle', 'string'],
- ['pubDate', 'date'],
- ['author', 'string']
- ]);
-
- if (KorAP.currentVC !== undefined)
- vc.fromJson(KorAP.currentVC);
- };
+ if (vc === undefined)
+ vc = _getCurrentVC(vcClass);
view.appendChild(vc.element());
this.classList.add('active');
};
@@ -175,6 +165,20 @@
*/
/**
+ * Add VC creation on submission.
+ */
+ var form = document.getElementById('searchform');
+ if (form !== undefined) {
+ form.addEventListener('submit', function (e) {
+ if (vc === undefined)
+ vc = _getCurrentVC(vcClass);
+
+ if (vc !== undefined)
+ input.value = vc.toQuery();
+ });
+ };
+
+ /**
* Init hint helper
* has to be final because of
* reposition
@@ -186,3 +190,18 @@
return obj;
});
});
+
+// Render Virtual collection
+function _getCurrentVC (vcClass) {
+ var vc = vcClass.create([
+ ['title', 'string'],
+ ['subTitle', 'string'],
+ ['pubDate', 'date'],
+ ['author', 'string']
+ ]);
+ if (KorAP.currentVC !== undefined)
+ vc.fromJson(KorAP.currentVC);
+
+ return vc;
+};
+
diff --git a/dev/js/src/util.js b/dev/js/src/util.js
index 7c2f474..f17ec2a 100644
--- a/dev/js/src/util.js
+++ b/dev/js/src/util.js
@@ -1,3 +1,5 @@
+window.KorAP = window.KorAP || {};
+
// Don't let events bubble up
if (Event.halt === undefined) {
// Don't let events bubble up
@@ -35,7 +37,9 @@
define(function () {
+ // Todo: That's double now!
KorAP.API = KorAP.API || {};
+ KorAP.Locale = KorAP.Locale || {};
var loc = KorAP.Locale;
loc.OR = loc.OR || 'or';