-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
304 lines (266 loc) · 11.1 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<head>
<title>tply demo</title>
<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,300' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css">
<link rel="stylesheet" href="static/zenburn.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<script src="dist/tply.js"></script>
<link rel="stylesheet" href="css/global.css">
<link rel="icon" type="image/png" href="favicon.png">
</head>
<body>
<div class="container">
<h1 class="page-title">tply demo</h1>
<div class="github-container">
<iframe src="https://ghbtns.com/github-btn.html?user=ichub&repo=tply&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=ichub&type=follow&count=true&size=large" frameborder="0" scrolling="0" width="220px" height="30px"></iframe>
</div>
<div class="examples">
<div class="example-container" data-title="simple text">
<type>
Why, hello there! How are you? I'm good!
</type>
</div>
<div class="example-container" data-title="pauses">
<type>Once upon a time...</type>
<wait>500ms</wait>
<br>
<type>There was a dramatic pause!</type>
</div>
<div class="example-container" data-title="delete previously typed characters">
<type>
<span>this text will be deleted</span>
</type>
<wait>500ms</wait>
<delete data-chars="21" data-ignore-whitespace="true"></delete>
<wait>500ms</wait>
<type>
told you :P
</type>
</div>
<div class="example-container" data-title="repeats">
<repeat data-repeat="3">
<type>This will repeat three times!</type>
<br>
</repeat>
</div>
<div class="example-container" data-title="clears (and infinite repeat)">
<repeat data-repeat="infinite">
<type>This will repeat forever!</type>
<wait>1s</wait>
<clearparent></clearparent>
</repeat>
</div>
<div class="example-container" data-title="styling">
<type style="font-size:200%;font-style:italic;">
No need to skimp out on
<span style="color:purple;font-weight:bold;">
flair!
</span>
</type>
</div>
<div class="example-container" data-title="customizing with attributes">
<type data-type="robot">
I am a spooky spooky SPOOKY robot!
</type>
<div class="configuration">
{
"types": [
{
"name": "robot",
"properties": {
"data-char-interval": "0ms",
"data-word-interval": "100ms"
}
}
]
}
</div>
</div>
<div class="example-container" data-title="more customization">
<type data-type="cool">
I am the coolest in the whole entire world.
</type>
<div class="configuration">
{
"types": [
{
"name": "cool",
"properties": {
"data-char-interval": "20ms"
},
"style": "color:blue;"
}
]
}
</div>
</div>
<div class="example-container" data-title="more customization">
<type>
<span>cool</span>
</type>
<div class="configuration">
{
"processing": [
{
"tag": "span",
"pre": function(el) {
el.textContent +=
";DROP TABLE users --";
},
"post": function(el) {
el.onclick = function() {
alert("cool (:");
}
}
}
]
}
</div>
</div>
</div>
<div id="explanation">
<div class="title">How can I run these myself?</div>
<div id="explanation-text">
To run each of these examples on your own, copy the html and configuration as it is presented above
into the designated spaces in the html below.
</div>
<code class="html">
<pre><html>
<head>
<title>tply animation</title>
<style>
#tply-source {
display: none; /* we don't want our template to be visible */
}
</style>
<script src="tply.js"></script> <!-- a reference to the tply file -->
</head>
<body>
<div id="tply-source">
<!-- the html you see in each example goes here -->
</div>
<div id="tply-destination">
<!-- this is where stuff is rendered-->
</div>
<script>
tply.animate(
document.getElementById("tply-source"),
document.getElementById("tply-destination"),
{ /*this is where the configuration you see would go */ });
</script>
</body>
</html></pre></code>
</div>
<script>
(function () {
"use strict";
hljs.highlightBlock(document.querySelector("#explanation code"));
var innerText = function(element) {
return element.innerText || element.textContent;
};
var setInnerText = function(element, text) {
if (typeof element.innerText !== "undefined") {
element.innerText = text;
} else {
element.textContent = text;
}
};
var unindentCode = function (text) {
var parts = text.split("\n").filter(function (item) {
return item.length > 0;
});
var result = "";
if (parts.length > 0) {
var count = 0;
while (parts[0][count] == " " && count < parts[0].length) {
count++;
}
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
var partText = "";
for (var j = count; j < parts[i].length; j++) {
partText += part[j];
}
result += partText;
if (i < parts.length - 2) {
result += "\n";
}
}
}
return result;
};
var createCodeElement = function (codeText, language) {
var code = document.createElement("code");
var pre = document.createElement("pre");
setInnerText(pre, unindentCode(codeText))
code.appendChild(pre);
code.classList.add(language);
return code;
};
var createExample = function (exampleContainer) {
var configurationElement = exampleContainer.querySelector(".configuration");
var configObject = {};
var hasConfig = false;
if (configurationElement !== null && typeof configurationElement !== "undefined") {
configObject = eval("configObject = " + innerText(configurationElement));
exampleContainer.removeChild(configurationElement);
hasConfig = true;
}
var example = document.createElement("div");
example.classList.add("example");
var template = document.createElement("div");
template.classList.add("tply-template");
template.innerHTML = exampleContainer.innerHTML;
exampleContainer.innerHTML = "";
var title = document.createElement("div");
title.classList.add("title");
setInnerText(title, exampleContainer.getAttribute("data-title"));
var redo = document.createElement("div");
redo.classList.add("redo");
setInnerText(redo, "redo");
title.appendChild(redo);
exampleContainer.appendChild(title);
example.appendChild(template);
exampleContainer.appendChild(example);
var destination = document.createElement("div");
destination.classList.add("tply-destination");
template.parentNode.appendChild(destination);
var code = createCodeElement(template.innerHTML, "html");
exampleContainer.appendChild(code);
hljs.highlightBlock(code);
if (hasConfig) {
var separator = document.createElement("div");
separator.classList.add("separator");
setInnerText(separator, "With the following configuration:");
exampleContainer.appendChild(separator);
var config = createCodeElement(innerText(configurationElement), "javascript");
exampleContainer.appendChild(config);
hljs.highlightBlock(config);
}
var status = tply.animate(template, destination, configObject);
redo.addEventListener("click", function () {
var restart = function () {
destination.innerHTML = "";
status = tply.animate(template, destination, configObject);
};
if (status.isFinished) {
restart();
} else {
status.cancel(restart);
}
});
};
var examples = document.querySelectorAll(".examples .example-container");
for (var i = 0; i < examples.length; i++) {
var exampleContainer = examples[i];
createExample(exampleContainer)
}
})();
</script>
</div>
</body>
</html>