-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
304 lines (261 loc) · 9.79 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>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Typing.js</title>
</head>
<body>
<div class="body">
<div class="body__centering">
<div class="body__title">
<h1>typing.js</h1>
</div>
<div class="body__window"></div>
<div class="body__links-block">
<a href="#content" class="get-link">Get Started</a><br>
<a href="https://github.com/antpv/typingscript" class="git-link"><span class="get-link__image"><img src="css/img/github-logo.svg"></span> View on Github</a>
</div>
</div>
</div>
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-12">
<div class="content__title">
<h2>Installation</h2>
</div>
<div class="content__text">
<h3>Cdn</h3>
<p>Connect this script:</p>
<div class="content__url"><script src="https://unpkg.com/typingscript@0.0.2/typingscript.min.js" defer></script></div>
</div>
<div class="content__text mgtop">
<h3>Npm</h3>
<p>Run npm command:</p>
<div class="content__url">npm install typingscript</div>
<p>The typical import default (main) file:</p>
<div class="content__url">import Typing from 'typingscript';</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="content__title">
<h2>Usage</h2>
</div>
<div class="content__text">
<p>Run the script:</p>
<div class="content__code">new typing(options)</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="content__subtitle">
<h3>Options properties:</h3>
</div>
<div class="content__object-config">
<div class="content__object-config_row">
element: (<span class="content__value">DOMElementNode</span>)<span class="content__important">!important</span>
<div class="content__object-config_row_text">DOM element node in which the script will be executed</div>
</div>
<div class="content__object-config_row">
strings: (<span class="content__value">array</span>)
<div class="content__object-config_row_text">An array of strings to be typing in the element.<br>Each line will be typed, deleted, and then the next line will be typed.<br>Can be replaced or merged with .type()</div>
</div>
<div class="content__object-config_row">
afterStringPause: (<span class="content__value">number</span>)<span class="content__default">default: 1000</span>
<div class="content__object-config_row_text">Pause after each typed line.<br>Works only for strings added by options: string parameter</div>
</div>
<div class="content__object-config_row">
speed: (<span class="content__value">number</span>)<span class="content__default">default: 60</span>
<div class="content__object-config_row_text">Typing speed in milliseconds.</div>
</div>
<div class="content__object-config_row">
removalRate: (<span class="content__value">number</span>)<span class="content__default">default: 30</span>
<div class="content__object-config_row_text">The rate of removal of text in milliseconds.</div>
</div>
<div class="content__object-config_row">
loop: (<span class="content__value">boolean</span>)<span class="content__default">default: false</span>
<div class="content__object-config_row_text">A parameter that tells the script to repeat typing text all the time.</div>
</div>
<div class="content__object-config_row">
autoStart: (<span class="content__value">boolean</span>)<span class="content__default">default: false</span>
<div class="content__object-config_row_text">The parameter responsible for running water, even if the item is not visible to the user at the moment.</div>
</div>
<div class="content__object-config_row">
cursor: (<span class="content__value">boolean</span>)<span class="content__default">default: true</span>
<div class="content__object-config_row_text">The parameter that is responsible for displaying the cursor.</div>
</div>
<div class="content__object-config_row">
cursorHTML: (<span class="content__value">string</span>)<span class="content__default">default: '|'</span>
<div class="content__object-config_row_text">The symbol that will be displayed instead of the cursor. Allowed HTML.</div>
</div>
<div class="content__object-config_row">
blinkingCursor: (<span class="content__value">boolean</span>)<span class="content__default">default: true</span>
<div class="content__object-config_row_text">Parameter responsible for blinking the cursor.</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="content__subtitle">
<h3>Examples:</h3>
</div>
<div class="content__text">
<p>A simple example of script execution:</p>
<div class="content__code">new typing({
element: document.getElementById('#id'),
strings: ['First string', 'Next string'],
loop: true
})</div>
<div class="content__window" id="simple-window"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="content__text">
<p>You can also call methods on an object:</p>
<div class="content__code"> new typing({
element: document.getElementById('#id'),
speed: 60,
removalRate: 40,
loop: true
})
.type('It\'s very simple')
.pause(1000)
.delete()
.type('Try it yourself!')
.pause(1000)</div>
<div class="content__window" id="chaining-window"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="content__subtitle">
<h3>Chaining:</h3>
</div>
<div class="content__object-config">
<div class="content__object-config_row">
.type(<span class="content__value">string</span>)
<div class="content__object-config_row_text">Adds a string to the task stack for typing a.</div>
</div>
<div class="content__object-config_row">
.delete(<span class="content__value">number</span>)
<div class="content__object-config_row_text">Adds the number of characters to the task stack for deletion.</div></div>
<div class="content__object-config_row">
.optoins(<span class="content__value">object</span>)
<div class="content__object-config_row_text">Updates the parameters object.</div></div>
<div class="content__object-config_row">
.pause(<span class="content__value">number</span>)
<div class="content__object-config_row_text">Adds a pause to the task stack.</div></div>
<div class="content__object-config_row">
.break()
<div class="content__object-config_row_text">Adds a line break to the task stack.</div></div>
<div class="content__object-config_row">
.freeze()
<div class="content__object-config_row_text">Freezes the execution of the script.</div></div>
<div class="content__object-config_row">
.unfreeze()
<div class="content__object-config_row_text">Unfreezes the execution of the script.</div></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="bottom center">
Developed with <span class="bottom__heart"><img src="css/img/heart.svg"></span> by Dmitry Antipov
</div>
</div>
</div>
<script src="js/typingscript.min.js"></script>
<script>
'use strict';
new typing({
element: document.getElementById('simple-window'),
strings: ['First string', 'Next string'],
loop: true
});
var code = document.body.querySelectorAll('.content__code');
Array.prototype.forEach.call(code, function (item) {
item.innerHTML = syntax(item.innerHTML.trim());
});
function syntax(code) {
var comments = [];
var strings = [];
var res = [];
var all = { 'C': comments, 'S': strings, 'R': res };
var safe = { '<': '<', '>': '>', '&': '&' };
return code.replace(/[<>&]/g, function (m) {
return safe[m];
}).replace(/\/\*[\s\S]*\*\//g, function (m) {
var l = comments.length;comments.push(m);return '~~~C' + l + '~~~';
}).replace(/([^\\])\/\/[^\n]*\n/g, function (m, f) {
var l = comments.length;comments.push(m);return f + '~~~C' + l + '~~~';
}).replace(/\/(\\\/|[^\/\n])*\/[gim]{0,3}/g, function (m) {
var l = res.length;res.push(m);return '~~~R' + l + '~~~';
}).replace(/([^\\])((?:'(?:\\'|[^'])*')|(?:"(?:\\"|[^"])*"))/g, function (m, f, s) {
var l = strings.length;strings.push(s);return f + '~~~S' + l + '~~~';
}).replace(/(var|function|typeof|new|return|if|for|in|while|break|do|continue|switch|case)([^a-z0-9\$_])/gi, '<span class="kwrd">$1</span>$2').replace(/(\{|\}|\]|\[|\|)/gi, '<span class="gly">$1</span>').replace(/([a-z\_\$][a-z0-9_]*)[\s]*\(/gi, '<span class="func">$1</span>(').replace(/~~~([CSR])(\d+)~~~/g, function (m, t, i) {
return '<span class="' + t + '">' + all[t][i] + '</span>';
}).replace(/\n/g, '<br/>').replace(/\t/g, ' ');
}
document.addEventListener('click', function (e) {
var target = e.target.closest('.content__object-config_row');
if (target) {
target.onmousedown = function () {
return false;
};
if (target.classList.contains('open')) target.classList.remove('open');else target.classList.add('open');
}
});
var f = new typing({
element: document.body.querySelector('.body__window'),
speed: 60,
removalRate: 40,
loop: false,
cursor: true,
blinkingCursor: true,
autoStart: false
})
.type('Hello develooper')
.pause(500)
.options({
removalRate: 100
})
.delete(4)
.pause(500)
.type('per')
.options({
speed: 200
})
.type('..')
.options({
speed: 60
})
.pause(700)
.break()
.type('how are you?')
.options({
removalRate: 20
})
.pause(2000);
new typing({
element: document.getElementById('chaining-window'),
speed: 60,
removalRate: 40,
loop: true
})
.type('It\'s very simple')
.pause(1000)
.delete()
.type('Try it yourself!')
.pause(1000);
</script>
</body>
</html>