typed.js 2.0.7 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ export default class Initializer {
20
20
  self.el = elementId;
21
21
  }
22
22
 
23
- self.options = {...defaults, ...options};
23
+ self.options = { ...defaults, ...options };
24
24
 
25
25
  // attribute to type into
26
26
  self.isInput = self.el.tagName.toLowerCase() === 'input';
@@ -37,7 +37,9 @@ export default class Initializer {
37
37
  self.cursorBlinking = true;
38
38
 
39
39
  // text content of element
40
- self.elContent = self.attr ? self.el.getAttribute(self.attr) : self.el.textContent;
40
+ self.elContent = self.attr
41
+ ? self.el.getAttribute(self.attr)
42
+ : self.el.textContent;
41
43
 
42
44
  // html or plain text
43
45
  self.contentType = self.options.contentType;
@@ -113,7 +115,7 @@ export default class Initializer {
113
115
  typewrite: true,
114
116
  curString: '',
115
117
  curStrPos: 0
116
- }
118
+ };
117
119
 
118
120
  // When the typing is complete (when not looped)
119
121
  self.typingComplete = false;
@@ -146,11 +148,21 @@ export default class Initializer {
146
148
  }
147
149
 
148
150
  appendAnimationCss(self) {
149
- if (!self.autoInsertCss) { return; }
150
- if (!self.showCursor || !self.fadeOut) { return; }
151
+ const cssDataName = 'data-typed-js-css';
152
+ if (!self.autoInsertCss) {
153
+ return;
154
+ }
155
+ if (!self.showCursor && !self.fadeOut) {
156
+ return;
157
+ }
158
+ if (document.querySelector(`[${cssDataName}]`)) {
159
+ return;
160
+ }
151
161
 
152
162
  let css = document.createElement('style');
153
163
  css.type = 'text/css';
164
+ css.setAttribute(cssDataName, true);
165
+
154
166
  let innerCss = '';
155
167
  if (self.showCursor) {
156
168
  innerCss += `
@@ -184,7 +196,9 @@ export default class Initializer {
184
196
  }
185
197
  `;
186
198
  }
187
- if (css.length === 0) { return; }
199
+ if (css.length === 0) {
200
+ return;
201
+ }
188
202
  css.innerHTML = innerCss;
189
203
  document.body.appendChild(css);
190
204
  }
package/src/typed.js CHANGED
@@ -87,6 +87,7 @@ export default class Typed {
87
87
  * @private
88
88
  */
89
89
  begin() {
90
+ this.options.onBegin(this);
90
91
  this.typingComplete = false;
91
92
  this.shuffleStringsIfNeeded(this);
92
93
  this.insertCursor();
@@ -141,7 +142,9 @@ export default class Typed {
141
142
  this.temporaryPause = true;
142
143
  this.options.onTypingPaused(this.arrayPos, this);
143
144
  // strip out the escape character and pause value so they're not printed
144
- curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
145
+ curString =
146
+ curString.substring(0, curStrPos) +
147
+ curString.substring(curStrPos + skip);
145
148
  this.toggleBlinking(true);
146
149
  }
147
150
  }
@@ -155,7 +158,10 @@ export default class Typed {
155
158
  }
156
159
  // strip out the escape characters and append all the string in between
157
160
  const stringBeforeSkip = curString.substring(0, curStrPos);
158
- const stringSkipped = curString.substring(stringBeforeSkip.length + 1, curStrPos + numChars);
161
+ const stringSkipped = curString.substring(
162
+ stringBeforeSkip.length + 1,
163
+ curStrPos + numChars
164
+ );
159
165
  const stringAfterSkip = curString.substring(curStrPos + numChars + 1);
160
166
  curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
161
167
  numChars--;
@@ -167,7 +173,7 @@ export default class Typed {
167
173
  this.toggleBlinking(false);
168
174
 
169
175
  // We're done with this sentence!
170
- if (curStrPos === curString.length) {
176
+ if (curStrPos >= curString.length) {
171
177
  this.doneTyping(curString, curStrPos);
172
178
  } else {
173
179
  this.keepTyping(curString, curStrPos, numChars);
@@ -205,7 +211,7 @@ export default class Typed {
205
211
  }
206
212
 
207
213
  /**
208
- * We're done typing all strings
214
+ * We're done typing the current string
209
215
  * @param {string} curString the current string in the strings array
210
216
  * @param {number} curStrPos the current position in the curString
211
217
  * @private
@@ -254,7 +260,10 @@ export default class Typed {
254
260
  if (this.smartBackspace) {
255
261
  // the remaining part of the current string is equal of the same part of the new string
256
262
  let nextString = this.strings[this.arrayPos + 1];
257
- if (nextString && curStringAtPosition === nextString.substr(0, curStrPos)) {
263
+ if (
264
+ nextString &&
265
+ curStringAtPosition === nextString.substr(0, curStrPos)
266
+ ) {
258
267
  this.stopNum = curStrPos;
259
268
  } else {
260
269
  this.stopNum = 0;
@@ -336,7 +345,7 @@ export default class Typed {
336
345
  * @private
337
346
  */
338
347
  humanizer(speed) {
339
- return Math.round(Math.random() * speed / 2) + speed;
348
+ return Math.round((Math.random() * speed) / 2) + speed;
340
349
  }
341
350
 
342
351
  /**
@@ -400,7 +409,9 @@ export default class Typed {
400
409
  this.stop();
401
410
  });
402
411
  this.el.addEventListener('blur', (e) => {
403
- if (this.el.value && this.el.value.length !== 0) { return; }
412
+ if (this.el.value && this.el.value.length !== 0) {
413
+ return;
414
+ }
404
415
  this.start();
405
416
  });
406
417
  }
@@ -415,6 +426,7 @@ export default class Typed {
415
426
  this.cursor = document.createElement('span');
416
427
  this.cursor.className = 'typed-cursor';
417
428
  this.cursor.innerHTML = this.cursorChar;
418
- this.el.parentNode && this.el.parentNode.insertBefore(this.cursor, this.el.nextSibling);
429
+ this.el.parentNode &&
430
+ this.el.parentNode.insertBefore(this.cursor, this.el.nextSibling);
419
431
  }
420
432
  }
package/webpack.config.js CHANGED
@@ -41,7 +41,5 @@ export default {
41
41
  }
42
42
  ]
43
43
  },
44
- plugins: [
45
- new webpack.BannerPlugin(banner)
46
- ]
44
+ plugins: [new webpack.BannerPlugin(banner)]
47
45
  };