diff options
-rw-r--r-- | lib/scripts/spellcheck.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js index 2af56642f..e00512010 100644 --- a/lib/scripts/spellcheck.js +++ b/lib/scripts/spellcheck.js @@ -96,6 +96,7 @@ function ajax_spell_class(){ this.txtNoSug = 'No Suggestions'; this.txtChange= 'Change'; + this.timer = null; /** * Initializes everything @@ -304,6 +305,14 @@ function ajax_spell_class(){ * @author Andreas Gohr <andi@splitbrain.org> */ this.start = function(){ + if(ajax_spell.timer !== null){ + window.clearTimeout(ajax_spell.timer); + ajax_spell.timer = null; + }else{ + // there is no timer set, we timed out already + return; + } + var data = this.response; var error = data.charAt(0); data = data.substring(1); @@ -363,6 +372,27 @@ function ajax_spell_class(){ ajax_spell.setState('start'); }; + /** + * Calback for the timeout handling + * + * Will be called when the aspell backend didn't return + */ + this.timedOut = function(){ + if(ajax_spell.timer !== null){ + window.clearTimeout(ajax_spell.timer); + ajax_spell.timer = null; + + ajax_spell.textboxObj.disabled = false; + ajax_spell.showboxObj.style.display = 'none'; + ajax_spell.textboxObj.style.display = 'block'; + ajax_spell.editbarObj.style.visibility = 'visible'; + ajax_spell.showboxObj.innerHTML = ''; + ajax_spell.setState('start'); + + window.alert('Error: The spell checker did not respond'); + } + }; + // --- Callers --- /** @@ -380,6 +410,9 @@ function ajax_spell_class(){ ajax.onCompletion = this.start; ajax.runAJAX('call=check&utf8='+ajax_spell.utf8ok+ '&data='+encodeURIComponent(ajax_spell.textboxObj.value)); + + // abort after 13 seconds + this.timer = window.setTimeout(ajax_spell.timedOut,13000); }; /** |