-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuState.js
More file actions
66 lines (51 loc) · 1.49 KB
/
Copy pathmenuState.js
File metadata and controls
66 lines (51 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var menuState = {
_headerElement: document.querySelector(".header"),
_menuItemsList: document.querySelectorAll(".menu-container div, .settings-container div"),
_currentIndex: -1,
init: function () {
console.log(this.menuItemsList);
if (this._menuItemsList.length !== 0){
this._currentIndex = 0;
}
},
_setCurrent: function(index){
if(index < 0 || index >= this._menuItemsList.length){
return;
}
if(this._currentIndex !== -1) {
this.removeFocus();
}
this._currentIndex = index;
this.setFocus();
},
canSetFocus: function(){
if (this._currentIndex === -1){
return false;
}
return true;
},
setFocus: function () {
if (!this.canSetFocus()){
return;
}
this.removeFocus();
this._menuItemsList[this._currentIndex].classList.add("focus");
this._headerElement.classList.add("active");
},
removeFocus: function () {
var temp = document.querySelector(".header .focus");
if (temp){
temp.classList.remove("focus");
}
this._headerElement.classList.remove("active");
},
downAction: function () {
mainApp.setFocusedState("categoryState");
},
leftAction: function () {
this._setCurrent(this._currentIndex - 1);
},
rightAction: function () {
this._setCurrent(this._currentIndex + 1);
}
};