-
Notifications
You must be signed in to change notification settings - Fork 1
/
stop_js.mustache
47 lines (40 loc) · 1.2 KB
/
stop_js.mustache
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
function byClass(name) {
return document.getElementsByClassName(name);
}
function addClass(target, clss) {
target.className += " " + clss;
}
function removeClass(target, clss) {
const regex = new RegExp(clss);
target.className = target.className.replace(regex, '')
}
function deselectAll() {
const elements = byClass('service');
for (let i = 0; i < elements.length; i++) {
removeClass(elements[i], 'selected');
}
const serviceIdElements = byClass('service_id');
for (let i = 0; i < serviceIdElements.length; i++) {
removeClass(serviceIdElements[i], 'selected');
}
}
function selectServiceId(target) {
const serviceId = target.innerHTML;
deselectAll();
addClass(target, 'selected');
const service = byClass(serviceId)[0];
addClass(service, 'selected');
}
window.onload = function () {
const twoHoursAgo = new Date(new Date() - (2 * 60 * 60 * 1000));
const dayOfWeek = twoHoursAgo.getDay();
const currentServiceId = byClass('svid_vd' + dayOfWeek)[0];
selectServiceId(currentServiceId);
const services = byClass('service_id');
for (let i = 0; i < services.length; i++) {
const s = services[i];
s.onclick = function(e) {
selectServiceId(e.target);
}
}
}