diff options
-rw-r--r-- | inc/aspell.php | 8 | ||||
-rw-r--r-- | lib/exe/ajax.php | 5 | ||||
-rw-r--r-- | lib/exe/spellcheck.php | 9 | ||||
-rw-r--r-- | lib/scripts/spellcheck.js | 19 | ||||
-rw-r--r-- | lib/scripts/tw-sack.js | 216 |
5 files changed, 159 insertions, 98 deletions
diff --git a/inc/aspell.php b/inc/aspell.php index ea8a7e428..9e83436a8 100644 --- a/inc/aspell.php +++ b/inc/aspell.php @@ -165,7 +165,7 @@ class Aspell{ ); $process = proc_open(ASPELL_BIN.' -a'.$this->args, $descspec, $pipes); - if (is_resource($process)) { + if ($process) { //write to stdin fwrite($pipes[0],$text); fclose($pipes[0]); @@ -184,13 +184,13 @@ class Aspell{ if(proc_close($process) != 0){ //something went wrong - trigger_error("aspell returned an error: $err", E_USER_WARNING); - return null; + $err = "Aspell returned an error: $err"; + return false; } return true; } //opening failed - trigger_error("Could not run aspell '".ASPELL_BIN."'", E_USER_WARNING); + $err = "Could not run Aspell '".ASPELL_BIN."'"; return false; } diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 02911b858..c75bce52d 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -17,12 +17,15 @@ require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/pageutils.php'); require_once(DOKU_INC.'inc/auth.php'); +header('Content-Type: text/html; charset=utf-8'); + + //call the requested function $call = 'ajax_'.$_POST['call']; if(function_exists($call)){ $call(); }else{ - print "The called function does not exist!"; + print "The called function '".htmlspecialchars($call)."' does not exist!"; } /** diff --git a/lib/exe/spellcheck.php b/lib/exe/spellcheck.php index c6a883e32..bdd6789d4 100644 --- a/lib/exe/spellcheck.php +++ b/lib/exe/spellcheck.php @@ -51,6 +51,8 @@ require_once (DOKU_INC.'inc/init.php'); require_once (DOKU_INC.'inc/utf8.php'); require_once (DOKU_INC.'inc/aspell.php'); +header('Content-Type: text/html; charset=utf-8'); + //create spell object $spell = new Aspell($conf['lang'],'null','utf-8'); $spell->setMode(PSPELL_FAST); @@ -84,7 +86,12 @@ function spell_check() { // $string = preg_replace('!()!e','spellclean(\\1)',$string); // run aspell in terse sgml mode - $spell->runAspell("!\n+sgml\n".$string,$out,$err); + if(!$spell->runAspell("!\n+sgml\n".$string,$out,$err)){ + print '2'; //to indicate an error + print "An error occured while trying to run the spellchecker:\n"; + print $err; + return; + } // go through the result $lines = split("\n",$out); diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js index 5b7833601..feeeb0967 100644 --- a/lib/scripts/spellcheck.js +++ b/lib/scripts/spellcheck.js @@ -206,6 +206,7 @@ function ajax_spell_class(){ this.suggestObj.style.display = "none"; } + // --- Callbacks --- /** @@ -228,6 +229,9 @@ function ajax_spell_class(){ ajax_spell.editbarObj.style.visibility = 'hidden'; ajax_spell.showboxObj.style.display = 'block'; }else{ + if(error == '2'){ + alert(data); + } ajax_spell.textboxObj.disabled = false; ajax_spell.editbarObj.style.visibility = 'visible'; ajax_spell.setState('noerr'); @@ -263,8 +267,9 @@ function ajax_spell_class(){ this.setState('run'); this.textboxObj.disabled = true; var ajax = new sack(this.handler); + ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; - ajax.onCompletion = this.start; + ajax.onCompletion = this.start; ajax.runAJAX('call=check&data='+encodeURIComponent(this.textboxObj.value)); } @@ -278,8 +283,9 @@ function ajax_spell_class(){ var text = this.showboxObj.innerHTML; if(text != ''){ var ajax = new sack(this.handler); + ajax.AjaxFailedAlert = ''; ajax.encodeURIString = false; - ajax.onCompletion = this.stop; + ajax.onCompletion = this.stop; ajax.runAJAX('call=resume&data='+encodeURIComponent(text)); } } @@ -299,7 +305,14 @@ function ajax_spell_class(){ this.suggestObj.style.display = "none"; var x = findPosX('spell_error'+id); var y = findPosY('spell_error'+id); - var scrollPos = this.showboxObj.scrollTop; + + // handle scrolling + if(is_opera){ + var scrollPos = 0; //FIXME how to do this without browser sniffing? + }else{ + var scrollPos = this.showboxObj.scrollTop; + } + this.suggestObj.style.left = x+'px'; this.suggestObj.style.top = (y+16-scrollPos)+'px'; diff --git a/lib/scripts/tw-sack.js b/lib/scripts/tw-sack.js index 18b63730a..f9b8f247f 100644 --- a/lib/scripts/tw-sack.js +++ b/lib/scripts/tw-sack.js @@ -1,95 +1,133 @@ -// ====== Simple Ajax Code Kit ======= -// code by Gregory Wild-Smith (c)2005 -// http://twilightuniverse.com -// If you use this code please keep this credit intact. -// A link or email would be nice, but is not required. -// v1.01 +/* Simple AJAX Code-Kit (SACK) */ +/* ©2005 Gregory Wild-Smith */ +/* www.twilightuniverse.com */ +/* Software licenced under a modified X11 licence, see documentation or authors website for more details */ function sack(file){ - this.AjaxFailedAlert = "Your browser doesn't support the extended functionality of this website, and therefore you have have an experience that differs from the intended one.\n"; - this.requestFile = file; - this.method = "POST"; - this.URLString = ""; - this.encodeURIString = true; - this.execute = false; + this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n"; + this.requestFile = file; + this.method = "POST"; + this.URLString = ""; + this.encodeURIString = true; + this.execute = false; - this.onLoading = function() { }; - this.onLoaded = function() { }; - this.onInteractive = function() { }; - this.onCompletion = function() { }; - - this.createAJAX = function() { - try { - this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e) { - try { - this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (oc) { - this.xmlhttp = null; - } - } - if(!this.xmlhttp && typeof XMLHttpRequest != "undefined") - this.xmlhttp = new XMLHttpRequest(); - if (!this.xmlhttp){ - // no XMLHttpRequest support, so no AJAX. - this.failed = true; - } - }; + this.onLoading = function() { }; + this.onLoaded = function() { }; + this.onInteractive = function() { }; + this.onCompletion = function() { }; - this.encodeURLString = function(string){ - varArray = string.split('&'); - for (i = 0; i < varArray.length; i++){ - urlVars = varArray[i].split('='); - if (urlVars[0].indexOf('amp;') != -1){ - urlVars[0] = urlVars[0].substring(4); - } - urlVars[0] = encodeURIComponent(urlVars[0]); - urlVars[1] = encodeURIComponent(urlVars[1]); - varArray[i] = urlVars.join("="); - } - return varArray.join('&'); - } - - this.runResponse = function(){ - eval(this.response); - } - - this.runAJAX = function(urlstring){ - if (urlstring){ this.URLString = urlstring; } - if (this.element) { this.elementObj = document.getElementById(this.element); } - if (this.xmlhttp) { - var self = this; // wierd fix for odd behavior where "this" wouldn't work in the readystate function. - this.xmlhttp.open(this.method, this.requestFile ,true); - if (this.method == "POST" && this.xmlhttp.setRequestHeader) { - this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') - } - if (this.encodeURIString){ this.URLString = this.encodeURLString(this.URLString); } - this.xmlhttp.send(this.URLString); - this.xmlhttp.onreadystatechange = function() { - switch (self.xmlhttp.readyState){ - case 1: // Loading. - self.onLoading(); - break; - case 2: // Loaded. - self.onLoaded(); - break; - case 3: // Interactive - is called every 4096 bytes.. pretty much just tells you it's downloading data. - self.onInteractive(); - break; - case 4: // Completed. - self.response = self.xmlhttp.responseText; - self.responseXML = self.xmlhttp.responseXML; - self.onCompletion(); - if(self.execute){ self.runResponse(); } - if (self.elementObj) { - self.elementObj.innerHTML = self.response; - } - break; - } - }; - } - }; + this.createAJAX = function() { + try { + this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (err) { + this.xmlhttp = null; + } + } + if(!this.xmlhttp && typeof XMLHttpRequest != "undefined") + this.xmlhttp = new XMLHttpRequest(); + if (!this.xmlhttp){ + this.failed = true; + } + }; + + this.setVar = function(name, value){ + if (this.URLString.length < 3){ + this.URLString = name + "=" + value; + } else { + this.URLString += "&" + name + "=" + value; + } + } + + this.encVar = function(name, value){ + var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value); + return varString; + } + + this.encodeURLString = function(string){ + varArray = string.split('&'); + for (i = 0; i < varArray.length; i++){ + urlVars = varArray[i].split('='); + if (urlVars[0].indexOf('amp;') != -1){ + urlVars[0] = urlVars[0].substring(4); + } + varArray[i] = this.encVar(urlVars[0],urlVars[1]); + } + return varArray.join('&'); + } + + this.runResponse = function(){ + eval(this.response); + } + + this.runAJAX = function(urlstring){ + this.responseStatus = new Array(2); + if(this.failed && this.AjaxFailedAlert){ + alert(this.AjaxFailedAlert); + } else { + if (urlstring){ + if (this.URLString.length){ + this.URLString = this.URLString + "&" + urlstring; + } else { + this.URLString = urlstring; + } + } + if (this.encodeURIString){ + var timeval = new Date().getTime(); + this.URLString = this.encodeURLString(this.URLString); + this.setVar("rndval", timeval); + } + if (this.element) { this.elementObj = document.getElementById(this.element); } + if (this.xmlhttp) { + var self = this; + if (this.method == "GET") { + var totalurlstring = this.requestFile + "?" + this.URLString; + this.xmlhttp.open(this.method, totalurlstring, true); + } else { + this.xmlhttp.open(this.method, this.requestFile, true); + } + if (this.method == "POST"){ + try { + this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded') + } catch (e) {} + } + + this.xmlhttp.send(this.URLString); + this.xmlhttp.onreadystatechange = function() { + switch (self.xmlhttp.readyState){ + case 1: + self.onLoading(); + break; + case 2: + self.onLoaded(); + break; + case 3: + self.onInteractive(); + break; + case 4: + self.response = self.xmlhttp.responseText; + self.responseXML = self.xmlhttp.responseXML; + self.responseStatus[0] = self.xmlhttp.status; + self.responseStatus[1] = self.xmlhttp.statusText; + self.onCompletion(); + if(self.execute){ self.runResponse(); } + if (self.elementObj) { + var elemNodeName = self.elementObj.nodeName; + elemNodeName.toLowerCase(); + if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){ + self.elementObj.value = self.response; + } else { + self.elementObj.innerHTML = self.response; + } + } + self.URLString = ""; + break; + } + }; + } + } + }; this.createAJAX(); -//if(this.failed && this.AjaxFailedAlert){ alert(this.AjaxFailedAlert); } } -//Setup VIM: ex: et ts=2 enc=utf-8 : |