-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuControl.js
58 lines (37 loc) · 1.17 KB
/
MenuControl.js
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
var menus = ["Switches", "Modes"];
var menuControl;
function MenuControl(sw) {
//private
var current_menu = 0;
if (typeof sw == "undefined")
sw = [];
var menu = sw;
for (i in menu)
{
$(".panels").append("<section class='panel' id='menu_"+i+"'><h3>"+menu[i]+"</h3></section>");
}
var id="#menu_"+current_menu;
if (!$(id).hasClass("selected_panel"))
$(id).addClass("selected_panel");
setInterval(function() {
var id="#menu_"+current_menu;
if (!$(id).hasClass("selected_panel"))
$(id).addClass("selected_panel");
}, 1000/30);
//functions
this.getCurrentMenu = function() {
var j = current_menu;
return j;
}
this.getCurrentMenuName = function() {
return menu[current_menu].toLowerCase();
}
this.selectNext = function() {
$("#menu_"+current_menu).removeClass("selected_panel");
if (++current_menu >= menu.length) current_menu = 0;
}
this.selectPrev = function() {
$("#menu_"+current_menu).removeClass("selected_panel");
if (--current_menu < 0 && menu.length != 0) current_menu = menu.length-1;
}
}