Skip to content

Commit 0247813

Browse files
committed
fixed merge conflicts
2 parents 86b0f82 + 44ea7e1 commit 0247813

File tree

9 files changed

+84
-35
lines changed

9 files changed

+84
-35
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ var typed = new Typed(".element", {
125125
});
126126
~~~
127127

128+
### Bulk Typing
129+
130+
The following example would emulate how a terminal acts when typing a command and seeing its result.
131+
132+
~~~ javascript
133+
var typed = new Typed(".element", {
134+
strings: [
135+
"git push --force ^1000\n `pushed to origin with option force`"
136+
]
137+
});
138+
~~~
139+
128140
### CSS
129141

130142
CSS animations are build upon initialzation in JavaScript. But, you can customize them at your will! These classes are:

assets/demos.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
document.addEventListener('DOMContentLoaded', function() {
2-
var typed = new Typed("#typed", {
2+
var typed = new Typed('#typed', {
33
stringsElement: '#typed-strings',
44
typeSpeed: 20,
55
backSpeed: 20,
66
startDelay: 1000,
77
loop: false,
88
loopCount: Infinity,
9-
onComplete: function(self) { prettyLog('onCmplete ' + self) },
9+
onComplete: function(self) { prettyLog('onComplete ' + self) },
1010
preStringTyped: function(pos, self) { prettyLog('preStringTyped ' + pos + ' ' + self); },
1111
onStringTyped: function(pos, self) { prettyLog('onStringTyped ' + pos + ' ' + self) },
1212
onLastStringBackspaced: function(self) { prettyLog('onLastStringBackspaced ' + self) },
@@ -74,6 +74,13 @@ document.addEventListener('DOMContentLoaded', function() {
7474
smartBackspace: false,
7575
loop: true
7676
});
77+
78+
new Typed('#typed6', {
79+
strings: ['npm install^1000\n`installing components...` ^1000\n`Fetching from source...`'],
80+
typeSpeed: 40,
81+
backSpeed: 0,
82+
loop: true
83+
});
7784
});
7885

7986
function prettyLog(str) {

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typed.js",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"homepage": "https://github.com/mattboldt/typed.js",
55
"authors": [
66
"Matt Boldt <[email protected]>"

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ gulp.task('html-docs', () => {
4747
return gulp.src('./src/*.js')
4848
.pipe(gulpDocumentation('html'), {}, {
4949
name: 'Typed.js Docs',
50-
version: '2.0.2'
50+
version: '2.0.3'
5151
})
5252
.pipe(gulp.dest('docs'));
5353
});

lib/typed.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* typed.js - A JavaScript Typing Animation Library
44
* Author: Matt Boldt <[email protected]>
5-
* Version: v2.0.1
5+
* Version: v2.0.3
66
* Url: https://github.com/mattboldt/typed.js
77
* License(s): MIT
88
*
@@ -215,6 +215,7 @@ return /******/ (function(modules) { // webpackBootstrap
215215
}
216216

217217
var humanize = this.humanizer(this.typeSpeed);
218+
var numChars = 1;
218219

219220
if (this.pause.status === true) {
220221
this.setPauseStatus(curString, curStrPos, true);
@@ -223,27 +224,42 @@ return /******/ (function(modules) { // webpackBootstrap
223224

224225
// contain typing function in a timeout humanize'd delay
225226
this.timeout = setTimeout(function () {
227+
// skip over any HTML chars
228+
curStrPos = _htmlParserJs.htmlParser.typeHtmlChars(curString, curStrPos, _this2);
229+
230+
var pauseTime = 0;
231+
var substr = curString.substr(curStrPos);
226232
// check for an escape character before a pause value
227233
// format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
228234
// single ^ are removed from string
229-
var pauseTime = 0;
230-
var substr = curString.substr(curStrPos);
231235
if (substr.charAt(0) === '^') {
232-
var skip = 1; // skip atleast 1
233236
if (/^\^\d+/.test(substr)) {
237+
var skip = 1; // skip at least 1
234238
substr = /\d+/.exec(substr)[0];
235239
skip += substr.length;
236240
pauseTime = parseInt(substr);
237241
_this2.temporaryPause = true;
238242
_this2.options.onTypingPaused(_this2.arrayPos, _this2);
243+
// strip out the escape character and pause value so they're not printed
244+
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
245+
_this2.toggleBlinking(true);
239246
}
240-
_this2.toggleBlinking(true);
241-
242-
// strip out the escape character and pause value so they're not printed
243-
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
244247
}
245248

246-
curStrPos = _htmlParserJs.htmlParser.typeHtmlChars(curString, curStrPos, _this2);
249+
// check for skip characters formatted as
250+
// "this is a `string to print NOW` ..."
251+
if (substr.charAt(0) === '`') {
252+
while (curString.substr(curStrPos + numChars).charAt(0) !== '`') {
253+
numChars++;
254+
if (curStrPos + numChars > curString.length) break;
255+
}
256+
// strip out the escape characters and append all the string in between
257+
var stringBeforeSkip = curString.substring(0, curStrPos);
258+
var stringSkipped = curString.substring(stringBeforeSkip.length + 1, curStrPos + numChars);
259+
var stringAfterSkip = curString.substring(curStrPos + numChars + 1);
260+
curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
261+
numChars--;
262+
}
247263

248264
// timeout for any pause after a character
249265
_this2.timeout = setTimeout(function () {
@@ -254,7 +270,7 @@ return /******/ (function(modules) { // webpackBootstrap
254270
if (curStrPos === curString.length) {
255271
_this2.doneTyping(curString, curStrPos);
256272
} else {
257-
_this2.keepTyping(curString, curStrPos);
273+
_this2.keepTyping(curString, curStrPos, numChars);
258274
}
259275
// end of character pause
260276
if (_this2.temporaryPause) {
@@ -275,18 +291,17 @@ return /******/ (function(modules) { // webpackBootstrap
275291
*/
276292
}, {
277293
key: 'keepTyping',
278-
value: function keepTyping(curString, curStrPos) {
294+
value: function keepTyping(curString, curStrPos, numChars) {
279295
// call before functions if applicable
280296
if (curStrPos === 0) {
281297
this.toggleBlinking(false);
282298
this.options.preStringTyped(this.arrayPos, this);
283299
}
284300
// start typing each new char into existing string
285301
// curString: arg, this.el.html: original text inside element
286-
var nextString = curString.substr(0, curStrPos + 1);
302+
curStrPos += numChars;
303+
var nextString = curString.substr(0, curStrPos);
287304
this.replaceText(nextString);
288-
// add characters one by one
289-
curStrPos++;
290305
// loop the function
291306
this.typewrite(curString, curStrPos);
292307
}

lib/typed.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/typed.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typed.js",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"homepage": "https://github.com/mattboldt/typed.js",
55
"repository": "https://github.com/mattboldt/typed.js",
66
"license": "MIT",

src/typed.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default class Typed {
115115
}
116116

117117
const humanize = this.humanizer(this.typeSpeed);
118+
let numChars = 1;
118119

119120
if (this.pause.status === true) {
120121
this.setPauseStatus(curString, curStrPos, true);
@@ -123,27 +124,42 @@ export default class Typed {
123124

124125
// contain typing function in a timeout humanize'd delay
125126
this.timeout = setTimeout(() => {
127+
// skip over any HTML chars
128+
curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);
129+
130+
let pauseTime = 0;
131+
let substr = curString.substr(curStrPos);
126132
// check for an escape character before a pause value
127133
// format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
128134
// single ^ are removed from string
129-
let pauseTime = 0;
130-
let substr = curString.substr(curStrPos);
131135
if (substr.charAt(0) === '^') {
132-
let skip = 1; // skip atleast 1
133136
if (/^\^\d+/.test(substr)) {
137+
let skip = 1; // skip at least 1
134138
substr = /\d+/.exec(substr)[0];
135139
skip += substr.length;
136140
pauseTime = parseInt(substr);
137141
this.temporaryPause = true;
138142
this.options.onTypingPaused(this.arrayPos, this);
143+
// strip out the escape character and pause value so they're not printed
144+
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
145+
this.toggleBlinking(true);
139146
}
140-
this.toggleBlinking(true);
141-
142-
// strip out the escape character and pause value so they're not printed
143-
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
144147
}
145148

146-
curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);
149+
// check for skip characters formatted as
150+
// "this is a `string to print NOW` ..."
151+
if (substr.charAt(0) === '`') {
152+
while (curString.substr(curStrPos + numChars).charAt(0) !== '`') {
153+
numChars++;
154+
if (curStrPos + numChars > curString.length) break;
155+
}
156+
// strip out the escape characters and append all the string in between
157+
const stringBeforeSkip = curString.substring(0, curStrPos);
158+
const stringSkipped = curString.substring(stringBeforeSkip.length + 1, curStrPos + numChars);
159+
const stringAfterSkip = curString.substring(curStrPos + numChars + 1);
160+
curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
161+
numChars--;
162+
}
147163

148164
// timeout for any pause after a character
149165
this.timeout = setTimeout(() => {
@@ -154,7 +170,7 @@ export default class Typed {
154170
if (curStrPos === curString.length) {
155171
this.doneTyping(curString, curStrPos);
156172
} else {
157-
this.keepTyping(curString, curStrPos);
173+
this.keepTyping(curString, curStrPos, numChars);
158174
}
159175
// end of character pause
160176
if (this.temporaryPause) {
@@ -173,18 +189,17 @@ export default class Typed {
173189
* @param {number} curStrPos the current position in the curString
174190
* @private
175191
*/
176-
keepTyping(curString, curStrPos) {
192+
keepTyping(curString, curStrPos, numChars) {
177193
// call before functions if applicable
178194
if (curStrPos === 0) {
179195
this.toggleBlinking(false);
180196
this.options.preStringTyped(this.arrayPos, this);
181197
}
182198
// start typing each new char into existing string
183199
// curString: arg, this.el.html: original text inside element
184-
const nextString = curString.substr(0, curStrPos + 1);
200+
curStrPos += numChars;
201+
const nextString = curString.substr(0, curStrPos);
185202
this.replaceText(nextString);
186-
// add characters one by one
187-
curStrPos++;
188203
// loop the function
189204
this.typewrite(curString, curStrPos);
190205
}

0 commit comments

Comments
 (0)