diff options
author | andi <andi@splitbrain.org> | 2005-06-14 19:40:04 +0200 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-06-14 19:40:04 +0200 |
commit | c66822c0a36e3dbb262ce249f99d04a64ce0476f (patch) | |
tree | a25cd416640629cd1d5c94ab357dfe955fa84042 /lib/scripts/spellcheck.js | |
parent | 21777a2bc74163743daaa35c93a1364e269d46c7 (diff) | |
download | dokuwiki-c66822c0a36e3dbb262ce249f99d04a64ce0476f.tar.gz dokuwiki-c66822c0a36e3dbb262ce249f99d04a64ce0476f.zip |
Spellchecker: use UTF-8 workaround only if needed
The spellchecker now tests the browsers UTF-8 compliance and only uses
the entitiy encoding if needed. This hopefully fixes problems with
Safari.
darcs-hash:20050614174004-9977f-9c64abc8c31c47e89ac01784eae81f766bc54af0.gz
Diffstat (limited to 'lib/scripts/spellcheck.js')
-rw-r--r-- | lib/scripts/spellcheck.js | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js index 3df9a25ff..9c33f12c8 100644 --- a/lib/scripts/spellcheck.js +++ b/lib/scripts/spellcheck.js @@ -124,6 +124,7 @@ function spellButton(imageFile, speedTip, funcCall, accessKey) { */ function ajax_spell_class(){ this.inited = false; + this.utf8ok = 1; this.handler = DOKU_BASE+'lib/exe/spellcheck.php'; // to hold the page objects (initialized with init()) this.textboxObj = null; @@ -153,7 +154,7 @@ function ajax_spell_class(){ this.inited = true; // check for AJAX availability - var ajax = new sack(); + var ajax = new sack(this.handler); if(ajax.failed) return; // get Elements @@ -171,13 +172,11 @@ function ajax_spell_class(){ this.txtNoSug = txtNoSug; this.txtChange= txtChange; - // register click event - document.onclick = this.docClick; - - // register focus event - this.textboxObj.onfocus = this.setState; - - this.setState('start'); + // start UTF-8 compliance test - send an UTF-8 char and see what comes back + ajax.AjaxFailedAlert = ''; + ajax.encodeURIString = false; + ajax.onCompletion = this.initReady; + ajax.runAJAX('call=utf8test&data='+encodeURIComponent('ü')); } /** @@ -298,6 +297,30 @@ function ajax_spell_class(){ // --- Callbacks --- /** + * Callback. Called after the object was initialized and UTF-8 tested + * Inside the callback 'this' is the SACK object!! + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + this.initReady = function(){ + var data = this.response; + + //test for UTF-8 compliance (will fail for konqueror) + if(data != 'ü'){ + ajax_spell.utf8ok = 0; + } + + // register click event + document.onclick = ajax_spell.docClick; + + // register focus event + ajax_spell.textboxObj.onfocus = ajax_spell.setState; + + // get started + ajax_spell.setState('start'); + } + + /** * Callback. Called after finishing spellcheck. * Inside the callback 'this' is the SACK object!! * @@ -309,11 +332,15 @@ function ajax_spell_class(){ data = data.substring(1); if(error == '1'){ ajax_spell.setState('stop'); - // convert numeric entities back to UTF-8 - data = data.replace(/&#(\d+);/g, - function(whole,match1) { - return String.fromCharCode(+match1); - }); + + // convert numeric entities back to UTF-8 if needed + if(!ajax_spell.utf8ok){ + data = data.replace(/&#(\d+);/g, + function(whole,match1) { + return String.fromCharCode(+match1); + }); + } + // replace textbox through div ajax_spell.showboxObj.innerHTML = data; ajax_spell.showboxObj.style.width = ajax_spell.textboxObj.style.width; @@ -340,15 +367,16 @@ function ajax_spell_class(){ this.stop = function(){ var data = this.response; - // convert numeric entities back to UTF-8 - data = data.replace(/&#(\d+);/g, + // convert numeric entities back to UTF-8 if needed + if(!ajax_spell.utf8ok){ + data = data.replace(/&#(\d+);/g, function(whole,match1) { return String.fromCharCode(+match1); - }); - // now remove & protection - data = data.replace(/&/g,'&'); + }); + // now remove & protection + data = data.replace(/&/g,'&'); + } - ajax_spell.setState('start'); // replace div with textbox again ajax_spell.textboxObj.value = data; ajax_spell.textboxObj.disabled = false; @@ -356,6 +384,7 @@ function ajax_spell_class(){ ajax_spell.textboxObj.style.display = 'block'; ajax_spell.editbarObj.style.visibility = 'visible'; ajax_spell.showboxObj.innerHTML = ''; + ajax_spell.setState('start'); } // --- Callers --- @@ -372,7 +401,8 @@ function ajax_spell_class(){ ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; ajax.onCompletion = this.start; - ajax.runAJAX('call=check&data='+encodeURIComponent(this.textboxObj.value)); + ajax.runAJAX('call=check&utf8='+ajax_spell.utf8ok+ + '&data='+encodeURIComponent(this.textboxObj.value)); } /** @@ -388,7 +418,8 @@ function ajax_spell_class(){ ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; ajax.onCompletion = this.stop; - ajax.runAJAX('call=resume&data='+encodeURIComponent(text)); + ajax.runAJAX('call=resume&utf8='+ajax_spell.utf8ok+ + '&data='+encodeURIComponent(text)); } } |