Fixed prefix tool in menus
diff --git a/public/js/spec/menuSpec.js b/public/js/spec/menuSpec.js
index fef6027..a818574 100644
--- a/public/js/spec/menuSpec.js
+++ b/public/js/spec/menuSpec.js
@@ -928,13 +928,14 @@
expect(menu.shownItem(0).name()).toEqual("Titel");
expect(menu.element().childNodes[1].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().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
expect(menu.shownItem(1).active()).toBe(true);
expect(menu.shownItem(2)).toBe(undefined);
});
- xit('should be navigatable with a prefix (2)', function () {
+ it('should be navigatable with a prefix (2)', function () {
var menu = KorAP.HintMenu.create("cnx/", demolist);
menu.limit(3);
expect(menu.show()).toBe(true);
@@ -942,6 +943,7 @@
menu.prefix('el');
expect(menu.show()).toBe(true);
+
expect(menu.prefix()).toEqual("el");
expect(menu._prefix.active()).toEqual(false);
expect(menu.shownItem(0).name()).toEqual("Titel");
@@ -955,16 +957,17 @@
// Backward
menu.prev();
expect(menu._prefix.active()).toEqual(true);
+
expect(menu.shownItem(0).name()).toEqual("Titel");
expect(menu.element().childNodes[1].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().childNodes[2].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.shownItem(0).name()).toEqual("Titel");
@@ -974,7 +977,6 @@
expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
expect(menu.shownItem(1).active()).toBe(true);
expect(menu.shownItem(2)).toBe(undefined);
-*/
});
xit('should be page downable');
diff --git a/public/js/src/menu.js b/public/js/src/menu.js
index c5bd2f8..5e7537b 100644
--- a/public/js/src/menu.js
+++ b/public/js/src/menu.js
@@ -503,6 +503,7 @@
* Make the previous item in the menu active
*/
prev : function () {
+
// No active element set
if (this._position == -1)
return;
@@ -510,8 +511,11 @@
var newItem;
// Set new live item
- var oldItem = this.liveItem(this._position--);
- oldItem.active(false);
+ if (!this._prefix.active()) {
+ var oldItem = this.liveItem(this._position--);
+ oldItem.active(false);
+ };
+
newItem = this.liveItem(this._position);
// The previous element is undefined - roll to bottom
@@ -520,9 +524,14 @@
// Activate prefix
var prefix = this._prefix;
this._offset = this.liveLength() - this.limit();
+
+ // Normalize offset
+ this._offset = this._offset < 0 ? 0 : this._offset;
+
this._position = this.liveLength() - 1;
if (prefix.isSet() && !prefix.active()) {
+
this._position++;
prefix.active(true);
return;