diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-06-20 22:56:16 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-06-20 22:56:16 +0200 |
commit | 54d2f94854875c481eb511d09004175a29c7ef4d (patch) | |
tree | 718d897c2c7cb746a01098bbec92084070712617 | |
parent | e441516e371183d6f99ebd4738e7bf76052457b0 (diff) | |
download | rpg-54d2f94854875c481eb511d09004175a29c7ef4d.tar.gz rpg-54d2f94854875c481eb511d09004175a29c7ef4d.tar.bz2 |
timeout for spell checker
This adds a timeout of 13 seconds to the spell checker. This doesn't
fix anything but ensures editing can be continued on a backend problem.
darcs-hash:20060620205616-7ad00-1d3440a8c9246843a1efbb6e16116ff462074943.gz
-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); }; /** |