-
Notifications
You must be signed in to change notification settings - Fork 28
/
BadUIDate.html
238 lines (231 loc) · 8.49 KB
/
BadUIDate.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Bad UIDate</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<style>
form{
background-color: #eee; border-radius: 5px; padding: 10px; margin: 10px;
}
form #advancedArea{
display: none; margin-top: 10px; margin-bottom: 10px; border: 1px solid #ccc; padding: 10px; transition: all 0.5s;
}
form #advancedArea input#toggleSlider{
width: 30px;
}
footer{
position: fixed; bottom: 0; width: 100%; text-align: center; font-size: 12px; color: #999;
}
</style>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GT9SGNE9P7"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-GT9SGNE9P7');
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4885726053170676"
crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="https://goulartnogueira.github.io/BadUI/">Bad UI</a> Birth Selector</h1>
<form>
<h3>Date of Birth Selector</h3>
<div>Date: <span id="dateDisplay"></span></div>
<div>
<button id="start" type="button" onclick="setDate(1)"> << </button>
<button id="backward" type="button" onclick="addDate(-1)"> < </button>
<button id="submit" type="button"> Submit </button>
<button id="forward" type="button" onclick="addDate(1)"> > </button>
<button id="end" type="button" onclick="setDate(-1)"> >> </button>
</div>
<hr>
<input id="advancedMode" type="checkbox">
<label for="advancedMode">Advanced Mode</label>
<div id="advancedArea">
<div>
<input id="autoMode" type="checkbox">
<label for="autoMode">Auto Mode</label>
<!-- Faster Button -->
<button id="faster" type="button" onclick="autoSpeed(10)">Faster</button>
</div>
<!-- Toggle switch made with a binary slider -->
<div>
<label for="toggle">Decrease</label>
<input
id="toggleSlider"
type="range"
min="0"
max="1"
step="1"
value="0"
onchange="toggle()">
<label for="toggle">Increase</label>
</div>
<!-- <div>
<label for="toggle">Decrease</label>
<input
id="toggle"
type="radio"
name="toggle"
value="0"
onclick="toggle(0)"
>
<input
id="toggle"
type="radio"
name="toggle"
value="1"
onclick="toggle(1)"
>
<label for="toggle">Increase</label>
</div> -->
</div>
<!-- <div>
<input id="submit" type="submit" value="Submit">
</div> -->
</form>
<footer>
<p>Live demo at: <a href="https://goulartnogueira.github.io/BadUI/Date/BadUIDate.html">https://goulartnogueira.github.io/BadUI/Date/BadUIDate.html</a></p>
<p>Made with 💩 by André G. N.</p>
</footer>
</body>
<script>
var date = new Date();
var advancedModeCheckbox = document.getElementById("advancedMode");
var advancedArea = document.getElementById("advancedArea");
var autoModeCheckbox = document.getElementById("autoMode");
var submitButton = document.getElementById("submit");
var startButton = document.getElementById("start");
var backButton = document.getElementById("backward");
var selectButton = document.getElementById("select");
var forwardButton = document.getElementById("forward");
var endButton = document.getElementById("end");
var dateDisplay = document.getElementById("dateDisplay");
function setDate(value) {
if(value == 1) {
// Set date to 01/01/0001
date.setFullYear(1);
date.setMonth(0);
date.setDate(1);
} else if(value == -1) {
// Set date to today
date.setFullYear(9999);
date.setMonth(12);
date.setDate(0);
}
updateDateDisplay();
}
function addDate(value) {
date.setDate(date.getDate() + value);
updateDateDisplay();
}
function pad(num, size) {
// Pad number with 0
var s = "0000" + num;
return s.substr(s.length-size);
}
function updateDateDisplay() {
// Show week day
var weekDay = date.getDay();
var weekDayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var weekDayDisplay = weekDayNames[weekDay];
// show leading zero
var yearDisplay = date.getFullYear();
// If year is between 0 and 1000, add a leading zero
if(yearDisplay < 1000 && yearDisplay > -1) {
yearDisplay = pad(yearDisplay, 4);
}
var dateString = weekDayDisplay + ", " + pad(date.getDate(), 2) + "/" + pad(date.getMonth() + 1, 2) + "/" + yearDisplay;
dateDisplay.innerHTML = dateString;
}
// set initial date as today:
setDate(0)
// Advanced Mode
advancedModeCheckbox.addEventListener("change", function() {
console.log("advancedModeCheckbox.checked: " + advancedModeCheckbox.checked);
if (this.checked) {
// Show advanced controls
advancedArea.style.display = "block";
} else {
// Hide advanced controls
advancedArea.style.display = "none";
}
});
var interval = 1000;
var autoMode = false;
var speed = -1;
// Continuous update
var intervalID = setInterval(function() {
if(advancedModeCheckbox.checked) {
if(autoModeCheckbox.checked) {
addDate(speed);
}
}
}, interval);
// Speed Faster
function autoSpeed(value) {
if (interval <= 1) {
speed *= value;
} else {
interval = interval / value;
// Update interval
clearInterval(intervalID);
intervalID = setInterval(function() {
if(advancedModeCheckbox.checked) {
if(autoModeCheckbox.checked) {
addDate(speed);
}
}
}, interval);
}
}
var fasterButton = document.getElementById("faster");
fasterButton.addEventListener("click", function() {
autoSpeed(10);
// Add "even faster" to beginning of button
this.innerHTML = "More " + this.innerHTML;
});
// toggle
var toggleSlider = document.getElementById("toggleSlider");
toggleSlider.addEventListener("change", function() {
if(this.value == 0) {
if(speed > 0) {
speed = -speed;
}
} else {
if(speed < 0) {
speed = -speed;
}
}
});
// On submit
document.getElementById("submit").addEventListener("click", function(event) {
event.preventDefault();
// Check if today is user's birthday
if(date.getDate() == new Date().getDate() && date.getMonth() == new Date().getMonth()) {
alert("Happy Birthday!");
}
// If selected date is larger than today
if(date > new Date()) {
// confirm with user if they were born in the future
var confirm = window.confirm("You are born in the future. Are you sure?");
if(confirm) {
alert("Have a nice time-travel!");
} else {
alert("You were born in" + date.toDateString() + ". But your system says today is " + new Date().toDateString() + ". If you are not a time traveler, please fix your system.");
}
} else {
// Confirm age
var diff = new Date() - date;
var age = Math.ceil(diff / (1000 * 3600 * 24 * 365.25))-1;
var confirmAge = window.confirm("You are " + age + " years old. Are you sure?");
if(confirmAge) {
alert("Thank you!");
} else {
alert("Please fix your birthday.");
}
}
});
</script>
</html>