Started a screen implementation in the menu
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index 5f8ab9d..8e6141a 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -1,9 +1,5 @@
-define(['menu'], function () {
-
- var menuItemClass = require('menu/item');
- var prefixClass = require('menu/prefix');
- var lengthFieldClass = require('menu/lengthField');
- var menuClass = require('menu');
+define(['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'],
+ function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
// The OwnMenu item
KorAP.OwnMenuItem = {
@@ -1066,10 +1062,59 @@
});
+ it('should show screens by offset', function () {
+ var menu = KorAP.HintMenu.create('cnx/', demolist);
+ menu.limit(3);
+ expect(menu.show()).toBe(true);
+
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+
+ menu.next();
+
+ expect(menu.shownItem(0).active()).toBe(true);
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+
+ menu.next();
+
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ expect(menu.shownItem(0).lcField()).toEqual(' titel');
+ expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
+
+/*
+ menu.screen(0);
+ expect(menu.shownItem(0).active()).toBe(false);
+ expect(menu.shownItem(1).active()).toBe(true);
+ expect(menu.shownItem(2).active()).toBe(false);
+ expect(menu.shownItem(3)).toBe(undefined);
+*/
+
+console.log('VVVVVVVVVVVVVVVVV');
+ menu.screen(1);
+ expect(menu.shownItem(0)).not.toBeUndefined();
+ expect(menu.shownItem(1)).not.toBeUndefined();
+ expect(menu.shownItem(2)).not.toBeUndefined();
+ expect(menu.shownItem(3)).toBe(undefined);
+
+ expect(menu.shownItem(0).active()).toBe(true);
+console.log('AAAAAAAAAAAAAAAAA');
+/*
+ expect(menu.shownItem(1).active()).toBe(false);
+ expect(menu.shownItem(2).active()).toBe(false);
+*/
+ });
+
+
xit('should be page downable');
xit('should be page upable');
- it('should scroll to a chosen value', function () {
+ xit('should scroll to a chosen value', function () {
var menu = KorAP.OwnMenu.create(demolist);
menu.limit(3);
this._active = 5;
@@ -1078,6 +1123,9 @@
xit('should highlight a chosen value');
});
+
+
+
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 bd363e3..ce59f3c 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -54,6 +54,10 @@
* mark and sweep GC)!
*/
destroy : function () {
+ this._prefix._menu = undefined;
+ this._lengthField._menu = undefined;
+ this._slider._menu = undefined;
+
if (this._element != undefined)
delete this._element["menu"];
@@ -155,6 +159,16 @@
};
},
+ /**
+ * Show screen X
+ */
+ screen : function (nr) {
+ if (this._offset === nr)
+ return;
+
+ this._showItems(nr);
+ },
+
// Initialize list
_init : function (itemClass, prefixClass, lengthFieldClass, params) {
var that = this;
@@ -179,7 +193,7 @@
this._lengthField._menu = this;
// Initialize the slider
- this._slider = sliderClass.create();
+ this._slider = sliderClass.create(this);
var e = document.createElement("ul");
e.style.opacity = 0;
@@ -318,10 +332,14 @@
// Set the first element to active
// Todo: Or the last element chosen
- if (this._firstActive)
+ if (this._firstActive) {
this.liveItem(0).active(true);
-
- this.position = 0;
+ this.position = 0;
+ this._active = 0;
+ }
+ else {
+ this.position = -1;
+ }
this._prefix.active(false);
@@ -438,21 +456,33 @@
},
// Append Items that should be shown
- _showItems : function (offset) {
+ _showItems : function (off) {
+
this.delete();
// Use list
var shown = 0;
var i;
for (i in this._list) {
-
// Don't show - it's before offset
- if (shown++ < offset)
+ if (shown++ < off)
continue;
- this._append(this._list[i]);
+ var itemNr = this._list[i];
+ var item = this.item(itemNr);
+ this._append(itemNr);
- if (shown >= (this.limit() + this._offset))
+ /*
+ this._items[this._list[i]].active();
+ console.dir([i, this._active]);
+ if (this._active === i) {
+console.log('True!')
+ this._items[this._list[i]].active(true);
+ };
+ */
+
+ // this._offset))
+ if (shown >= (this.limit() + off))
break;
};
},
@@ -579,18 +609,18 @@
next : function () {
// No active element set
- if (this.position === -1)
- return;
-
var newItem;
- // Set new live item
- if (!this._prefix.active()) {
- var oldItem = this.liveItem(this.position);
- oldItem.active(false);
+ if (this.position !== -1) {
+ // Set new live item
+ if (!this._prefix.active()) {
+ var oldItem = this.liveItem(this.position);
+ oldItem.active(false);
+ };
};
this.position++;
+ this._active = this.position;
newItem = this.liveItem(this.position);
@@ -604,12 +634,14 @@
if (prefix.isSet() && !prefix.active()) {
this.position--;
prefix.active(true);
+ this._active = -1;
return;
}
else {
this._offset = 0;
this.position = 0;
newItem = this.liveItem(0);
+ this._active = 0;
this._showItems(0);
};
}
diff --git a/dev/js/src/menu/slider.js b/dev/js/src/menu/slider.js
index af9a759..c35f284 100644
--- a/dev/js/src/menu/slider.js
+++ b/dev/js/src/menu/slider.js
@@ -3,16 +3,20 @@
/**
* Create new prefix object.
*/
- create : function () {
- return Object.create(this)._init();
+ create : function (menu) {
+ return Object.create(this)._init(menu);
},
_mousemove : function (e) {
var relativePos = e.clientY - this._event.init;
- var currentPos = 0;
var diffHeight = (this._rulerHeight - this._sliderHeight);
- var relativeOffset = ((relativePos + currentPos) / diffHeight);
- this.offset(parseInt(relativeOffset * this._screens));
+ var relativeOffset = (relativePos / diffHeight);
+
+ var off = this.offset(parseInt(relativeOffset * this._screens));
+ if (off !== undefined) {
+ this._menu.screen(off);
+ };
+
e.halt();
// Support touch!
@@ -43,7 +47,9 @@
},
// Initialize prefix object
- _init : function () {
+ _init : function (menu) {
+
+ this._menu = menu;
this._offset = 0;
this._event = {};
@@ -55,10 +61,15 @@
document.createElement('span')
);
+ this._element.appendChild(document.createElement('div'))
+ // Do not mark the menu on mousedown
+ .addEventListener('mousedown', function (e) {
+ e.halt()
+ });
+
// TODO: Support touch!
this._slider.addEventListener('mousedown', this._mousedown.bind(this), false);
- this._element.appendChild(document.createElement('div'));
return this;
},
@@ -83,14 +94,15 @@
},
offset : function (off) {
- if (off === undefined)
+ if (arguments.length === 0)
return this._offset;
if (off === this._offset || off > this._screens || off < 0)
- return;
+ return undefined;
this._offset = off;
this._slider.style.top = (this._step * off) + '%';
+ return off;
},
element : function () {