Skip to content

Commit

Permalink
Updated the commands syntax.
Browse files Browse the repository at this point in the history
Remove and pause commands no longer require a space character
afterwards.
  • Loading branch information
stvwhtly committed May 30, 2015
1 parent d2dd54f commit 146f55a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ Deleting characters `~`

It is possible to delete a defined number of characters then proceed with the rest of the text output.

Use `~x ` within the text string, where x is an integer value defining the characters to backspace, followed by a space.
Use `~x` within the text string, where x is an integer value defining the characters to backspace.

Example, type "auti", delete 1 character and continue to type "o", resulting in the word "auto":

```
auti~1 o^`
auti~1o^`
```

Pause / Delay `^`
---

Delay typing the next character using `^x ` where x in an integer value of milliseconds to pause.
Delay typing the next character using `^x` where x in an integer value of milliseconds to pause.

To pause for 2 seconds after typing the word "pause" before continuing to type:

Expand Down
16 changes: 10 additions & 6 deletions jquery.teletype.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Teletype jQuery Plugin
* @version 0.1.4
* @version 0.1.5
*
* @author Steve Whiteley
* @see http://teletype.rocks
Expand Down Expand Up @@ -45,12 +45,16 @@
}
}
var letters = current.string.split( '' ),
letter = letters[current.position];
letter = letters[current.position],
start = current.position + 1;
if ( letter == '^' || letter == '~' ) {
var end = current.string.substr( current.position + 1 ).indexOf( ' ' );
var value = current.string.substr( current.position + 1, end );
var end = current.string.substr( start ).search( /[^0-9]/ );
if ( end == -1 ) {
end = current.string.length;
}
var value = current.string.substr( start, end );
if ( $.isNumeric( value ) ) {
current.string = current.string.replace( letter + value + ' ', '' );
current.string = current.string.replace( letter + value, '' );
if ( letter == '^' ) {
window.setTimeout( function() {
window.setTimeout( type, delay( settings.typeDelay ) );
Expand All @@ -65,7 +69,7 @@
return;
}
} else if ( letter == '\\' ) {
var nextChar = current.string.substr( current.position + 1, 1 );
var nextChar = current.string.substr( start, 1 );
if ( nextChar == 'n' ) {
current.position++;
letter = '<br />';
Expand Down
2 changes: 1 addition & 1 deletion jquery.teletype.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 146f55a

@joe312213
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great plugin.

I tweaked it to add an 'end' callback, for when all typing completes (providing, not infinitely looping). Handy for resetting markup after animation.

here's the patch:


--- teletype.js Wed Jul 8 04:39:51 2015
+++ teletype_.js Wed Jul 8 03:54:26 2015
@@ -91,6 +91,10 @@
window.setTimeout( function() {
window.setTimeout( type, delay( settings.typeDelay ) );
}, settings.delay );

  •           }else{
    
  •                   if ( typeof( settings.callbackEnd ) == 'function' ) {
    
  •                       settings.callbackEnd( letter, current, object );
    
  •                   }  
            }
        }
        if ( typeof( settings.callbackType ) == 'function' ) {
    
    @@ -154,6 +158,7 @@
    loop: 0,
    humanise: true,
    callbackNext: null,
    callbackType: null,
  •   callbackEnd: null,
    
    };
    }( jQuery ) );

Please sign in to comment.