Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mattboldt committed Jul 15, 2017
2 parents 86b0f82 + 44ea7e1 commit 0247813
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 35 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ var typed = new Typed(".element", {
});
~~~

### Bulk Typing

The following example would emulate how a terminal acts when typing a command and seeing its result.

~~~ javascript
var typed = new Typed(".element", {
strings: [
"git push --force ^1000\n `pushed to origin with option force`"
]
});
~~~

### CSS

CSS animations are build upon initialzation in JavaScript. But, you can customize them at your will! These classes are:
Expand Down
11 changes: 9 additions & 2 deletions assets/demos.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
document.addEventListener('DOMContentLoaded', function() {
var typed = new Typed("#typed", {
var typed = new Typed('#typed', {
stringsElement: '#typed-strings',
typeSpeed: 20,
backSpeed: 20,
startDelay: 1000,
loop: false,
loopCount: Infinity,
onComplete: function(self) { prettyLog('onCmplete ' + self) },
onComplete: function(self) { prettyLog('onComplete ' + self) },
preStringTyped: function(pos, self) { prettyLog('preStringTyped ' + pos + ' ' + self); },
onStringTyped: function(pos, self) { prettyLog('onStringTyped ' + pos + ' ' + self) },
onLastStringBackspaced: function(self) { prettyLog('onLastStringBackspaced ' + self) },
Expand Down Expand Up @@ -74,6 +74,13 @@ document.addEventListener('DOMContentLoaded', function() {
smartBackspace: false,
loop: true
});

new Typed('#typed6', {
strings: ['npm install^1000\n`installing components...` ^1000\n`Fetching from source...`'],
typeSpeed: 40,
backSpeed: 0,
loop: true
});
});

function prettyLog(str) {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed.js",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://github.com/mattboldt/typed.js",
"authors": [
"Matt Boldt <me@mattboldt.com>"
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ gulp.task('html-docs', () => {
return gulp.src('./src/*.js')
.pipe(gulpDocumentation('html'), {}, {
name: 'Typed.js Docs',
version: '2.0.2'
version: '2.0.3'
})
.pipe(gulp.dest('docs'));
});
Expand Down
43 changes: 29 additions & 14 deletions lib/typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* typed.js - A JavaScript Typing Animation Library
* Author: Matt Boldt <me@mattboldt.com>
* Version: v2.0.1
* Version: v2.0.3
* Url: https://github.com/mattboldt/typed.js
* License(s): MIT
*
Expand Down Expand Up @@ -215,6 +215,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

var humanize = this.humanizer(this.typeSpeed);
var numChars = 1;

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

// 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
var pauseTime = 0;
var substr = curString.substr(curStrPos);
if (substr.charAt(0) === '^') {
var skip = 1; // skip atleast 1
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);
}
_this2.toggleBlinking(true);

// strip out the escape character and pause value so they're not printed
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
}

curStrPos = _htmlParserJs.htmlParser.typeHtmlChars(curString, curStrPos, _this2);
// 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 () {
Expand All @@ -254,7 +270,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (curStrPos === curString.length) {
_this2.doneTyping(curString, curStrPos);
} else {
_this2.keepTyping(curString, curStrPos);
_this2.keepTyping(curString, curStrPos, numChars);
}
// end of character pause
if (_this2.temporaryPause) {
Expand All @@ -275,18 +291,17 @@ return /******/ (function(modules) { // webpackBootstrap
*/
}, {
key: 'keepTyping',
value: function keepTyping(curString, curStrPos) {
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
var nextString = curString.substr(0, curStrPos + 1);
curStrPos += numChars;
var nextString = curString.substr(0, curStrPos);
this.replaceText(nextString);
// add characters one by one
curStrPos++;
// loop the function
this.typewrite(curString, curStrPos);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/typed.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/typed.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed.js",
"version": "2.0.2",
"version": "2.0.3",
"homepage": "https://github.com/mattboldt/typed.js",
"repository": "https://github.com/mattboldt/typed.js",
"license": "MIT",
Expand Down
41 changes: 28 additions & 13 deletions src/typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class Typed {
}

const humanize = this.humanizer(this.typeSpeed);
let numChars = 1;

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

// contain typing function in a timeout humanize'd delay
this.timeout = setTimeout(() => {
// skip over any HTML chars
curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);

let pauseTime = 0;
let 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
let pauseTime = 0;
let substr = curString.substr(curStrPos);
if (substr.charAt(0) === '^') {
let skip = 1; // skip atleast 1
if (/^\^\d+/.test(substr)) {
let skip = 1; // skip at least 1
substr = /\d+/.exec(substr)[0];
skip += substr.length;
pauseTime = parseInt(substr);
this.temporaryPause = true;
this.options.onTypingPaused(this.arrayPos, this);
// strip out the escape character and pause value so they're not printed
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
this.toggleBlinking(true);
}
this.toggleBlinking(true);

// strip out the escape character and pause value so they're not printed
curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
}

curStrPos = htmlParser.typeHtmlChars(curString, curStrPos, this);
// 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
const stringBeforeSkip = curString.substring(0, curStrPos);
const stringSkipped = curString.substring(stringBeforeSkip.length + 1, curStrPos + numChars);
const stringAfterSkip = curString.substring(curStrPos + numChars + 1);
curString = stringBeforeSkip + stringSkipped + stringAfterSkip;
numChars--;
}

// timeout for any pause after a character
this.timeout = setTimeout(() => {
Expand All @@ -154,7 +170,7 @@ export default class Typed {
if (curStrPos === curString.length) {
this.doneTyping(curString, curStrPos);
} else {
this.keepTyping(curString, curStrPos);
this.keepTyping(curString, curStrPos, numChars);
}
// end of character pause
if (this.temporaryPause) {
Expand All @@ -173,18 +189,17 @@ export default class Typed {
* @param {number} curStrPos the current position in the curString
* @private
*/
keepTyping(curString, curStrPos) {
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
const nextString = curString.substr(0, curStrPos + 1);
curStrPos += numChars;
const nextString = curString.substr(0, curStrPos);
this.replaceText(nextString);
// add characters one by one
curStrPos++;
// loop the function
this.typewrite(curString, curStrPos);
}
Expand Down

0 comments on commit 0247813

Please sign in to comment.