* 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
(curString, curStrPos)
| 133 | * @private |
| 134 | */ |
| 135 | typewrite(curString, curStrPos) { |
| 136 | if (this.fadeOut && this.el.classList.contains(this.fadeOutClass)) { |
| 137 | this.el.classList.remove(this.fadeOutClass); |
| 138 | if (this.cursor) this.cursor.classList.remove(this.fadeOutClass); |
| 139 | } |
| 140 | |
| 141 | const humanize = this.humanizer(this.typeSpeed); |
| 142 | let numChars = 1; |
| 143 | |
| 144 | if (this.pause.status === true) { |
| 145 | this.setPauseStatus(curString, curStrPos, true); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | // contain typing function in a timeout humanize'd delay |
| 150 | this.timeout = setTimeout(() => { |
| 151 | // skip over any HTML chars |
| 152 | curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this); |
| 153 | |
| 154 | let pauseTime = 0; |
| 155 | let substr = curString.substring(curStrPos); |
| 156 | // check for an escape character before a pause value |
| 157 | // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^ |
| 158 | // single ^ are removed from string |
| 159 | if (substr.charAt(0) === '^') { |
| 160 | if (/^\^\d+/.test(substr)) { |
| 161 | let skip = 1; // skip at least 1 |
| 162 | substr = /\d+/.exec(substr)[0]; |
| 163 | skip += substr.length; |
| 164 | pauseTime = parseInt(substr); |
| 165 | this.temporaryPause = true; |
| 166 | this.options.onTypingPaused(this.arrayPos, this); |
| 167 | // strip out the escape character and pause value so they're not printed |
| 168 | curString = |
| 169 | curString.substring(0, curStrPos) + |
| 170 | curString.substring(curStrPos + skip); |
| 171 | this.toggleBlinking(true); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // check for skip characters formatted as |
| 176 | // "this is a `string to print NOW` ..." |
| 177 | if (substr.charAt(0) === '`') { |
| 178 | while (curString.substring(curStrPos + numChars).charAt(0) !== '`') { |
| 179 | numChars++; |
| 180 | if (curStrPos + numChars > curString.length) break; |
| 181 | } |
| 182 | // strip out the escape characters and append all the string in between |
| 183 | const stringBeforeSkip = curString.substring(0, curStrPos); |
| 184 | const stringSkipped = curString.substring( |
| 185 | stringBeforeSkip.length + 1, |
| 186 | curStrPos + numChars |
| 187 | ); |
| 188 | const stringAfterSkip = curString.substring(curStrPos + numChars + 1); |
| 189 | curString = stringBeforeSkip + stringSkipped + stringAfterSkip; |
| 190 | numChars--; |
| 191 | } |
| 192 |
no test coverage detected