Fix slider resize in menus after prefixes are removed
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 7577c2f..d1dcbe9 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -1428,6 +1428,19 @@
});
describe('KorAP.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"],
@@ -1505,6 +1518,29 @@
expect(menu.slider()._slider.style.height).toEqual('60%');
});
+ it('should correctly resize on prefixing', function () {
+ var menu = KorAP.OwnMenu.create(demolonglist);
+ menu._firstActive = true;
+ menu.limit(3);
+
+ expect(menu.show()).toBe(true);
+ expect(menu.slider().offset()).toEqual(0);
+ expect(menu.slider().length()).toEqual(9);
+
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu.slider().length()).toEqual(6);
+
+ expect(menu.prefix("el").show()).toBe(true);
+ expect(menu.slider().length()).toEqual(2);
+
+ expect(menu.prefix("e").show()).toBe(true);
+ expect(menu.slider().length()).toEqual(6);
+
+ expect(menu.prefix("").show()).toBe(true);
+ expect(menu.slider().length()).toEqual(9);
+ });
+
+
it('should correctly move the list on mousemove', function () {
var list = [
["Constituency"],
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index abe2a15..b600833 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -5,11 +5,9 @@
*/
/*
* TODO: space is not a valid prefix!
- * TODO: What is _pos and what is position?
- * TODO: What is the difference between position
- * and _active?
* TODO: Ignore keys with function key combinations (other than shift)
* TODO: Show the slider briefly on move (whenever screen is called).
+ * TODO: Optimize scrolling to active item.
*/
define([
'menu/item',
@@ -132,8 +130,6 @@
this._slider.length(this.liveLength());
this._slider.limit(this._limit);
- this.position = 0; // position in the active list
- this._active = -1; // active item in the item list
this._firstActive = false; // Show the first item active always?
this._reset();
return this;
@@ -158,11 +154,14 @@
if (this.prefix().length <= 0) {
// add all items to the list and lowlight
- for (var i = 0; i < this._items.length; i++) {
+ var i = 0;
+ for (; i < this._items.length; i++) {
this._list.push(i);
this._items[i].lowlight();
};
+ this._slider.length(i);
+
return true;
};
@@ -371,7 +370,8 @@
/**
- * Filter the list and make it visible
+ * Filter the list and make it visible.
+ * This is always called once the prefix changes.
*
* @param {string} Prefix for filtering the list
*/
@@ -415,12 +415,10 @@
};
this.position = active;
- this._active = active;
}
else if (this._firstActive) {
this.position = 0;
- this._active = 0;
}
else {
@@ -445,8 +443,11 @@
//this._slider.show();
// Iterate to the active item
- if (this._active !== -1 && !this._prefix.isSet()) {
- while (this._list[this.position] < this._active) {
+ if (this.position !== -1 && !this._prefix.isSet()) {
+
+ // TODO: OPTIMIZE
+
+ while (this._list[this.position] < this.position) {
// TODO. Improve this by moving using screen!
this.next();
@@ -595,7 +596,6 @@
};
this.position++;
- this._active = this.position;
newItem = this.liveItem(this.position);
@@ -609,13 +609,11 @@
if (prefix.isSet() && !prefix.active()) {
this.position--;
prefix.active(true);
- this._active = -1;
return;
}
else {
this.position = 0;
newItem = this.liveItem(0);
- this._active = 0;
this._showItems(0);
};
}
@@ -725,7 +723,7 @@
// Reset chosen item and prefix
_reset : function () {
this._offset = 0;
- this._pos = 0;
+ this.position = 0;
this._prefix.clear();
},