diff --git a/README.md b/README.md
index bb7bc20..c4fb965 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,15 @@ OpenSpritz currently needs a little more love to make it work with JSONP and nee
Once you have tested your changes and confirmed they work, send a pull request. Add yourself to the list of contributors below as well!
+## Bookmarklet
+
+[Bookmarklet](https://rawgithub.com/smorin/OpenSpritz/master/bookmarklet.html)
+
+```
+ OpenSpritz this!
+
+```
+
### Contributors
* [Rich Jones](https://github.com/Miserlou)
diff --git a/bookmarklet.html b/bookmarklet.html
new file mode 100644
index 0000000..6cbda20
--- /dev/null
+++ b/bookmarklet.html
@@ -0,0 +1,5 @@
+
+
OpenSpritz
+ OpenSpritz this!
+
+
\ No newline at end of file
diff --git a/spritz.html b/spritz.html
index 5d616c5..cced85e 100644
--- a/spritz.html
+++ b/spritz.html
@@ -34,6 +34,8 @@
900wpm
950wpm
+
+ Toggle Pause
diff --git a/spritz.js b/spritz.js
index 795ea66..53da172 100644
--- a/spritz.js
+++ b/spritz.js
@@ -11,12 +11,18 @@ function create_spritz(){
spritz_loader = function() {
- $.get("https://rawgithub.com/Miserlou/OpenSpritz/master/spritz.html", function(data){
+ //$.get("https://rawgithub.com/Miserlou/OpenSpritz/master/spritz.html", function(data){
+ $.get("https://rawgithub.com/smorin/OpenSpritz/master/spritz.html", function(data){
if (!($("#spritz_container").length) ) {
$("body").prepend(data);
}
},'html');
+
+ //$(document).bind('keypress', 'ctrl+a', function() {alert("worked")});
+ // Hot keys throws an error and seems to bind to every ket instead of just shift
+ //jQuery(document).bind('keypress', 'Shift+p',function (evt){alert('shift+p'); return false; });
+
};
load_jq(spritz_loader);
@@ -35,6 +41,10 @@ function load_jq(spritz_loader){
var done = false;
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
+ // https://github.com/jeresig/jquery.hotkeys
+ var script_keys = document.createElement("script");
+ script_keys.src = "https://rawgithub.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js";
+
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
@@ -42,6 +52,7 @@ function load_jq(spritz_loader){
}
};
document.getElementsByTagName("head")[0].appendChild(script);
+ document.getElementsByTagName("head")[0].appendChild(script_keys);
} else{
spritz_loader();
}
@@ -71,8 +82,91 @@ function spritz(){
}
}
-// The meat!
+spritz_words = [""];
+spritz_index = 1;
+spritz_interval = undefined;
+spritz_pause = false;
+
+function spritz_pause_toggle() {
+ if (spritz_pause == true) {
+ spritz_pause = false;
+ } else {
+ spritz_pause = true;
+ }
+}
+
function spritzify(input){
+ spritz_index = 1;
+ spritz_pause = false;
+ spritzify_go(input);
+}
+
+function spritzify_go(input){
+
+ var wpm = parseInt($("#spritz_selector").val(), 10);
+ var ms_per_word = 60000/wpm;
+
+ // Split on any spaces.
+ spritz_words = input.split(/\s+/);
+
+ var word = '';
+ var result = '';
+
+
+ // Preprocess words
+ var temp_words = spritz_words.slice(0); // copy Array
+ var t = 0;
+
+ for (var i=0; i 8) && spritz_words[i].indexOf('.') == -1){
+ temp_words.splice(t+1, 0, spritz_words[i]);
+ temp_words.splice(t+1, 0, spritz_words[i]);
+ t++;
+ t++;
+ }
+
+ // Add an additional space after punctuation.
+ if(spritz_words[i].indexOf('.') != -1 || spritz_words[i].indexOf('!') != -1 || spritz_words[i].indexOf('?') != -1 || spritz_words[i].indexOf(':') != -1 || spritz_words[i].indexOf(';') != -1|| spritz_words[i].indexOf(')') != -1){
+ temp_words.splice(t+1, 0, ".");
+ temp_words.splice(t+1, 0, ".");
+ temp_words.splice(t+1, 0, ".");
+ t++;
+ t++;
+ t++;
+ }
+
+ t++;
+
+ }
+ spritz_words = temp_words.slice(0);
+
+ // Set the timers!
+ if (! spritz_interval === undefined ) {
+ clearInterval(spritz_interval);
+ }
+ spritz_interval= setInterval(function() {
+ if (spritz_index < spritz_words.length) {
+ if (! spritz_pause) {
+ var p = pivot(spritz_words[spritz_index]);
+ spritz_index = spritz_index + 1;
+ $('#spritz_result').html(p);
+ }
+ } else {
+ clearInterval(spritz_interval);
+ }
+ } , ms_per_word);
+
+
+}
+
+// The meat!
+function spritzify_orig(input){
var wpm = parseInt($("#spritz_selector").val(), 10);
var ms_per_word = 60000/wpm;
@@ -170,6 +264,9 @@ function pivot(word){
else{
var tail = 22 - (word.length + 7);
+ if( tail < 0) {
+ tail = 0;
+ }
word = '.......' + word + ('.'.repeat(tail));
var start = word.slice(0, word.length/2);