2
2
*
3
3
* typed.js - A JavaScript Typing Animation Library
4
4
* Author: Matt Boldt <[email protected] >
5
- * Version: v2.0.1
5
+ * Version: v2.0.3
6
6
* Url: https://github.com/mattboldt/typed.js
7
7
* License(s): MIT
8
8
*
@@ -215,6 +215,7 @@ return /******/ (function(modules) { // webpackBootstrap
215
215
}
216
216
217
217
var humanize = this . humanizer ( this . typeSpeed ) ;
218
+ var numChars = 1 ;
218
219
219
220
if ( this . pause . status === true ) {
220
221
this . setPauseStatus ( curString , curStrPos , true ) ;
@@ -223,27 +224,42 @@ return /******/ (function(modules) { // webpackBootstrap
223
224
224
225
// contain typing function in a timeout humanize'd delay
225
226
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 ) ;
226
232
// check for an escape character before a pause value
227
233
// format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
228
234
// single ^ are removed from string
229
- var pauseTime = 0 ;
230
- var substr = curString . substr ( curStrPos ) ;
231
235
if ( substr . charAt ( 0 ) === '^' ) {
232
- var skip = 1 ; // skip atleast 1
233
236
if ( / ^ \^ \d + / . test ( substr ) ) {
237
+ var skip = 1 ; // skip at least 1
234
238
substr = / \d + / . exec ( substr ) [ 0 ] ;
235
239
skip += substr . length ;
236
240
pauseTime = parseInt ( substr ) ;
237
241
_this2 . temporaryPause = true ;
238
242
_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 ) ;
239
246
}
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 ) ;
244
247
}
245
248
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
+ }
247
263
248
264
// timeout for any pause after a character
249
265
_this2 . timeout = setTimeout ( function ( ) {
@@ -254,7 +270,7 @@ return /******/ (function(modules) { // webpackBootstrap
254
270
if ( curStrPos === curString . length ) {
255
271
_this2 . doneTyping ( curString , curStrPos ) ;
256
272
} else {
257
- _this2 . keepTyping ( curString , curStrPos ) ;
273
+ _this2 . keepTyping ( curString , curStrPos , numChars ) ;
258
274
}
259
275
// end of character pause
260
276
if ( _this2 . temporaryPause ) {
@@ -275,18 +291,17 @@ return /******/ (function(modules) { // webpackBootstrap
275
291
*/
276
292
} , {
277
293
key : 'keepTyping' ,
278
- value : function keepTyping ( curString , curStrPos ) {
294
+ value : function keepTyping ( curString , curStrPos , numChars ) {
279
295
// call before functions if applicable
280
296
if ( curStrPos === 0 ) {
281
297
this . toggleBlinking ( false ) ;
282
298
this . options . preStringTyped ( this . arrayPos , this ) ;
283
299
}
284
300
// start typing each new char into existing string
285
301
// 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 ) ;
287
304
this . replaceText ( nextString ) ;
288
- // add characters one by one
289
- curStrPos ++ ;
290
305
// loop the function
291
306
this . typewrite ( curString , curStrPos ) ;
292
307
}
0 commit comments