diff --git a/src/handlers/audio_synth_handler.rs b/src/handlers/audio_synth_handler.rs index f364c0dafe..47c3d30824 100644 --- a/src/handlers/audio_synth_handler.rs +++ b/src/handlers/audio_synth_handler.rs @@ -94,12 +94,16 @@ impl AudioSynthHandler { // TODO: Return errors. /// Create audio from the sentence. fn create_audio(&self, sentence: &str) -> Vec { - let words = split_sentence(sentence); + let mut words = split_sentence(sentence); if words.len() == 0 { // TODO: Raise error! } + // This file adds extra silent padding at both ends. + words.insert(0, "_blank".to_string()); + words.push("_blank".to_string()); + // Note: Keeping a list of buffered file readers is stupid and is simply // being done for this example. I'll create a multithreaded shared LRU cache // that reads from the disk and uses the dictionary word as the lookup key. diff --git a/src/handlers/vocab_list_handler.rs b/src/handlers/vocab_list_handler.rs index 0b31f383b5..a15c10c964 100644 --- a/src/handlers/vocab_list_handler.rs +++ b/src/handlers/vocab_list_handler.rs @@ -56,6 +56,8 @@ impl VocabListHandler { Err(_) => { continue; }, Ok(s) => { let word = s.replace(".wav", ""); + if (word.starts_with("_")) { continue; } + if (word.ends_with("_")) { continue; } words.push(word); } } diff --git a/src/web/css/style.css b/src/web/css/style.css index 8a533425a6..cb29d02a17 100644 --- a/src/web/css/style.css +++ b/src/web/css/style.css @@ -58,3 +58,9 @@ button { padding: 5px; border: 1px; } + +#stats { + margin: 20px 0; + font-size: 0.8em; + color #777; +} diff --git a/src/web/js/dictionary.js b/src/web/js/dictionary.js index 74c8e493c8..aeabe704ba 100644 --- a/src/web/js/dictionary.js +++ b/src/web/js/dictionary.js @@ -8,16 +8,22 @@ words: [], /** Load the word list from the server. */ - load: function() { + load: function(successCallback, failureCallback) { var that = this; $.get('/words') .done(function(data) { console.log('success', data); that.words = data.words; + if (typeof successCallback !== 'undefined') { + successCallback(that); + } }) .fail(function() { // Page has catastrophically failed. Suggest reload. console.error('failure'); + if (typeof successCallback !== 'undefined') { + failureCallback(that); + } }); }, diff --git a/src/web/js/script.js b/src/web/js/script.js index 8e44ea163f..7d06ac5c6e 100644 --- a/src/web/js/script.js +++ b/src/web/js/script.js @@ -12,6 +12,12 @@ var handleTyping = function(ev) { var sentence = $(this).val(), suggestedWords = []; + + if (ev.keyCode === 27) { + $(this).val(''); // ESC key. + sentence = ''; + } + if (Dictionary.checkSentence(sentence)) { setState('ok'); } else { @@ -22,6 +28,14 @@ uiSetSuggestedWords(suggestedWords); } + /** Handle typing outside of the input box. */ + var handleBodyTyping = function(ev) { + if (ev.keyCode === 27) { + // Handle ESC key. + $('input').select(); + } + } + /** Handle form submission. */ var formSubmit = function(ev) { var $audio = $('#sound'), @@ -69,6 +83,10 @@ $('ul').html(html); } + var uiDictionaryLoadCallback = function(dictionary) { + $('#wordcount').html(dictionary.words.length); + } + // TODO: Temp for debug. window.setState = setState; @@ -78,7 +96,8 @@ //$('input').on('keypress', handleTyping); //$('input').on('keydown', handleTyping); $('input').on('keyup', handleTyping); - Dictionary.load(); + $('body').on('keyup', handleBodyTyping); + Dictionary.load(uiDictionaryLoadCallback); } $(function() { diff --git a/web/index.html b/web/index.html index a440c8c4c1..f111d0329a 100644 --- a/web/index.html +++ b/web/index.html @@ -1,7 +1,7 @@ - Title + Jungle Horse @@ -17,6 +17,9 @@ +
+ Currently featuring 0 words. +