Fix screen calculation in menus
Change-Id: I676caa4b4c288774d962164fcb85cb2d0e8c0842
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 1f9d849..1fb1ffd 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -338,13 +338,18 @@
}
else if (e.type === "touchmove") {
var t = e.touches[0];
+
+ // TODO:
+ // Instead of using 26px, choose the item height
+ // or use the menu height // shownItems
+
// s.movetoRel(t.clientY - this._initTouch);
if ((this._lastTouch + 26) < t.clientY) {
- this.screen(this.offset - 1);
+ this.viewDown();
this._lastTouch = t.clientY;
}
else if ((this._lastTouch - 26) > t.clientY) {
- this.screen(this.offset + 1);
+ this.viewUp();
this._lastTouch = t.clientY;
}
e.halt();
@@ -425,19 +430,32 @@
* in the viewport.
*/
screen : function (nr) {
+
+ // Normalize negative values
if (nr < 0) {
nr = 0
}
+
+ // The shown list already shows everything
+ else if (this.liveLength() < this.limit()) {
+ return false;
+ }
+
+ // Move relatively to the next screen
else if (nr > (this.liveLength() - this.limit())) {
nr = (this.liveLength() - this.limit());
};
+ // no change
if (this.offset === nr)
- return;
+ return false;
this._showItems(nr);
+
+ return true;
},
+
/**
* Get the associated dom element.
*/
@@ -677,7 +695,7 @@
return this._list.length;
},
-
+
/**
* Make the next item in the filtered menu active
*/
@@ -816,6 +834,21 @@
},
+ /**
+ * Move the view one item up
+ */
+ viewUp : function () {
+ this.screen(this.offset - 1);
+ },
+
+
+ /**
+ * Move the view one item down
+ */
+ viewDown : function () {
+ this.screen(this.offset + 1);
+ },
+
// Unmark all items
_unmark : function () {
for (var i in this._list) {