-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathBadUIPhone.html
158 lines (148 loc) · 6.74 KB
/
BadUIPhone.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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<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>
<style>
form{
background-color: #eee; border-radius: 5px; padding: 10px; margin: 10px;
}
form input#slider{
transition: width 0.5s ease-in-out;
}
form input#angleSlider{
display: none;
}
footer{
position: fixed; bottom: 0; width: 100%; text-align: center; font-size: 12px; color: #999;
}
</style>
</head>
<body>
<h1>Check out <a href="./..">More Bad UI</a> samples</h1>
<form>
<h3>Bad Phone Selector</h3>
<div>Phone: <span id="phoneDisplay">(30) 339-669-214 </span></div>
<input id="slider" type="range" min="10000000000" max="99999999999" value="55555555555" title="Hint: use keyboard arrows to change value" style="transition: width 0.5s ease-in-out;">
<hr>
<div>
<input id="advancedMode" type="checkbox">
<label for="advancedMode">Advanced Mode</label>
<input id="angleSlider" type="range" min="-10" max="10" step="0.02" style="display: none;" value="0">
<!-- <div id = "angleArea" style="display: none;">Angle: <span id="angleDisplay"></span></div>
<div id = "speedArea" style="display: none;">Speed: <span id="speedDisplay"></span></div>
<div id = "valueArea" style="display: none;">Value: <span id="valueDisplay"></span></div> -->
</div>
<input id="submit" type="submit" value="Submit">
</form>
<footer>
<p>Available at: <a href="https://github.com/GoulartNogueira/BadUI">github.com/GoulartNogueira/BadUI</a></p>
<p>Made with <span style="color: #ff0000;">♥</span> by André G. N.</p>
</footer>
</body>
<script>
var slider = document.getElementById("slider");
var angleSlider = document.getElementById("angleSlider");
// var angleDisplay = document.getElementById("angleDisplay");
// var speedDisplay = document.getElementById("speedDisplay");
// var valueDisplay = document.getElementById("valueDisplay");
var phoneDisplay = document.getElementById("phoneDisplay");
var advancedModeCheckbox = document.getElementById("advancedMode");
var angle = 0;
var speed = 0;
var friction = 0.99;
var value = Number(slider.value);
// Phone value is converted to a string
function PhoneNumberToDisplay( value ) {
// (XX)XXX-XXX-XXXX
var display = "("+ value.toString().substr(0, 2) + ") " + value.toString().substr(2, 3) + '-' + value.toString().substr(5, 3)+'-' + value.toString().substr(8, 3);
return display;
}
// Apply Physics rule to update phone value based on angle and speed
function UpdatePhone() {
// Get angle and speed from sliders
angle = Number(angleSlider.value);
value = Number(slider.value)
// Speed is based on angle
speed += Math.sin(angle * Math.PI / 180)*1000;
// Friction
speed *= friction;
value += Math.round(speed*100000);
// Update phone value
// Bounce off edges, inverting speed
if (value > slider.max) {
value = slider.max;
speed *= -1;
} else if (value < slider.min) {
value = slider.min;
speed *= -1;
}
slider.value = value;
// Update phone display
phoneDisplay.innerHTML = PhoneNumberToDisplay(value);
// // Update speed display
// speedDisplay.innerHTML = Math.round(speed);
// // Update value display
// valueDisplay.innerHTML = Math.round(value);
// // Update angle display
// angleDisplay.innerHTML = angle;
}
// Continuous update
setInterval(UpdatePhone, 10);
// Advanced Mode
advancedModeCheckbox.addEventListener("change", function() {
if (this.checked) {
// Show advanced controls
document.getElementById("angleSlider").style.display = "block";
slider.style.width = '100%';
// document.getElementById("angleArea").style.display = "block";
// document.getElementById("speedArea").style.display = "block";
// document.getElementById("valueArea").style.display = "block";
} else {
// Hide advanced controls
document.getElementById("angleSlider").style.display = "none";
// document.getElementById("angleArea").style.display = "none";
// document.getElementById("speedArea").style.display = "none";
// document.getElementById("valueArea").style.display = "none";
slider.style.width = '197px';
angleSlider.style.display = 'none';
// speed = 0;
angleSlider.value = 0;
slider.style.transform = 'rotate(0deg)';
}
});
slider.oninput = function() {
speed = 0;
};
angleSlider.oninput = function() {
angle = Number(angleSlider.value);
slider.style.transform = 'rotate(' + angle + 'deg)';
};
// Advanced Mode
var advancedMode = false
/* When checked, set a variable */
advancedModeCheckbox.addEventListener('change', function() {
advancedMode = advancedModeCheckbox.checked;
});
// On submit
document.getElementById("submit").addEventListener("click", function(event) {
if (confirm("Is this your Phone Number?\n" + PhoneNumberToDisplay(value))) {
// Thank you
alert("Thank you for your submission!");
} else {
// Please Contact your phone administrator
alert("Please contact your phone administrator to change your phone number to " + PhoneNumberToDisplay(value));
}
// Prevent default form submission
event.preventDefault();
});
</script>
</html>