-
Notifications
You must be signed in to change notification settings - Fork 1
/
typed.js
1045 lines (906 loc) · 31.9 KB
/
typed.js
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
*
* typed.js - A JavaScript Typing Animation Library
* Author: Matt Boldt <me@mattboldt.com>
* Version: v2.0.9
* Url: https://github.com/mattboldt/typed.js
* License(s): MIT
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["Typed"] = factory();
else
root["Typed"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _initializerJs = __webpack_require__(1);
var _htmlParserJs = __webpack_require__(3);
/**
* Welcome to Typed.js!
* @param {string} elementId HTML element ID _OR_ HTML element
* @param {object} options options object
* @returns {object} a new Typed object
*/
var Typed = (function () {
function Typed(elementId, options) {
_classCallCheck(this, Typed);
// Initialize it up
_initializerJs.initializer.load(this, options, elementId);
// All systems go!
this.begin();
}
/**
* Toggle start() and stop() of the Typed instance
* @public
*/
_createClass(Typed, [{
key: 'toggle',
value: function toggle() {
this.pause.status ? this.start() : this.stop();
}
/**
* Stop typing / backspacing and enable cursor blinking
* @public
*/
}, {
key: 'stop',
value: function stop() {
clearInterval(this.timeout);
if (this.typingComplete) return;
if (this.pause.status) return;
this.toggleBlinking(true);
this.pause.status = true;
this.options.onStop(this.arrayPos, this);
}
/**
* Start typing / backspacing after being stopped
* @public
*/
}, {
key: 'start',
value: function start() {
if (this.typingComplete) return;
if (!this.pause.status) return;
this.pause.status = false;
if (this.pause.typewrite) {
this.typewrite(this.pause.curString, this.pause.curStrPos);
} else {
this.backspace(this.pause.curString, this.pause.curStrPos);
}
this.options.onStart(this.arrayPos, this);
}
/**
* Destroy this instance of Typed
* @public
*/
}, {
key: 'destroy',
value: function destroy() {
this.reset(false);
this.options.onDestroy(this);
}
/**
* Reset Typed and optionally restarts
* @param {boolean} restart
* @public
*/
}, {
key: 'reset',
value: function reset() {
var restart = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
clearInterval(this.timeout);
this.replaceText('');
if (this.cursor && this.cursor.parentNode) {
this.cursor.parentNode.removeChild(this.cursor);
this.cursor = null;
}
this.strPos = 0;
this.arrayPos = 0;
this.curLoop = 0;
if (restart) {
this.insertCursor();
this.options.onReset(this);
this.begin();
}
}
/**
* Begins the typing animation
* @private
*/
}, {
key: 'begin',
value: function begin() {
var _this = this;
this.typingComplete = false;
this.shuffleStringsIfNeeded(this);
this.insertCursor();
if (this.bindInputFocusEvents) this.bindFocusEvents();
this.timeout = setTimeout(function () {
// Check if there is some text in the element, if yes start by backspacing the default message
if (!_this.currentElContent || _this.currentElContent.length === 0) {
_this.typewrite(_this.strings[_this.sequence[_this.arrayPos]], _this.strPos);
} else {
// Start typing
_this.backspace(_this.currentElContent, _this.currentElContent.length);
}
}, this.startDelay);
}
/**
* Called for each character typed
* @param {string} curString the current string in the strings array
* @param {number} curStrPos the current position in the curString
* @private
*/
}, {
key: 'typewrite',
value: function typewrite(curString, curStrPos) {
var _this2 = this;
if (this.fadeOut && this.el.classList.contains(this.fadeOutClass)) {
this.el.classList.remove(this.fadeOutClass);
if (this.cursor) this.cursor.classList.remove(this.fadeOutClass);
}
var humanize = this.humanizer(this.typeSpeed);
var numChars = 1;
if (this.pause.status === true) {
this.setPauseStatus(curString, curStrPos, true);
return;
}
// contain typing function in a timeout humanize'd delay
this.timeout = setTimeout(function () {
// skip over any HTML chars
curStrPos = _htmlParserJs.htmlParser.typeHtmlChars(curString, curStrPos, _this2);
var pauseTime = 0;
var substr = curString.substr(curStrPos);
// check for an escape character before a pause value
// format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
// single ^ are removed from string
if (substr.charAt(0) === '^') {
if (/^\^\d+/.test(substr)) {
var skip = 1; // skip at least 1
substr = /\d+/.exec(substr)[0];
skip += substr.length;
pauseTime = parseInt(substr);
_this2.temporaryPause = true;
_this2.options.onTypingPaused(_this2.arrayPos, _this2);
// strip out the escape character and pause value so they're not printed
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
_this2.toggleBlinking(true);
}
}
// check for skip characters formatted as
// "this is a `string to print NOW` ..."
if (substr.charAt(0) === '`') {
while (curString.substr(curStrPos + numChars).charAt(0) !== '`') {
numChars++;
if (curStrPos + numChars > curString.length) break;
}
// strip out the escape characters and append all the string in between
var stringBeforeSkip = curString.substring(0, curStrPos);
var stringSkipped = curString.substring(stringBeforeSkip.length + 1, curStrPos + numChars);
var stringAfterSkip = curString.substring(curStrPos + numChars + 1);
curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
numChars--;
}
// timeout for any pause after a character
_this2.timeout = setTimeout(function () {
// Accounts for blinking while paused
_this2.toggleBlinking(false);
// We're done with this sentence!
if (curStrPos >= curString.length) {
_this2.doneTyping(curString, curStrPos);
} else {
_this2.keepTyping(curString, curStrPos, numChars);
}
// end of character pause
if (_this2.temporaryPause) {
_this2.temporaryPause = false;
_this2.options.onTypingResumed(_this2.arrayPos, _this2);
}
}, pauseTime);
// humanized value for typing
}, humanize);
}
/**
* Continue to the next string & begin typing
* @param {string} curString the current string in the strings array
* @param {number} curStrPos the current position in the curString
* @private
*/
}, {
key: 'keepTyping',
value: function keepTyping(curString, curStrPos, numChars) {
// call before functions if applicable
if (curStrPos === 0) {
this.toggleBlinking(false);
this.options.preStringTyped(this.arrayPos, this);
}
// start typing each new char into existing string
// curString: arg, this.el.html: original text inside element
curStrPos += numChars;
var nextString = curString.substr(0, curStrPos);
this.replaceText(nextString);
// loop the function
this.typewrite(curString, curStrPos);
}
/**
* We're done typing the current string
* @param {string} curString the current string in the strings array
* @param {number} curStrPos the current position in the curString
* @private
*/
}, {
key: 'doneTyping',
value: function doneTyping(curString, curStrPos) {
var _this3 = this;
// fires callback function
this.options.onStringTyped(this.arrayPos, this);
this.toggleBlinking(true);
// is this the final string
if (this.arrayPos === this.strings.length - 1) {
// callback that occurs on the last typed string
this.complete();
// quit if we wont loop back
if (this.loop === false || this.curLoop === this.loopCount) {
return;
}
}
this.timeout = setTimeout(function () {
_this3.backspace(curString, curStrPos);
}, this.backDelay);
}
/**
* Backspaces 1 character at a time
* @param {string} curString the current string in the strings array
* @param {number} curStrPos the current position in the curString
* @private
*/
}, {
key: 'backspace',
value: function backspace(curString, curStrPos) {
var _this4 = this;
if (this.pause.status === true) {
this.setPauseStatus(curString, curStrPos, true);
return;
}
if (this.fadeOut) return this.initFadeOut();
this.toggleBlinking(false);
var humanize = this.humanizer(this.backSpeed);
this.timeout = setTimeout(function () {
curStrPos = _htmlParserJs.htmlParser.backSpaceHtmlChars(curString, curStrPos, _this4);
// replace text with base text + typed characters
var curStringAtPosition = curString.substr(0, curStrPos);
_this4.replaceText(curStringAtPosition);
// if smartBack is enabled
if (_this4.smartBackspace) {
// the remaining part of the current string is equal of the same part of the new string
var nextString = _this4.strings[_this4.arrayPos + 1];
if (nextString && curStringAtPosition === nextString.substr(0, curStrPos)) {
_this4.stopNum = curStrPos;
} else {
_this4.stopNum = 0;
}
}
// if the number (id of character in current string) is
// less than the stop number, keep going
if (curStrPos > _this4.stopNum) {
// subtract characters one by one
curStrPos--;
// loop the function
_this4.backspace(curString, curStrPos);
} else if (curStrPos <= _this4.stopNum) {
// if the stop number has been reached, increase
// array position to next string
_this4.arrayPos++;
// When looping, begin at the beginning after backspace complete
if (_this4.arrayPos === _this4.strings.length) {
_this4.arrayPos = 0;
_this4.options.onLastStringBackspaced();
_this4.shuffleStringsIfNeeded();
_this4.begin();
} else {
_this4.typewrite(_this4.strings[_this4.sequence[_this4.arrayPos]], curStrPos);
}
}
// humanized value for typing
}, humanize);
}
/**
* Full animation is complete
* @private
*/
}, {
key: 'complete',
value: function complete() {
this.options.onComplete(this);
if (this.loop) {
this.curLoop++;
} else {
this.typingComplete = true;
}
}
/**
* Has the typing been stopped
* @param {string} curString the current string in the strings array
* @param {number} curStrPos the current position in the curString
* @param {boolean} isTyping
* @private
*/
}, {
key: 'setPauseStatus',
value: function setPauseStatus(curString, curStrPos, isTyping) {
this.pause.typewrite = isTyping;
this.pause.curString = curString;
this.pause.curStrPos = curStrPos;
}
/**
* Toggle the blinking cursor
* @param {boolean} isBlinking
* @private
*/
}, {
key: 'toggleBlinking',
value: function toggleBlinking(isBlinking) {
if (!this.cursor) return;
// if in paused state, don't toggle blinking a 2nd time
if (this.pause.status) return;
if (this.cursorBlinking === isBlinking) return;
this.cursorBlinking = isBlinking;
if (isBlinking) {
this.cursor.classList.add('typed-cursor--blink');
} else {
this.cursor.classList.remove('typed-cursor--blink');
}
}
/**
* Speed in MS to type
* @param {number} speed
* @private
*/
}, {
key: 'humanizer',
value: function humanizer(speed) {
return Math.round(Math.random() * speed / 2) + speed;
}
/**
* Shuffle the sequence of the strings array
* @private
*/
}, {
key: 'shuffleStringsIfNeeded',
value: function shuffleStringsIfNeeded() {
if (!this.shuffle) return;
this.sequence = this.sequence.sort(function () {
return Math.random() - 0.5;
});
}
/**
* Adds a CSS class to fade out current string
* @private
*/
}, {
key: 'initFadeOut',
value: function initFadeOut() {
var _this5 = this;
this.el.className += ' ' + this.fadeOutClass;
if (this.cursor) this.cursor.className += ' ' + this.fadeOutClass;
return setTimeout(function () {
_this5.arrayPos++;
_this5.replaceText('');
// Resets current string if end of loop reached
if (_this5.strings.length > _this5.arrayPos) {
_this5.typewrite(_this5.strings[_this5.sequence[_this5.arrayPos]], 0);
} else {
_this5.typewrite(_this5.strings[0], 0);
_this5.arrayPos = 0;
}
}, this.fadeOutDelay);
}
/**
* Replaces current text in the HTML element
* depending on element type
* @param {string} str
* @private
*/
}, {
key: 'replaceText',
value: function replaceText(str) {
if (this.attr) {
this.el.setAttribute(this.attr, str);
} else {
if (this.isInput) {
this.el.value = str;
} else if (this.contentType === 'html') {
this.el.innerHTML = str;
} else {
this.el.textContent = str;
}
}
}
/**
* If using input elements, bind focus in order to
* start and stop the animation
* @private
*/
}, {
key: 'bindFocusEvents',
value: function bindFocusEvents() {
var _this6 = this;
if (!this.isInput) return;
this.el.addEventListener('focus', function (e) {
_this6.stop();
});
this.el.addEventListener('blur', function (e) {
if (_this6.el.value && _this6.el.value.length !== 0) {
return;
}
_this6.start();
});
}
/**
* On init, insert the cursor element
* @private
*/
}, {
key: 'insertCursor',
value: function insertCursor() {
if (!this.showCursor) return;
if (this.cursor) return;
this.cursor = document.createElement('span');
this.cursor.className = 'typed-cursor';
this.cursor.innerHTML = this.cursorChar;
this.el.parentNode && this.el.parentNode.insertBefore(this.cursor, this.el.nextSibling);
}
}]);
return Typed;
})();
exports['default'] = Typed;
module.exports = exports['default'];
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _defaultsJs = __webpack_require__(2);
var _defaultsJs2 = _interopRequireDefault(_defaultsJs);
/**
* Initialize the Typed object
*/
var Initializer = (function () {
function Initializer() {
_classCallCheck(this, Initializer);
}
_createClass(Initializer, [{
key: 'load',
/**
* Load up defaults & options on the Typed instance
* @param {Typed} self instance of Typed
* @param {object} options options object
* @param {string} elementId HTML element ID _OR_ instance of HTML element
* @private
*/
value: function load(self, options, elementId) {
// chosen element to manipulate text
if (typeof elementId === 'string') {
self.el = document.querySelector(elementId);
} else {
self.el = elementId;
}
self.options = _extends({}, _defaultsJs2['default'], options);
// attribute to type into
self.isInput = self.el.tagName.toLowerCase() === 'input';
self.attr = self.options.attr;
self.bindInputFocusEvents = self.options.bindInputFocusEvents;
// show cursor
self.showCursor = self.isInput ? false : self.options.showCursor;
// custom cursor
self.cursorChar = self.options.cursorChar;
// Is the cursor blinking
self.cursorBlinking = true;
// text content of element
self.elContent = self.attr ? self.el.getAttribute(self.attr) : self.el.textContent;
// html or plain text
self.contentType = self.options.contentType;
// typing speed
self.typeSpeed = self.options.typeSpeed;
// add a delay before typing starts
self.startDelay = self.options.startDelay;
// backspacing speed
self.backSpeed = self.options.backSpeed;
// only backspace what doesn't match the previous string
self.smartBackspace = self.options.smartBackspace;
// amount of time to wait before backspacing
self.backDelay = self.options.backDelay;
// Fade out instead of backspace
self.fadeOut = self.options.fadeOut;
self.fadeOutClass = self.options.fadeOutClass;
self.fadeOutDelay = self.options.fadeOutDelay;
// variable to check whether typing is currently paused
self.isPaused = false;
// input strings of text
self.strings = self.options.strings.map(function (s) {
return s.trim();
});
// div containing strings
if (typeof self.options.stringsElement === 'string') {
self.stringsElement = document.querySelector(self.options.stringsElement);
} else {
self.stringsElement = self.options.stringsElement;
}
if (self.stringsElement) {
self.strings = [];
self.stringsElement.style.display = 'none';
var strings = Array.prototype.slice.apply(self.stringsElement.children);
var stringsLength = strings.length;
if (stringsLength) {
for (var i = 0; i < stringsLength; i += 1) {
var stringEl = strings[i];
self.strings.push(stringEl.innerHTML.trim());
}
}
}
// character number position of current string
self.strPos = 0;
// current array position
self.arrayPos = 0;
// index of string to stop backspacing on
self.stopNum = 0;
// Looping logic
self.loop = self.options.loop;
self.loopCount = self.options.loopCount;
self.curLoop = 0;
// shuffle the strings
self.shuffle = self.options.shuffle;
// the order of strings
self.sequence = [];
self.pause = {
status: false,
typewrite: true,
curString: '',
curStrPos: 0
};
// When the typing is complete (when not looped)
self.typingComplete = false;
// Set the order in which the strings are typed
for (var i in self.strings) {
self.sequence[i] = i;
}
// If there is some text in the element
self.currentElContent = this.getCurrentElContent(self);
self.autoInsertCss = self.options.autoInsertCss;
this.appendAnimationCss(self);
}
}, {
key: 'getCurrentElContent',
value: function getCurrentElContent(self) {
var elContent = '';
if (self.attr) {
elContent = self.el.getAttribute(self.attr);
} else if (self.isInput) {
elContent = self.el.value;
} else if (self.contentType === 'html') {
elContent = self.el.innerHTML;
} else {
elContent = self.el.textContent;
}
return elContent;
}
}, {
key: 'appendAnimationCss',
value: function appendAnimationCss(self) {
var cssDataName = 'data-typed-js-css';
if (!self.autoInsertCss) {
return;
}
if (!self.showCursor && !self.fadeOut) {
return;
}
if (document.querySelector('[' + cssDataName + ']')) {
return;
}
var css = document.createElement('style');
css.type = 'text/css';
css.setAttribute(cssDataName, true);
var innerCss = '';
if (self.showCursor) {
innerCss += '\n .typed-cursor{\n opacity: 1;\n }\n .typed-cursor.typed-cursor--blink{\n animation: typedjsBlink 0.7s infinite;\n -webkit-animation: typedjsBlink 0.7s infinite;\n animation: typedjsBlink 0.7s infinite;\n }\n @keyframes typedjsBlink{\n 50% { opacity: 0.0; }\n }\n @-webkit-keyframes typedjsBlink{\n 0% { opacity: 1; }\n 50% { opacity: 0.0; }\n 100% { opacity: 1; }\n }\n ';
}
if (self.fadeOut) {
innerCss += '\n .typed-fade-out{\n opacity: 0;\n transition: opacity .25s;\n }\n .typed-cursor.typed-cursor--blink.typed-fade-out{\n -webkit-animation: 0;\n animation: 0;\n }\n ';
}
if (css.length === 0) {
return;
}
css.innerHTML = innerCss;
document.body.appendChild(css);
}
}]);
return Initializer;
})();
exports['default'] = Initializer;
var initializer = new Initializer();
exports.initializer = initializer;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
/**
* Defaults & options
* @returns {object} Typed defaults & options
* @public
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var defaults = {
/**
* @property {array} strings strings to be typed
* @property {string} stringsElement ID of element containing string children
*/
strings: ['These are the default values...', 'You know what you should do?', 'Use your own!', 'Have a great day!'],
stringsElement: null,
/**
* @property {number} typeSpeed type speed in milliseconds
*/
typeSpeed: 0,
/**
* @property {number} startDelay time before typing starts in milliseconds
*/
startDelay: 0,
/**
* @property {number} backSpeed backspacing speed in milliseconds
*/
backSpeed: 0,
/**
* @property {boolean} smartBackspace only backspace what doesn't match the previous string
*/
smartBackspace: true,
/**
* @property {boolean} shuffle shuffle the strings
*/
shuffle: false,
/**
* @property {number} backDelay time before backspacing in milliseconds
*/
backDelay: 700,
/**
* @property {boolean} fadeOut Fade out instead of backspace
* @property {string} fadeOutClass css class for fade animation
* @property {boolean} fadeOutDelay Fade out delay in milliseconds
*/
fadeOut: false,
fadeOutClass: 'typed-fade-out',
fadeOutDelay: 500,
/**
* @property {boolean} loop loop strings
* @property {number} loopCount amount of loops
*/
loop: false,
loopCount: Infinity,
/**
* @property {boolean} showCursor show cursor
* @property {string} cursorChar character for cursor
* @property {boolean} autoInsertCss insert CSS for cursor and fadeOut into HTML <head>
*/
showCursor: true,
cursorChar: '|',
autoInsertCss: true,
/**
* @property {string} attr attribute for typing
* Ex: input placeholder, value, or just HTML text
*/
attr: null,
/**
* @property {boolean} bindInputFocusEvents bind to focus and blur if el is text input
*/
bindInputFocusEvents: false,
/**
* @property {string} contentType 'html' or 'null' for plaintext
*/
contentType: 'html',
/**
* All typing is complete
* @param {Typed} self
*/
onComplete: function onComplete(self) {},
/**
* Before each string is typed
* @param {number} arrayPos
* @param {Typed} self
*/
preStringTyped: function preStringTyped(arrayPos, self) {},
/**
* After each string is typed
* @param {number} arrayPos
* @param {Typed} self
*/
onStringTyped: function onStringTyped(arrayPos, self) {},
/**
* During looping, after last string is typed
* @param {Typed} self
*/
onLastStringBackspaced: function onLastStringBackspaced(self) {},
/**
* Typing has been stopped
* @param {number} arrayPos
* @param {Typed} self
*/
onTypingPaused: function onTypingPaused(arrayPos, self) {},
/**
* Typing has been started after being stopped
* @param {number} arrayPos
* @param {Typed} self
*/
onTypingResumed: function onTypingResumed(arrayPos, self) {},
/**
* After reset
* @param {Typed} self
*/
onReset: function onReset(self) {},
/**
* After stop
* @param {number} arrayPos
* @param {Typed} self
*/
onStop: function onStop(arrayPos, self) {},
/**
* After start
* @param {number} arrayPos
* @param {Typed} self
*/
onStart: function onStart(arrayPos, self) {},
/**
* After destroy
* @param {Typed} self
*/
onDestroy: function onDestroy(self) {}
};
exports['default'] = defaults;
module.exports = exports['default'];
/***/ }),
/* 3 */
/***/ (function(module, exports) {
/**
* TODO: These methods can probably be combined somehow
* Parse HTML tags & HTML Characters
*/
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var HTMLParser = (function () {
function HTMLParser() {
_classCallCheck(this, HTMLParser);
}
_createClass(HTMLParser, [{
key: 'typeHtmlChars',
/**
* Type HTML tags & HTML Characters
* @param {string} curString Current string
* @param {number} curStrPos Position in current string
* @param {Typed} self instance of Typed
* @returns {number} a new string position
* @private
*/
value: function typeHtmlChars(curString, curStrPos, self) {
if (self.contentType !== 'html') return curStrPos;
var curChar = curString.substr(curStrPos).charAt(0);
if (curChar === '<' || curChar === '&') {
var endTag = '';
if (curChar === '<') {
endTag = '>';
} else {
endTag = ';';
}
while (curString.substr(curStrPos + 1).charAt(0) !== endTag) {
curStrPos++;
if (curStrPos + 1 > curString.length) {
break;
}
}
curStrPos++;
}
return curStrPos;