Fixed scrolling feature in menus for values equal to limit
diff --git a/dev/demo/menudemo.js b/dev/demo/menudemo.js
index 244aff4..c00f01e 100644
--- a/dev/demo/menudemo.js
+++ b/dev/demo/menudemo.js
@@ -4,12 +4,15 @@
require(['menu','menu/item', 'menu/prefix', 'menu/lengthField'], function (menuClass, itemClass, prefixClass, lengthFieldClass) {
+ /**
+ * Create own menu item class.
+ */
var OwnMenuItemClass = {
-
create : function (params) {
return Object.create(itemClass).upgradeTo(this)._init(params);
},
+ // content function
content : function (content) {
if (arguments.length === 1) {
this._content = content;
@@ -26,6 +29,8 @@
further : function () {
console.log("Further: " + this._name);
},
+
+ // initialize item
_init : function (params) {
if (params[0] === undefined)
throw new Error("Missing parameters");
@@ -33,11 +38,13 @@
this._name = params[0];
this._content = document.createTextNode(this._name);
this._lcField = ' ' + this.content().textContent.toLowerCase();
-
return this;
}
};
+ /**
+ * Create own prefix class.
+ */
var OwnPrefixClass = {
create : function () {
return Object.create(prefixClass)
@@ -49,6 +56,9 @@
}
};
+ /**
+ * Create own menu class.
+ */
var OwnMenu = {
create : function (params) {
var obj = Object.create(menuClass)
@@ -74,7 +84,6 @@
document.getElementById('menu').appendChild(menu.element());
- menu.limit(3);
- menu.show(0); // Make this a 3
+ menu.limit(3).show(3);
menu.focus();
});
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index f993d33..e19122a 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -1327,7 +1327,7 @@
expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
});
- it('should scroll to a chosen value', function () {
+ it('should scroll to a chosen value (1)', function () {
var menu = KorAP.OwnMenu.create(demolist);
menu.limit(3);
@@ -1348,16 +1348,23 @@
expect(menu.shownItem(1).active()).toBe(false);
expect(menu.shownItem(2).active()).toBe(true);
expect(menu.shownItem(3)).toBe(undefined);
-
});
- xit('should highlight a chosen value');
- xit('should move the viewport to active, if active is not in the viewport');
+ it('should scroll to a chosen value (2)', function () {
+ var menu = KorAP.OwnMenu.create(demolonglist);
+
+ // Choose value 3
+ expect(menu.limit(3).show(3)).toBe(true);
+ expect(menu.shownItem(0).lcField()).toEqual(' länge');
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+ });
+
+ xit('should scroll to a chosen value after prefixing, if the chosen value is live');
});
-
-
-
describe('KorAP.Prefix', function () {
it('should be initializable', function () {
var p = prefixClass.create();
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 2cd99d6..69107d0 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -7,6 +7,7 @@
* TODO: space is not a valid prefix!
* TODO: Show the slider briefly on move (whenever screen is called).
* TODO: Ignore alt+ and strg+ key strokes.
+ * TODO: Should scroll to a chosen value after prefixing, if the chosen value is live
*/
define([
'menu/item',
@@ -409,7 +410,8 @@
active = this.liveLength() - 1;
};
- if (active > this._limit) {
+ // Item is outside the first viewport
+ if (active >= this._limit) {
offset = active;
if (offset > (this.liveLength() - this._limit)) {
offset = this.liveLength() - this._limit;