-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdialog.html
249 lines (226 loc) · 8.97 KB
/
dialog.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
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet">
<script>
const sampleDelays = [136, 161, 139, 56, 96, 128, 159, 56, 96, 48, 113, 64, 183, 100, 140, 20, 88, 80];
const averageDelay = sampleDelays.reduce(function (a,b) { return a + b }, 0) / sampleDelays.length;
const normalizedDelays = sampleDelays.map(function (a) { return a / averageDelay });
function initial()
{
return transition([["introducing", "opacity", 0, ".5s"], ["bottom", "opacity", 0, ".5s"]])
.transition("introducing", "max-width", 0, ".5s")
}
Promise.prototype.transition = function(id, property, value, duration)
{
return this.then(function ()
{
return transition(id, property, value, duration);
});
}
function delay(sleep)
{
return new Promise(function (resolve, reject)
{
setTimeout(resolve, sleep);
});
}
function call__()
{
const theFunction = arguments[0];
const args = Array.prototype.slice.call(arguments, 1, arguments.length - 1);
return function ()
{
return theFunction.apply(this, args);
}
}
function type(text, WPM, direction)
{
if (!direction)
direction = "right";
const averageCharactersPerWord = 5.1;
const CPM = (WPM || 160) * averageCharactersPerWord;
const baseDelay = 1000 / (CPM / 60);
const length = text.length;
return new Promise(function (resolve, reject)
{
(function type(index)
{
document.getElementById("rest-" + direction).innerText += text.charAt(index);
if (index === length - 1)
return window.requestAnimationFrame(function ()
{
resolve();
});
window.setTimeout(type, normalizedDelays[index % normalizedDelays.length] * baseDelay, index + 1);
})(0);
});
}
function deleteToRunKit(WPM)
{
const averageCharactersPerWord = 5.1;
const CPM = (WPM || 160) * averageCharactersPerWord;
const baseDelay = 1000 / (CPM / 60);
return new Promise(function (resolve, reject)
{
(function deleteOne(index)
{
const text = document.getElementById("rest-right").innerText;
const newText = text.substr(0, text.length - 1);
console.log(newText);
document.getElementById("rest-right").innerText = newText;
if (newText === "")
return resolve();
window.setTimeout(deleteOne, normalizedDelays[index % normalizedDelays.length] * baseDelay, index + 1);
})(0);
});
}
function transition(id, property, value, duration)
{
if (Array.isArray(id))
return id.map(function (props)
{
return transition(...props);
}).reduce(function (previous, next) { return previous.then(next); }, Promise.resolve());
const element = document.getElementById(id);
const style = element.style;
return new Promise(function (resolve, reject)
{
element.addEventListener("transitionend", function handle()
{
resolve();
element.removeEventListener("transitionend", handle);
});
style.transition += (style.transition.length > 0 ? ", " : "") + property + " " + duration;
style[property] = value;
});
}
function showButton(which)
{
return transition(which, "opacity", 1, ".5s");
}
function hideButton()
{
return transition("right", "opacity", 0, ".3s");
}
</script>
<style>
body {
border:0;
margin:0;
padding:0;
}
.logo {
background: url("./logo.png");
background-size: 100%;
background-repeat: none;
height: 150pt;
width: 150pt;
display: block;
border-radius: 7%;
position: absolute;
left:0;
right:0;
top:-200pt;
bottom:0;
margin:auto;
opacity: 0;
transition: all 0.45s;
}
.opaque {
opacity: 1;
}
.try-it-now
{
-webkit-font-smoothing: antialiased;
background-color: rgb(40, 175, 250);
border-radius: 4px;
border:1px solid rgb(40, 175, 250);
box-sizing: border-box;
cursor: pointer;
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-weight: 600;
font-size: 16px;
height: 34px;
line-height: 14px;
text-align: center;
text-rendering: optimizelegibility;
color:white;
width:100px;
}
div#right-container
{
margin:0;
padding:0;
width:0px;
position:relative;
background:red;
width:0px;
height: 0px;
line-height: 14px;
display:inline-block;
}
button#right
{
margin:0;
padding:0;
width:0px;
position:absolute;
top:-26px;
width:100px;
height: 34px;
line-height: 14px;
margin-left:20px;
opacity:0;
}
.bottom
{
position: absolute;
left:0;
right:0;
top:100pt;
bottom:0;
margin: auto;
opacity: 1;
}
button#end-replay
{
left:-110px;
border:1px solid white;
background: transparent;
opacity:0;
}
button#end-try-it-now
{
position: absolute;
left:110px;
opacity:0;
}
</style>
</head>
<body>
<div style = "font: 35px 'Fira Sans'; font-weight: bold; text-align: center; width:100%; height: 100vh; line-height:100vh;">
<span id = "rest-left" style = "white-space:pre;"></span><span id = "introducing" style = "max-width:500px; vertical-align:top; display:inline-block; overflow: hidden; font-family:Roboto; font-weight:300">Introducing </span><span style = "white-space:pre;">RunKit</span><span id = "rest-right" style = "white-space:pre; font-family:Roboto; font-weight:300;"></span><div id = "right-container"><button id = "right" data-demokit-click-action = "href:http://runkit.com/new" class = "try-it-now bottom">Try It Now</button></div>
</div>
<div class="logo"></div>
<button id = "bottom" class = "try-it-now bottom" data-demokit-click-action = "href:http://runkit.com/new">Try It Now</button>
<button id = "end-replay" class = "try-it-now bottom" data-demokit-click-action = "replay" class = "tryitnow bottom">Replay</button>
<button id = "end-try-it-now" class = "try-it-now bottom" data-demokit-click-action = "href:http://runkit.com/new">Try It Now</button>
</body>
<script>
function fadeIn()
{
return new Promise(function (resolve, reject)
{
var logo = document.querySelector(".logo");
document.addEventListener("transitionend", function handle()
{
document.removeEventListener("transitionend", handle);
resolve();
});
logo.classList.add("opaque");
});
}
</script>
</html>