You are not logged in.
Pages: 1
Hello,
I've noticed a problem with the spell check function in Xinha. An example can be seen here:
http://nt.bupipedream.com/pipeline/spellertest.html
If you click the spell check button without typing anything in the editor, the spell checker window pops up with the following message:
};"Language Used":"en_GB","Mispelled words":"","Total words suggested":"","Total Lines Checked":""};
Warning: Invalid argument supplied for foreach() in /var/www/xinha/plugins/SpellChecker/spell-check-logic.php on line 147
If, however, you type some stuff into the editor prior to starting the spell check, it works fine.
Any ideas?
Many thanks,
Martin
Offline
There is problems with the logic here, it assumes that there should be some words during the process. If you look at line 135 of the logic.php file you find the ending bracket, followed by more values of "$infolines", problem is the $infolines is started inside the brackets, and the brackets contain code which executes if trim($text) - meaning we get an error when text is missing. Quick fix however.
From line 135 - 142
}
$infolines .= '"Language Used":"'.$lang.'",';
$infolines .= '"Mispelled words":"'.$counter.'",';
$infolines .= '"Total words suggested":"'.$suggest_count.'",';
$infolines .= '"Total Lines Checked":"'.$returnlines.'"';
$infolines .= '};';
$varlines = substr($varlines, 0, strlen($varlines) - 1);
echo $varlines.'};'.$infolines.'</script>';
We move the bracket to after the echo statement, and we indent the lines for nice view :
$infolines .= '"Language Used":"'.$lang.'",';
$infolines .= '"Mispelled words":"'.$counter.'",';
$infolines .= '"Total words suggested":"'.$suggest_count.'",';
$infolines .= '"Total Lines Checked":"'.$returnlines.'"';
$infolines .= '};';
$varlines = substr($varlines, 0, strlen($varlines) - 1);
echo $varlines.'};'.$infolines.'</script>';
}
But there is another problem aswell, the foreach statement on line 147 throws an error when the $textarray
isnt an array, also since the $textarray = array() is set inside the if(trim($text)) code.
So replace lines 147-150 :
foreach ($textarray as $key=>$value)
{
echo $value;
}
With theese instead, we only need to validate that its infact an array to continue. Sure, we could also have used same check as the code above,
if(!(trim($text)=='')) {
if (is_array($textarray)){
foreach ($textarray as $key=>$value)
{
echo $value;
}
}
This fix woulod resolve the problems, but when I get to think of it maby the best way would be to pull att the vars outside of the condition, meaning setting the array and the $infolines outside, since the logic from JS maby need something here. That I havnt thought of, give me a note in that case and Ill rewrite the code.
Offline
To have the variables outside the condition, meaning that the output from the logic will be as if it all went ok - which sounds better in my head (Havnt installed the Aspell so cant test it 100%).
The code would then be, I just glue the whole document, use WinMerge to spot the differences - not that many really. Moved some vars outside the conedition and placed them infront of it.
<?php
$text = stripslashes($_POST['content']);
// Convert UTF-8 multi-bytes into decimal character entities. This is because
// aspell isn't fully utf8-aware
$text = preg_replace('/([\xC0-\xDF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
$text = preg_replace('/([\xE0-\xEF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
$text = preg_replace('/([\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
function utf8_ord($chr)
{
switch(strlen($chr))
{
case 1 :
return ord($chr);
case 2 :
$ord = ord($chr{1}) & 63;
$ord = $ord | ((ord($chr{0}) & 31) << 6);
return $ord;
case 3 :
$ord = ord($chr{2}) & 63;
$ord = $ord | ((ord($chr{1}) & 63) << 6);
$ord = $ord | ((ord($chr{0}) & 15) << 12);
return $ord;
case 4 :
$ord = ord($chr{3}) & 63;
$ord = $ord | ((ord($chr{2}) & 63) << 6);
$ord = $ord | ((ord($chr{1}) & 63) << 12);
$ord = $ord | ((ord($chr{0}) & 7) << 18);
return $ord;
default :
trigger_error('Character not utf-8', E_USER_ERROR);
}
}
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'aspell_setup.php');
##############################################################################
header('Content-Type: text/html; charset=utf-8');
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="spell-check-style.css" />';
// Lets define some values outside the condition below, in case we have an empty
// document.
$textarray = array();
$varlines = '<script type="text/javascript">var suggested_words = { ';
$infolines = 'var spellcheck_info = {';
$counter = 0;
$suggest_count = 0;
if (trim($text) != "")
{
if ($fd = fopen($temptext, 'w'))
{
$textarray = explode("\n", $text);
fwrite ($fd, "!\n");
foreach ($textarray as $key=>$value)
{
// adding the carat to each line prevents the use of aspell commands within the text...
fwrite($fd, "^$value\n");
}
fclose($fd);
chmod($temptext, 0777);
// next run aspell
$return = shell_exec($aspellcommand . ' 2>&1');
// echo $return;
unlink($temptext);
$returnarray = explode("\n", $return);
$returnlines = count($returnarray);
//print_r(htmlentities($return));
$textlines = count($textarray);
$lineindex = -1;
$poscorrect = 0;
foreach ($returnarray as $key=>$value)
{
// if there is a correction here, processes it, else move the $textarray pointer to the next line
if (substr($value, 0, 1) == '&')
{
$counter=$counter+1;
$correction = explode(' ', $value);
$word = $correction[1];
$suggest_count += $correction[2];
$absposition = substr($correction[3], 0, -1) - 1;
$position = $absposition + $poscorrect;
$niceposition = $lineindex.','.$absposition;
$suggstart = strpos($value, ':') + 2;
$suggestions = substr($value, $suggstart);
$suggestionarray = explode(', ', $suggestions);
$beforeword = substr($textarray[$lineindex], 0, $position);
$afterword = substr($textarray[$lineindex], $position + strlen($word));
$textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span>'.$afterword;
$suggestion_list = '';
foreach ($suggestionarray as $key=>$value)
{
$suggestion_list .= $value.',';
}
$suggestion_list = substr($suggestion_list, 0, strlen($suggestion_list) - 1);
$varlines .= '"'.$word.'":"'.$suggestion_list.'",';
$poscorrect = $poscorrect + 41;
}
elseif (substr($value, 0, 1) == '#')
{
$correction = explode(' ', $value);
$word = $correction[1];
$absposition = $correction[2] - 1;
$position = $absposition + $poscorrect;
$niceposition = $lineindex.','.$absposition;
$beforeword = substr($textarray[$lineindex], 0, $position);
$afterword = substr($textarray[$lineindex], $position + strlen($word));
$textarray[$lineindex] = $beforeword.$word.$afterword;
$textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span><span class="HA-spellcheck-suggestions">'.$word.'</span>'.$afterword;
// $poscorrect = $poscorrect;
$poscorrect = $poscorrect + 88 + strlen($word);
}
else
{
//print "Done with line $lineindex, next line...<br><br>";
$poscorrect = 0;
$lineindex = $lineindex + 1;
}
}
}
else
{
// This one isnt used for anything at the moment!
$return = 'failed to open!';
}
}
$infolines .= '"Language Used":"'.$lang.'",';
$infolines .= '"Mispelled words":"'.$counter.'",';
$infolines .= '"Total words suggested":"'.$suggest_count.'",';
$infolines .= '"Total Lines Checked":"'.$returnlines.'"';
$infolines .= '};';
$varlines = substr($varlines, 0, strlen($varlines) - 1);
echo $varlines.'};'.$infolines.'</script>';
echo '</head>
<body onload="window.parent.finishedSpellChecking();">';
foreach ($textarray as $key=>$value)
{
echo $value;
}
$dictionaries = str_replace(chr(10),",", shell_exec($aspelldictionaries));
echo '<div id="HA-spellcheck-dictionaries">'.$dictionaries.'</div>';
echo '</body></html>';
//echo '<div id="HA-spellcheck-dictionaries">en_US,es,fr</div></body></html>';
?>
In short the changes would be pasting theese lines :
// Lets define some values outside the condition below, in case we have an empty
// document.
$textarray = array();
$varlines = '<script type="text/javascript">var suggested_words = { ';
$infolines = 'var spellcheck_info = {';
$counter = 0;
$suggest_count = 0;
infront of the if (trim($text) != "") line.
Last edited by kimss (2005-05-01 06:10:29)
Offline
Hi there,
I followed your first solution, and there are a couple of other oddities that I'm experiencing with the spell checker. For some reason, these problems occur only on my own Xinha testing page and not on the included Xinha sample. These issues can be observed at http://nt.bupipedream.com/pipeline/spellertest.html.
First of all, when the Dictionary drop-down box gets populated, some of the options are weird, and have HTML tags in them, like:
en_GB-<span class="HA-spellcheck-error">ize</span>-w_accents
Secondly, the Re-check button does some funny stuff. When you click it -- it comes up saying that "wo" isn't a word. Then when you press Ignore, it comes up saying that "ise" is not a word. This happens regardless of whether those pieces of text are in the text box or not.
Any insight you might be able to provide would be sincerely appreciated.
Best,
Martin
Offline
I see the problem, if you look closer at the HTML kode, the code for the dropdown menu is accually being spell checked. The tags are the ones used by the spellcheker to mark bad words.
I would need to succesfull install this on my machine to manage to debug that, (meaning Aspell). There are some issues with the spellchecker thats for sure, Ill keep you posted if I get to look into it more.
Offline
Thanks, appreciate it!
-Martin
Offline
Well, Ill give it a go before I hit the pub, I remembered I had already installed Aspell on my machine. I already fixed another problem right now, seems the PHP logic doesnts serve the content UTF-8, which means for me who is in Norway it all went wrong.
Quick fix for the utf-8 is like this, but Ill post more complete code if I solve the problems :
$infolines .= '"Language Used":"'.$lang.'",';
$infolines .= '"Mispelled words":"'.$counter.'",';
$infolines .= '"Total words suggested":"'.$suggest_count.'",';
$infolines .= '"Total Lines Checked":"'.$returnlines.'"';
$infolines .= '};';
$varlines = substr($varlines, 0, strlen($varlines) - 1);
echo utf8_encode($varlines).'};'.utf8_encode($infolines).'</script>';
echo '</head>
<body onload="window.parent.finishedSpellChecking();">';
foreach ($textarray as $key=>$value)
{
echo utf8_encode($value);
}
Note there are three utf8_encode() around the output variables. But you probably dont need to Scandinavian letters,
One more while Im at it, the selected dictionary is removed from the list when it gets selected, comment out one line in the spell-check-ui.js in the bottom, the line in question has a comment above it :
spell-check-ui.js
for (var i = 0; i < dicts.length; ++i) {
var txt = dicts[i];
var option = document.createElement("option");
if(txt == activeDictionary) {
// The line below removes the selected item instead, commented out
//txt = RegExp.$1;
option.selected = true;
}
option.value = txt;
option.appendChild(document.createTextNode(txt));
select.appendChild(option);
There is also added an extra empty dictionary from the PHP logic, since the JS splits on comma. Find theese two lines in :
spell-check-logic.php
$dictionaries = str_replace(chr(10),",", shell_exec($aspelldictionaries));
echo '<div id="HA-spellcheck-dictionaries">'.$dictionaries.'</div>';
Replace with :
$dictionaries = str_replace(chr(10),",", shell_exec($aspelldictionaries));
if(ereg(",$",$dictionaries))
$dictionaries = ereg_replace(",$","",$dictionaries);
echo '<div id="HA-spellcheck-dictionaries">'.$dictionaries.'</div>';
The annoying empty dictinary is now removed.
Last edited by kimss (2005-05-01 18:09:07)
Offline
Ok, it seems I have solved all the problems I could find at the moment, I also suspect you have pasted some faulty code from me from above since the error occured when rechecking the page, since I dont get it. I have manipulated two files now, and I post the complete code for them here, which makes it easier for you as all you need is to replace all the code in your files. Then it should work fine, tell me if you have any more problems.
spell-check-logic.php
<?php
/* Some enhancements and fixes ny kim@steinhaug.com, www.steinhaug.com
- When spellchecking empty document, some of the HTML was generated
inside the logic, resulting in faulty HTML code being presented.
- The documented is supposed to be utf-8, but the output was never
converted to utf-8.
- When listing the dictionaries an extra , was presented in the string
which resulted in the JS logic to create empty dictionary in dropdown
- Debug mode, run this file directly in browser and file is served as
plain text, its easier to debug this way.
*/
// Mode for debugging the code :
$debug = false;
$text = stripslashes($_POST['content']);
if($debug) $text = 'This is a wrrong sppelled word for tesling pruposes';
// Convert UTF-8 multi-bytes into decimal character entities. This is because
// aspell isn't fully utf8-aware
$text = preg_replace('/([\xC0-\xDF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
$text = preg_replace('/([\xE0-\xEF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
$text = preg_replace('/([\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF])/e', "'&#' . utf8_ord('\$1') . ';'", $text);
function utf8_ord($chr)
{
switch(strlen($chr))
{
case 1 :
return ord($chr);
case 2 :
$ord = ord($chr{1}) & 63;
$ord = $ord | ((ord($chr{0}) & 31) << 6);
return $ord;
case 3 :
$ord = ord($chr{2}) & 63;
$ord = $ord | ((ord($chr{1}) & 63) << 6);
$ord = $ord | ((ord($chr{0}) & 15) << 12);
return $ord;
case 4 :
$ord = ord($chr{3}) & 63;
$ord = $ord | ((ord($chr{2}) & 63) << 6);
$ord = $ord | ((ord($chr{1}) & 63) << 12);
$ord = $ord | ((ord($chr{0}) & 7) << 18);
return $ord;
default :
trigger_error('Character not utf-8', E_USER_ERROR);
}
}
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'aspell_setup.php');
##############################################################################
if(!$debug)
header('Content-Type: text/html; charset=utf-8');
else
header('Content-Type: text/plain; charset=utf-8');
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="spell-check-style.css" />';
// Lets define some values outside the condition below, in case we have an empty
// document.
$textarray = array();
$varlines = '<script type="text/javascript">var suggested_words = { ';
$infolines = 'var spellcheck_info = {';
$counter = 0;
$suggest_count = 0;
if (trim($text) != "")
{
if ($fd = fopen($temptext, 'w'))
{
$textarray = explode("\n", $text);
fwrite ($fd, "!\n");
foreach ($textarray as $key=>$value)
{
// adding the carat to each line prevents the use of aspell commands within the text...
fwrite($fd, "^$value\n");
}
fclose($fd);
chmod($temptext, 0777);
// next run aspell
$return = shell_exec($aspellcommand . ' 2>&1');
// echo $return;
unlink($temptext);
$returnarray = explode("\n", $return);
$returnlines = count($returnarray);
//print_r(htmlentities($return));
$textlines = count($textarray);
$lineindex = -1;
$poscorrect = 0;
foreach ($returnarray as $key=>$value)
{
// if there is a correction here, processes it, else move the $textarray pointer to the next line
if (substr($value, 0, 1) == '&')
{
$counter=$counter+1;
$correction = explode(' ', $value);
$word = $correction[1];
$suggest_count += $correction[2];
$absposition = substr($correction[3], 0, -1) - 1;
$position = $absposition + $poscorrect;
$niceposition = $lineindex.','.$absposition;
$suggstart = strpos($value, ':') + 2;
$suggestions = substr($value, $suggstart);
$suggestionarray = explode(', ', $suggestions);
$beforeword = substr($textarray[$lineindex], 0, $position);
$afterword = substr($textarray[$lineindex], $position + strlen($word));
$textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span>'.$afterword;
$suggestion_list = '';
foreach ($suggestionarray as $key=>$value)
{
$suggestion_list .= $value.',';
}
$suggestion_list = substr($suggestion_list, 0, strlen($suggestion_list) - 1);
$varlines .= '"'.$word.'":"'.$suggestion_list.'",';
$poscorrect = $poscorrect + 41;
}
elseif (substr($value, 0, 1) == '#')
{
$correction = explode(' ', $value);
$word = $correction[1];
$absposition = $correction[2] - 1;
$position = $absposition + $poscorrect;
$niceposition = $lineindex.','.$absposition;
$beforeword = substr($textarray[$lineindex], 0, $position);
$afterword = substr($textarray[$lineindex], $position + strlen($word));
$textarray[$lineindex] = $beforeword.$word.$afterword;
$textarray[$lineindex] = $beforeword.'<span class="HA-spellcheck-error">'.$word.'</span><span class="HA-spellcheck-suggestions">'.$word.'</span>'.$afterword;
// $poscorrect = $poscorrect;
$poscorrect = $poscorrect + 88 + strlen($word);
}
else
{
//print "Done with line $lineindex, next line...<br><br>";
$poscorrect = 0;
$lineindex = $lineindex + 1;
}
}
}
else
{
// This one isnt used for anything at the moment!
$return = 'failed to open!';
}
}
$infolines .= '"Language Used":"'.$lang.'",';
$infolines .= '"Mispelled words":"'.$counter.'",';
$infolines .= '"Total words suggested":"'.$suggest_count.'",';
$infolines .= '"Total Lines Checked":"'.$returnlines.'"';
$infolines .= '};';
$varlines = substr($varlines, 0, strlen($varlines) - 1);
echo utf8_encode($varlines).'};'.utf8_encode($infolines).'</script>';
echo '</head>
<body onload="window.parent.finishedSpellChecking();">';
foreach ($textarray as $key=>$value)
{
echo utf8_encode($value);
}
$dictionaries = str_replace(chr(10),",", shell_exec($aspelldictionaries));
if(ereg(",$",$dictionaries))
$dictionaries = ereg_replace(",$","",$dictionaries);
echo '<div id="HA-spellcheck-dictionaries">'.$dictionaries.'</div>';
echo '</body></html>';
?>
spell-check-ui.js
// Spell Checker Plugin for HTMLArea-3.0
// Sponsored by www.americanbible.org
// Implementation by Mihai Bazon, http://dynarch.com/mishoo/
//
// (c) dynarch.com 2003.
// Distributed under the same terms as HTMLArea itself.
// This notice MUST stay intact for use (see license.txt).
//
// $Id: spell-check-ui.js 60 2005-04-05 13:22:31Z niko $
// internationalization file was already loaded in parent ;-)
var SpellChecker = window.opener.SpellChecker;
var HTMLArea = window.opener.HTMLArea;
var _editor_url = window.opener._editor_url;
var is_ie = HTMLArea.is_ie;
var editor = SpellChecker.editor;
var frame = null;
var currentElement = null;
var wrongWords = null;
var modified = false;
var allWords = {};
var fixedWords = [];
var suggested_words = {};
var to_p_dict = []; // List of words to add to personal dictionary.
var to_r_list = []; // List of words to add to replacement list.
function _lc(string) {
return HTMLArea._lc(string, 'SpellChecker');
}
function makeCleanDoc(leaveFixed) {
// document.getElementById("status").innerHTML = 'Please wait: rendering valid HTML';
var words = wrongWords.concat(fixedWords);
for (var i = words.length; --i >= 0;) {
var el = words[i];
if (!(leaveFixed && /HA-spellcheck-fixed/.test(el.className))) {
el.parentNode.insertBefore(el.firstChild, el);
el.parentNode.removeChild(el);
} else
el.className = "HA-spellcheck-fixed";
}
// we should use innerHTML here, but IE6's implementation fucks up the
// HTML to such extent that our poor Perl parser doesn't understand it
// anymore.
return window.opener.HTMLArea.getHTML(frame.contentWindow.document.body, false, editor);
};
function recheckClicked() {
document.getElementById("status").innerHTML = _lc("Please wait: changing dictionary to") + ': "' + document.getElementById("f_dictionary").value + '".';
var field = document.getElementById("f_content");
field.value = makeCleanDoc(true);
field.form.submit();
};
function saveClicked() {
if (modified) {
editor.setHTML(makeCleanDoc(false));
}
if(to_p_dict.length || to_r_list.length && editor.config.SpellChecker.backend == 'php')
{
var data = {};
for(var i = 0;i < to_p_dict.length;i++)
{
data['to_p_dict[' + i + ']'] = to_p_dict[i];
}
for(var i = 0;i < to_r_list.length;i++)
{
data['to_r_list[' + i + '][0]'] = to_r_list[i][0];
data['to_r_list[' + i + '][1]'] = to_r_list[i][1];
}
// var win = window;
window.opener.HTMLArea._postback(_editor_url + '/plugins/SpellChecker/spell-check-savedicts.php', data);
window.close();
}
else
{
window.close();
}
return false;
};
function cancelClicked() {
var ok = true;
if (modified) {
ok = confirm(_lc("This will drop changes and quit spell checker. Please confirm."));
}
if (ok) {
window.close();
}
return false;
};
function replaceWord(el) {
var replacement = document.getElementById("v_replacement").value;
var this_word_modified = (el.innerHTML != replacement);
if (this_word_modified)
modified = true;
if (el) {
el.className = el.className.replace(/\s*HA-spellcheck-(hover|fixed)\s*/g, " ");
}
el.className += " HA-spellcheck-fixed";
el.__msh_fixed = true;
if (!this_word_modified) {
return false;
}
to_r_list.push([el.innerHTML, replacement]);
el.innerHTML = replacement;
};
function replaceClicked() {
replaceWord(currentElement);
var start = currentElement.__msh_id;
var index = start;
do {
++index;
if (index == wrongWords.length) {
index = 0;
}
} while ((index != start) && wrongWords[index].__msh_fixed);
if (index == start) {
index = 0;
alert(_lc("Finished list of mispelled words"));
}
wrongWords[index].__msh_wordClicked(true);
return false;
};
function revertClicked() {
document.getElementById("v_replacement").value = currentElement.__msh_origWord;
replaceWord(currentElement);
currentElement.className = "HA-spellcheck-error HA-spellcheck-current";
return false;
};
function replaceAllClicked() {
var replacement = document.getElementById("v_replacement").value;
var ok = true;
var spans = allWords[currentElement.__msh_origWord];
if (spans.length == 0) {
alert("An impossible condition just happened. Call FBI. ;-)");
} else if (spans.length == 1) {
replaceClicked();
return false;
}
/*
var message = "The word \"" + currentElement.__msh_origWord + "\" occurs " + spans.length + " times.\n";
if (replacement == currentElement.__msh_origWord) {
ok = confirm(message + "Ignore all occurrences?");
} else {
ok = confirm(message + "Replace all occurrences with \"" + replacement + "\"?");
}
*/
if (ok) {
for (var i = 0; i < spans.length; ++i) {
if (spans[i] != currentElement) {
replaceWord(spans[i]);
}
}
// replace current element the last, so that we jump to the next word ;-)
replaceClicked();
}
return false;
};
function ignoreClicked() {
document.getElementById("v_replacement").value = currentElement.__msh_origWord;
replaceClicked();
return false;
};
function ignoreAllClicked() {
document.getElementById("v_replacement").value = currentElement.__msh_origWord;
replaceAllClicked();
return false;
};
function learnClicked() {
to_p_dict.push(currentElement.__msh_origWord);
return ignoreAllClicked();
};
function internationalizeWindow() {
var types = ["div", "span", "button"];
for (var i = 0; i < types.length; ++i) {
var tag = types[i];
var els = document.getElementsByTagName(tag);
for (var j = els.length; --j >= 0;) {
var el = els[j];
if (el.childNodes.length == 1 && /\S/.test(el.innerHTML)) {
var txt = el.innerHTML;
el.innerHTML = _lc(txt);
}
}
}
};
function initDocument() {
internationalizeWindow();
modified = false;
frame = document.getElementById("i_framecontent");
var field = document.getElementById("f_content");
field.value = HTMLArea.getHTML(editor._doc.body, false, editor);
var dict = document.getElementById("f_dictionary");
if(typeof editor.config.SpellChecker.defaultDictionary != "undefined"
&& editor.config.SpellChecker.defaultDictionary != "") {
dict.value = editor.config.SpellChecker.defaultDictionary;
} else {
dict.value = "en_GB";
}
if(editor.config.SpellChecker.backend == 'php')
{
field.form.action = _editor_url + '/plugins/SpellChecker/spell-check-logic.php';
}
field.form.submit();
document.getElementById("f_init").value = "0";
// assign some global event handlers
var select = document.getElementById("v_suggestions");
select.onchange = function() {
document.getElementById("v_replacement").value = this.value;
};
if (is_ie) {
select.attachEvent("ondblclick", replaceClicked);
} else {
select.addEventListener("dblclick", replaceClicked, true);
}
document.getElementById("b_replace").onclick = replaceClicked;
if(editor.config.SpellChecker.backend == 'php')
{
document.getElementById("b_learn").onclick = learnClicked;
}
else
{
document.getElementById("b_learn").parent.removeChild(document.getElementById("b_learn"));
}
document.getElementById("b_replall").onclick = replaceAllClicked;
document.getElementById("b_ignore").onclick = ignoreClicked;
document.getElementById("b_ignall").onclick = ignoreAllClicked;
document.getElementById("b_recheck").onclick = recheckClicked;
document.getElementById("b_revert").onclick = revertClicked;
document.getElementById("b_info").onclick = displayInfo;
document.getElementById("b_ok").onclick = saveClicked;
document.getElementById("b_cancel").onclick = cancelClicked;
select = document.getElementById("v_dictionaries");
select.onchange = function() {
document.getElementById("f_dictionary").value = this.value;
};
};
function getAbsolutePos(el) {
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent) {
var tmp = getAbsolutePos(el.offsetParent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
};
function wordClicked(scroll) {
var self = this;
if (scroll) (function() {
var pos = getAbsolutePos(self);
var ws = { x: frame.offsetWidth - 4,
y: frame.offsetHeight - 4 };
var wp = { x: frame.contentWindow.document.body.scrollLeft,
y: frame.contentWindow.document.body.scrollTop };
pos.x -= Math.round(ws.x/2);
if (pos.x < 0) pos.x = 0;
pos.y -= Math.round(ws.y/2);
if (pos.y < 0) pos.y = 0;
frame.contentWindow.scrollTo(pos.x, pos.y);
})();
if (currentElement) {
var a = allWords[currentElement.__msh_origWord];
currentElement.className = currentElement.className.replace(/\s*HA-spellcheck-current\s*/g, " ");
for (var i = 0; i < a.length; ++i) {
var el = a[i];
if (el != currentElement) {
el.className = el.className.replace(/\s*HA-spellcheck-same\s*/g, " ");
}
}
}
currentElement = this;
this.className += " HA-spellcheck-current";
var a = allWords[currentElement.__msh_origWord];
for (var i = 0; i < a.length; ++i) {
var el = a[i];
if (el != currentElement) {
el.className += " HA-spellcheck-same";
}
}
// document.getElementById("b_replall").disabled = (a.length <= 1);
// document.getElementById("b_ignall").disabled = (a.length <= 1);
var txt;
if (a.length == 1) {
txt = "one occurrence";
} else if (a.length == 2) {
txt = "two occurrences";
} else {
txt = a.length + " occurrences";
}
var suggestions = suggested_words[this.__msh_origWord];
if (suggestions)
suggestions = suggestions.split(/,/);
else
suggestions = [];
var select = document.getElementById("v_suggestions");
document.getElementById("statusbar").innerHTML = "Found " + txt +
' for word "<b>' + currentElement.__msh_origWord + '</b>"';
for (var i = select.length; --i >= 0;) {
select.remove(i);
}
for (var i = 0; i < suggestions.length; ++i) {
var txt = suggestions[i];
var option = document.createElement("option");
option.value = txt;
option.appendChild(document.createTextNode(txt));
select.appendChild(option);
}
document.getElementById("v_currentWord").innerHTML = this.__msh_origWord;
if (suggestions.length > 0) {
select.selectedIndex = 0;
select.onchange();
} else {
document.getElementById("v_replacement").value = this.innerHTML;
}
select.style.display = "none";
select.style.display = "block";
return false;
};
function wordMouseOver() {
this.className += " HA-spellcheck-hover";
};
function wordMouseOut() {
this.className = this.className.replace(/\s*HA-spellcheck-hover\s*/g, " ");
};
function displayInfo() {
var info = frame.contentWindow.spellcheck_info;
if (!info)
alert("No information available");
else {
var txt = "** Document information **";
for (var i in info) {
txt += "\n" + i + " : " + info[i];
}
alert(txt);
}
return false;
};
function finishedSpellChecking() {
// initialization of global variables
currentElement = null;
wrongWords = null;
allWords = {};
fixedWords = [];
suggested_words = frame.contentWindow.suggested_words;
document.getElementById("status").innerHTML = "HTMLArea Spell Checker (<a href='readme-tech.html' target='_blank' title='Technical information'>info</a>)";
var doc = frame.contentWindow.document;
var spans = doc.getElementsByTagName("span");
var sps = [];
var id = 0;
for (var i = 0; i < spans.length; ++i) {
var el = spans[i];
if (/HA-spellcheck-error/.test(el.className)) {
sps.push(el);
el.__msh_wordClicked = wordClicked;
el.onclick = function(ev) {
ev || (ev = window.event);
ev && HTMLArea._stopEvent(ev);
return this.__msh_wordClicked(false);
};
el.onmouseover = wordMouseOver;
el.onmouseout = wordMouseOut;
el.__msh_id = id++;
var txt = (el.__msh_origWord = el.firstChild.data);
el.__msh_fixed = false;
if (typeof allWords[txt] == "undefined") {
allWords[txt] = [el];
} else {
allWords[txt].push(el);
}
} else if (/HA-spellcheck-fixed/.test(el.className)) {
fixedWords.push(el);
}
}
wrongWords = sps;
if (sps.length == 0) {
if (!modified) {
alert(_lc("No mispelled words found with the selected dictionary."));
// window.close();
} else {
alert(_lc("No mispelled words found with the selected dictionary."));
}
return false;
}
(currentElement = sps[0]).__msh_wordClicked(true);
var as = doc.getElementsByTagName("a");
for (var i = as.length; --i >= 0;) {
var a = as[i];
a.onclick = function() {
if (confirm(_lc("Please confirm that you want to open this link") + ":\n" +
this.href + "\n" + _lc("I will open it in a new page."))) {
window.open(this.href);
}
return false;
};
}
var dicts = doc.getElementById("HA-spellcheck-dictionaries");
if (dicts) {
dicts.parentNode.removeChild(dicts);
dicts = dicts.innerHTML.split(/,/);
var select = document.getElementById("v_dictionaries");
for (var i = select.length; --i >= 0;) {
select.remove(i);
}
var activeDictionary = document.getElementById("f_dictionary").value;
for (var i = 0; i < dicts.length; ++i) {
var txt = dicts[i];
var option = document.createElement("option");
if(txt == activeDictionary) {
// The line below removes the selected item instead
//txt = RegExp.$1;
option.selected = true;
}
option.value = txt;
option.appendChild(document.createTextNode(txt));
select.appendChild(option);
}
}
};
Offline
Hello,
Interestingly, I replaced my spell-check-logic.php and spell-check-ui.js with your versions and both of the problems I reported in my last message are still occurring. They can still be seen at the same URL, http://nt.bupipedream.com/pipeline/spellertest.html
If you have any other suggestions, I'd certainly appreciate hearing them, and many thanks for the assistance you've provided thus far.
Best,
Martin
Offline
Hehe, this might sound like a really dumb thing to do - but it happened to me. If you access your system from Firefox (I do) there seems to be a little problem with cached JS files. When opening up the SpellChecker dialog, hit F5 to reload all the files in that window - and the problem is fixed,
Tell me how your F5 works,
Offline
Hi there,
Thanks for the suggestion. Sadly, it didn't solve the problem -- the same problems are still occurring in both Firefox and Internet Explorer in my example at http://nt.bupipedream.com/pipeline/spellertest.html, even after reloading the dialog. Any other ideas?
Sorry for being a pain in the butt. Thanks for any advice.
-Martin
Offline
Ahh! I see. Seems I fixed all the problems when Spellchecking a page with something in it, but when Spellchecking an empty page, and hitting the recheck button (Which for some reason shouldnt be pressed...) the error appears.
Ill look into this later today and fix it.
Offline
Thanks!
-Martin
Offline
Hey there,
I was just wondering if you ever had a chance to take a look at this.
Many thanks,
Martin
Offline
Pages: 1