From 65d8008370fd7da9e202d352e708338d57e3907e Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:33:01 -0700 Subject: [PATCH 01/19] made changes to add hot keys --- README.md | 11 +++++++++++ spritz.html | 2 ++ spritz.js | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb7bc20..572aacd 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,17 @@ 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](javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://miserlou.github.io/OpenSpritz/spritz.js?callback=cb?callback=cb'; script.onload=cb; document.body.appendChild(script);})();) + +[Bookmarklet](javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://raw.github.com/smorin/OpenSpritz/master/spritz.js; document.body.appendChild(script);})();) + +``` + OpenSpritz this! + +``` + ### Contributors * [Rich Jones](https://github.com/Miserlou) diff --git a/spritz.html b/spritz.html index 5d616c5..21fad0d 100644 --- a/spritz.html +++ b/spritz.html @@ -34,6 +34,8 @@ + + diff --git a/spritz.js b/spritz.js index 795ea66..053246b 100644 --- a/spritz.js +++ b/spritz.js @@ -11,12 +11,16 @@ 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/SteveMorin/OpenSpritz/master/spritz.html", function(data){ if (!($("#spritz_container").length) ) { $("body").prepend(data); } },'html'); + + $(document).bind('keydown', 'ctrl+a', alert("worked")); + }; load_jq(spritz_loader); @@ -35,6 +39,9 @@ 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://github.com/jeresig/jquery.hotkeys/raw/master/jquery.hotkeys.js"; script.onload = script.onreadystatechange = function(){ if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { done = true; @@ -42,6 +49,7 @@ function load_jq(spritz_loader){ } }; document.getElementsByTagName("head")[0].appendChild(script); + document.getElementsByTagName("head")[0].appendChild(script_keys); } else{ spritz_loader(); } From a65dc73b8ebbe551f9f54c05ca60366c0cd3324c Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:34:42 -0700 Subject: [PATCH 02/19] fix typo in script reference --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index 053246b..1d0fce2 100644 --- a/spritz.js +++ b/spritz.js @@ -12,7 +12,7 @@ function create_spritz(){ spritz_loader = function() { //$.get("https://rawgithub.com/Miserlou/OpenSpritz/master/spritz.html", function(data){ - $.get("https://rawgithub.com/SteveMorin/OpenSpritz/master/spritz.html", function(data){ + $.get("https://rawgithub.com/smorin/OpenSpritz/master/spritz.html", function(data){ if (!($("#spritz_container").length) ) { $("body").prepend(data); From 92fc6091b5cf9ca7d804354b047e5449c188d2c2 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:44:05 -0700 Subject: [PATCH 03/19] added bookmarket and fixed invalid reference --- bookmarklet.html | 5 +++++ spritz.html | 2 +- spritz.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 bookmarklet.html 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 21fad0d..a26c63c 100644 --- a/spritz.html +++ b/spritz.html @@ -35,7 +35,7 @@ - + diff --git a/spritz.js b/spritz.js index 1d0fce2..33af5d4 100644 --- a/spritz.js +++ b/spritz.js @@ -41,7 +41,7 @@ function load_jq(spritz_loader){ 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://github.com/jeresig/jquery.hotkeys/raw/master/jquery.hotkeys.js"; + 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; From 6ddf587d7164afa0544d9de3d66ebe6bc0c68d0e Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:45:11 -0700 Subject: [PATCH 04/19] changed bookmarklet reference to be to bookmarklet.html --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 572aacd..c4fb965 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,7 @@ Once you have tested your changes and confirmed they work, send a pull request. ## Bookmarklet -[Bookmarklet](javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://miserlou.github.io/OpenSpritz/spritz.js?callback=cb?callback=cb'; script.onload=cb; document.body.appendChild(script);})();) - -[Bookmarklet](javascript:(function(){ cb = function(){ create_spritz();}; var script=document.createElement('SCRIPT');script.src='https://raw.github.com/smorin/OpenSpritz/master/spritz.js; document.body.appendChild(script);})();) +[Bookmarklet](https://rawgithub.com/smorin/OpenSpritz/master/bookmarklet.html) ``` OpenSpritz this! From 0b1c59b775caaf809fcc242d9b4c34569b018354 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:48:46 -0700 Subject: [PATCH 05/19] fix javascript typo for assignment --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index 33af5d4..357f76b 100644 --- a/spritz.js +++ b/spritz.js @@ -41,7 +41,7 @@ function load_jq(spritz_loader){ 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_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; From 0c482a19889f5e2a74ad0384cb6d1cf2466a4499 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:53:08 -0700 Subject: [PATCH 06/19] added change to hot keys --- spritz.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spritz.js b/spritz.js index 357f76b..bbf8751 100644 --- a/spritz.js +++ b/spritz.js @@ -39,9 +39,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 + // https://github.com/tzuryby/jquery.hotkeys var script_keys = document.createElement("script"); - script_keys.src = "https://rawgithub.com/jeresig/jquery.hotkeys/master/jquery.hotkeys.js"; + script_keys.src = "https://rawgithub.com/tzuryby/jquery.hotkeys/blob/master/jquery.hotkeys.js"; + script.onload = script.onreadystatechange = function(){ if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { done = true; From aa36f4079095a95726ef9a159c14ff1212e6c18a Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:53:58 -0700 Subject: [PATCH 07/19] reference typo --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index bbf8751..927576f 100644 --- a/spritz.js +++ b/spritz.js @@ -41,7 +41,7 @@ function load_jq(spritz_loader){ script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js"; // https://github.com/tzuryby/jquery.hotkeys var script_keys = document.createElement("script"); - script_keys.src = "https://rawgithub.com/tzuryby/jquery.hotkeys/blob/master/jquery.hotkeys.js"; + script_keys.src = "https://rawgithub.com/tzuryby/jquery.hotkeys/master/jquery.hotkeys.js"; script.onload = script.onreadystatechange = function(){ if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) { From 5bfc1ddc05895fd1afa6a4fe1fa303d791bb4718 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:56:09 -0700 Subject: [PATCH 08/19] fixed the way I call key bindings --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index 927576f..c04ea2d 100644 --- a/spritz.js +++ b/spritz.js @@ -19,7 +19,7 @@ function create_spritz(){ } },'html'); - $(document).bind('keydown', 'ctrl+a', alert("worked")); + $(document).bind('keydown', 'ctrl+a', function() {alert("worked")}); }; From b428f973499badc39bd0f878f91a6e35df7d4607 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 11:59:51 -0700 Subject: [PATCH 09/19] changed back to jeresig implemtation --- spritz.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spritz.js b/spritz.js index c04ea2d..d45620a 100644 --- a/spritz.js +++ b/spritz.js @@ -39,9 +39,9 @@ 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/tzuryby/jquery.hotkeys + // https://github.com/jeresig/jquery.hotkeys var script_keys = document.createElement("script"); - script_keys.src = "https://rawgithub.com/tzuryby/jquery.hotkeys/master/jquery.hotkeys.js"; + 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")) { From f98b61a2d8af60aebbb79b57b1505a1179a83f70 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:04:09 -0700 Subject: [PATCH 10/19] changed back to test keypress --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index d45620a..a447bee 100644 --- a/spritz.js +++ b/spritz.js @@ -19,7 +19,7 @@ function create_spritz(){ } },'html'); - $(document).bind('keydown', 'ctrl+a', function() {alert("worked")}); + $(document).bind('keypress', 'ctrl+a', function() {alert("worked")}); }; From 9957d3becbdceaf827838c71e812adda0df89e7d Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:07:38 -0700 Subject: [PATCH 11/19] testing keypress --- spritz.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index a447bee..f38c8ff 100644 --- a/spritz.js +++ b/spritz.js @@ -19,7 +19,8 @@ function create_spritz(){ } },'html'); - $(document).bind('keypress', 'ctrl+a', function() {alert("worked")}); + //$(document).bind('keypress', 'ctrl+a', function() {alert("worked")}); + jQuery(document).bind('keypress', 'Shift+p',function (evt){alert('shift+p'); return false; }); }; From a4ad6773876bad2231381fcae833f4e44984a735 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:24:18 -0700 Subject: [PATCH 12/19] added new code --- spritz.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/spritz.js b/spritz.js index f38c8ff..e99407e 100644 --- a/spritz.js +++ b/spritz.js @@ -20,7 +20,8 @@ function create_spritz(){ },'html'); //$(document).bind('keypress', 'ctrl+a', function() {alert("worked")}); - jQuery(document).bind('keypress', 'Shift+p',function (evt){alert('shift+p'); return false; }); + // 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; }); }; @@ -81,8 +82,78 @@ function spritz(){ } } -// The meat! +spritz_words = [""]; +spritz_index = 1; +spritz_interval; + function spritzify(input){ + spritz_index = 1; + 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! + clearInterval(spritz_interval); + setInterval(function() { + if (spritz_index < spritz_words.length) { + 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; From 39018ed3f4c5a55f396baef1ac06bbabcbfca48d Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:25:54 -0700 Subject: [PATCH 13/19] added new code --- spritz.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.js b/spritz.js index e99407e..2828215 100644 --- a/spritz.js +++ b/spritz.js @@ -147,7 +147,7 @@ function spritzify_go(input){ clearInterval(spritz_interval); } - }; , ms_per_word); + } , ms_per_word); } } From 66537675aee82dada454c789828364edba8b9282 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:32:58 -0700 Subject: [PATCH 14/19] fix wrong bracket nesting --- spritz.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spritz.js b/spritz.js index 2828215..0f9366f 100644 --- a/spritz.js +++ b/spritz.js @@ -146,10 +146,9 @@ function spritzify_go(input){ } else { clearInterval(spritz_interval); } - } , ms_per_word); - } + } // The meat! From 2f380249ad069b33c186458a634090ac48326f32 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:45:49 -0700 Subject: [PATCH 15/19] changed checks on interval --- spritz.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spritz.js b/spritz.js index 0f9366f..47ccb00 100644 --- a/spritz.js +++ b/spritz.js @@ -84,7 +84,7 @@ function spritz(){ spritz_words = [""]; spritz_index = 1; -spritz_interval; +spritz_interval = undefined; function spritzify(input){ spritz_index = 1; @@ -137,8 +137,10 @@ function spritzify_go(input){ spritz_words = temp_words.slice(0); // Set the timers! - clearInterval(spritz_interval); - setInterval(function() { + if (! spritz_interval === undefined ) { + clearInterval(spritz_interval); + } + spritz_interval= setInterval(function() { if (spritz_index < spritz_words.length) { var p = pivot(spritz_words[spritz_index]); spritz_index = spritz_index + 1; From 3175833d2cec25458115ef13ea9bfdb26e46d250 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:50:39 -0700 Subject: [PATCH 16/19] added pause functionality --- spritz.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spritz.js b/spritz.js index 47ccb00..cb74637 100644 --- a/spritz.js +++ b/spritz.js @@ -85,6 +85,15 @@ function spritz(){ 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; @@ -142,9 +151,11 @@ function spritzify_go(input){ } 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); } From 8a77cf26102262807136478f87057c7e7ea5530f Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 12:59:50 -0700 Subject: [PATCH 17/19] added button change --- spritz.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spritz.html b/spritz.html index a26c63c..cced85e 100644 --- a/spritz.html +++ b/spritz.html @@ -35,7 +35,7 @@ - + From 00df2f438dbc967193674aad4414df238b8d96b3 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 13:32:42 -0700 Subject: [PATCH 18/19] fixed a bug where words longer than 22 words cause the script to fail permanently --- spritz.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spritz.js b/spritz.js index cb74637..3a569dd 100644 --- a/spritz.js +++ b/spritz.js @@ -263,6 +263,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); From 876a2cd589ffcbd7e711c07c21fe555790697025 Mon Sep 17 00:00:00 2001 From: Steve Morin Date: Sun, 9 Mar 2014 13:33:26 -0700 Subject: [PATCH 19/19] fixed a bug where words longer than 22 words cause the script to fail permanently --- spritz.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spritz.js b/spritz.js index 3a569dd..53da172 100644 --- a/spritz.js +++ b/spritz.js @@ -97,6 +97,7 @@ function spritz_pause_toggle() { function spritzify(input){ spritz_index = 1; + spritz_pause = false; spritzify_go(input); }