forked from zombieFox/nightTab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
165 lines (158 loc) · 4.4 KB
/
Copy pathclock.js
File metadata and controls
165 lines (158 loc) · 4.4 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
var clock = (function() {
var bind = function() {
window.setInterval(function() {
clear();
render();
}, 1000);
};
var clear = function() {
var clock = helper.e(".clock");
while (clock.lastChild) {
clock.removeChild(clock.lastChild);
};
};
var _makeTimeObject = function() {
var time = helper.getDateTime();
time.meridiem = "AM";
if (state.get().header.clock.hour24.show) {
if (time.hours < 10) {
time.hours = "0" + time.hours;
};
} else {
if (time.hours > 12) {
time.meridiem = "PM";
time.hours = time.hours - 12;
};
if (time.hours == 0) {
time.hours = 12;
};
};
if (time.minutes < 10) {
time.minutes = "0" + time.minutes;
};
if (time.seconds < 10) {
time.seconds = "0" + time.seconds;
};
return time;
};
var render = function() {
var _clock = function() {
var clock = helper.e(".clock");
var timeObject = _makeTimeObject();
var action = {
hours: {
word: function(value) {
if (state.get().header.clock.hour24.show && value < 10) {
return "Zero " + helper.toWords(value);
} else {
return helper.toWords(value);
};
},
number: function(value) {
return value;
}
},
minutes: {
word: function(value) {
if (value < 10) {
return "Zero " + helper.toWords(value);
} else {
return helper.toWords(value);
};
},
number: function(value) {
return value;
}
},
seconds: {
word: function(value) {
return helper.toWords(value);
},
number: function(value) {
return value;
}
}
};
timeObject.hours = action.hours[state.get().header.clock.hours.display](timeObject.hours);
timeObject.minutes = action.minutes[state.get().header.clock.minutes.display](timeObject.minutes);
timeObject.seconds = action.seconds[state.get().header.clock.seconds.display](timeObject.seconds);
var elementHours = helper.makeNode({
tag: "span",
text: timeObject.hours,
attr: [{
key: "class",
value: "clock-item clock-hours"
}]
});
var elementMinutes = helper.makeNode({
tag: "span",
text: timeObject.minutes,
attr: [{
key: "class",
value: "clock-item clock-minutes"
}]
});
var elementSeconds = helper.makeNode({
tag: "span",
text: timeObject.seconds,
attr: [{
key: "class",
value: "clock-item clock-seconds"
}]
});
var elementMeridiem = helper.makeNode({
tag: "span",
text: timeObject.meridiem,
attr: [{
key: "class",
value: "clock-item clock-meridiem"
}]
});
if (state.get().header.clock.hours.show) {
clock.appendChild(elementHours);
};
if (state.get().header.clock.minutes.show) {
clock.appendChild(elementMinutes);
};
if (state.get().header.clock.seconds.show) {
clock.appendChild(elementSeconds);
};
if (!state.get().header.clock.hour24.show && state.get().header.clock.meridiem.show) {
clock.appendChild(elementMeridiem);
};
if (state.get().header.clock.separator.show) {
var separatorCharacter = ":";
var parts = clock.querySelectorAll("span");
if (parts.length > 1) {
parts.forEach(function(arrayItem, index) {
if (index > 0 && !arrayItem.classList.contains("clock-meridiem")) {
var separator = helper.makeNode({
tag: "span",
text: separatorCharacter,
attr: [{
key: "class",
value: "clock-item clock-separator"
}]
});
clock.insertBefore(separator, arrayItem);
};
});
};
};
};
if (state.get().header.clock.seconds.show || state.get().header.clock.minutes.show || state.get().header.clock.hours.show) {
_clock();
};
};
var init = function() {
render();
bind();
};
// exposed methods
return {
init: init,
bind: bind,
render: render,
clear: clear
};
})();