-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
129 lines (114 loc) · 5.33 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WeeksJs</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script src="./dist/weeksjs.umd.js">
</script>
<script>
console.log(weeksjs.getDaysOfWeek());
console.log(weeksjs.intToWeek(1 + 2 + 4 + 8 + 16 + 32, {
array: true
}));
console.log(weeksjs.weekToInt({
monday: true,
wednesday: true,
saturday: true
}));
</script>
</head>
<style>
#hightlight-encode {
padding: 0em;
font-weight: bold;
font-family: monospace;
font-size: 1em;
color: #e84d7a;
}
</style>
<body class="p-4">
<h2> WeeksJs</h2>
<h5>Control the days of the week of a record using simple and light binary numbers</h5>
<hr />
<div style="display: flex;">
<div id="selects">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="1"
data-name-value="sunday" id="flexSwitchCheckDefault">
<label class="form-check-label" for="flexSwitchCheckDefault">Sunday (value = 1)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="2"
data-name-value="monday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Monday (value = 2)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="4"
data-name-value="tuesday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Tuesday (value = 4)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="8"
data-name-value="wednesday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Wednesday (value = 8)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="16"
data-name-value="thursday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Thursday (value = 16)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="32"
data-name-value="friday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Friday (value = 32)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="64"
data-name-value="saturday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Saturday (value = 64)</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" data-bin-value="128"
data-name-value="holiday" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Holiday (value = 128)</label>
</div>
</div>
<div id="hightlight-encode">
</div>
</div>
</body>
<script>
function refreshView() {
let list = [...document.getElementById(`selects`).children].map(el => ({
name: String(el.children.item(0).getAttribute(`data-name-value`)),
checked: el.children.item(0).checked,
value: Number(el.children.item(0).getAttribute(`data-bin-value`)),
}))
let resultBin = list.filter(s => s.checked).reduce((prev, cur) => prev + cur.value, 0);
document.getElementById(`hightlight-encode`).innerHTML = `
<code>
let encodedWeeks = weeksjs.weekToInt({
<br/>
${list.map(item => ` ${item.name}: ${String(item.checked)}`).join(`<br/>`)}
<br/>
})
<br/>
console.log(encodedWeeks); //${resultBin}
</code>
`;
}
refreshView();
[...document.getElementsByClassName(`form-check-input`)].forEach(inputRef => {
inputRef.addEventListener(`change`, () => {
refreshView();
});
});
</script>
</html>