-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodes.js
More file actions
71 lines (60 loc) · 1.63 KB
/
modes.js
File metadata and controls
71 lines (60 loc) · 1.63 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
67
68
69
70
71
/*[ Class: Modes ]***************************************************
* A container to store the various display modes
*/
class Modes {
constructor() {
this.current = 0;
this.list = [{
name: "Digital Clock",
click: function(){},
reset: function(){},
display: function(){}
}];
document.title = this.name(this.previewNextIndex());
}
/**
* Mode storage: Store different modes for the clock
* @param {Array of Objects or a single Object} modesToAdd
* @return this
*/
addMode(modesToAdd) {
var me = this;
if (Array.isArray(modesToAdd)) {
for (var modeToAdd of modesToAdd) {
me.list.push(modeToAdd);
}
} else {
me.list.push(modesToAdd);
}
return this;
}
/**
* Get the index number for the next next()
* @return {Number}
*/
previewNextIndex() {
return ((this.current+1) > (this.list.length-1)) ? 0 : this.current+1;
}
/**
* Inc the index number for next()
*/
next() {
document.title = this.name(this.previewNextIndex());
this.current = this.previewNextIndex();
return this;
}
display() {
return this.list[this.current].display;
}
reset() {
return this.list[this.current].reset;
}
click() {
return this.list[this.current].click;
}
// Use an arg to force an index
name(index = -1) {
return (index == -1) ? this.list[this.current].name : this.list[index].name;
}
}
module.exports = {Modes};