Ticket #3910: 3910.patch
File 3910.patch, 31.5 KB (added by , 15 years ago) |
---|
-
editor/dialog/fck_spellerpages.html
32 32 33 33 var oEditor = window.parent.InnerDialogLoaded() ; 34 34 var FCKLang = oEditor.FCKLang ; 35 var oSpeller; 35 36 36 37 window.onload = function() 37 38 { 38 39 document.getElementById('txtHtml').value = oEditor.FCK.EditorDocument.body.innerHTML ; 39 40 varoSpeller = new spellChecker( document.getElementById('txtHtml') ) ;40 41 oSpeller = new spellChecker( document.getElementById('txtHtml') ) ; 41 42 oSpeller.spellCheckScript = oEditor.FCKConfig.SpellerPagesServerScript || 'server-scripts/spellchecker.php' ; 42 43 oSpeller.OnFinished = oSpeller_OnFinished ; 43 oSpeller.openChecker() ; 44 oSpeller.OnUpdateOkBtn = oSpeller_UpdateOkBtn; 45 oSpeller.bUseAddButton = (typeof oEditor.FCKConfig.SpellerPagesAddButton != 'undefined' && oEditor.FCKConfig.SpellerPagesAddButton) ? true : false; 46 oSpeller.openChecker(); 44 47 } 45 48 46 49 function OnSpellerControlsLoad( controlsWindow ) … … 61 64 window.parent.Cancel() ; 62 65 } 63 66 67 /** 68 * OnUpdateOkBtn handler for the speller object - called to let us know if 69 * changes have been made (or subsequently reversed out) so we can decide to 70 * enable/disable the 'Ok' button on the dialog 71 * @method oSpeller_UpdateOkBtn 72 * @param {boolean} bChanges true if corrections have been made, false if not 73 */ 74 function oSpeller_UpdateOkBtn(bChanges) { 75 // Enable the OK button 76 window.parent.SetOkButton(bChanges); 77 } 78 79 /** 80 * Standard FCK dialog method called when the OK button is clicked or RETURN is 81 * pressed to see if dialog should be closed. 82 * @method Ok 83 * @return {Boolean} true if dialog should be closed, false if not 84 */ 85 function Ok() { 86 // Apply any spelling changes made then close the dialog 87 oSpeller.terminateSpell(); 88 } 64 89 </script> 65 90 </head> 66 91 <body style="OVERFLOW: hidden" scroll="no" style="padding:0px;"> -
editor/dialog/fck_spellerpages/spellerpages/controls.html
46 46 } 47 47 } 48 48 49 function addWord() { 50 if(spellerObject) 51 spellerObject.addWord(); 52 } 53 49 54 function suggText() { 50 55 if( controlWindowObj ) { 51 56 controlWindowObj.setSuggestedText(); … … 110 115 <table border="0" cellpadding="0" cellspacing="0" border="0"> 111 116 <tr> 112 117 <td> 113 <input class="buttonDefault" type="button" fckLang="DlgSpellBtnIgnore" value="Ignore" onClick="ignore_word();">118 <input class="buttonDefault" type="button" id="btnIgnore" fckLang="DlgSpellBtnIgnore" value="Ignore" onClick="ignore_word();" disabled> 114 119 </td> 115 120 <td> </td> 116 121 <td> 117 <input class="buttonDefault" type="button" fckLang="DlgSpellBtnIgnoreAll" value="Ignore All" onClick="ignore_all();">122 <input class="buttonDefault" type="button" id="btnIgnoreAll" fckLang="DlgSpellBtnIgnoreAll" value="Ignore All" onClick="ignore_all();" disabled> 118 123 </td> 119 124 </tr> 120 125 <tr> … … 122 127 </tr> 123 128 <tr> 124 129 <td> 125 <input class="buttonDefault" type="button" fckLang="DlgSpellBtnReplace" value="Replace" onClick="replace_word();">130 <input class="buttonDefault" type="button" id="btnReplace" fckLang="DlgSpellBtnReplace" value="Replace" onClick="replace_word();" disabled> 126 131 </td> 127 132 <td> </td> 128 133 <td> 129 <input class="buttonDefault" type="button" fckLang="DlgSpellBtnReplaceAll" value="Replace All" onClick="replace_all();">134 <input class="buttonDefault" type="button" id="btnReplaceAll" fckLang="DlgSpellBtnReplaceAll" value="Replace All" onClick="replace_all();" disabled> 130 135 </td> 131 136 </tr> 132 137 <tr> … … 134 139 </tr> 135 140 <tr> 136 141 <td> 137 <input class="buttonDefault" type="button" name="btnUndo" fckLang="DlgSpellBtnUndo" value="Undo" onClick="undo();" 138 disabled> 142 <input class="buttonDefault" type="button" name="btnUndo" fckLang="DlgSpellBtnUndo" value="Undo" onClick="undo();" disabled> 139 143 </td> 140 144 <td> </td> 141 145 <td> 142 <!-- by FredCK 143 <input class="buttonDefault" type="button" value="Close" onClick="end_spell();"> 144 --> 146 <input class="buttonDefault" type="button" id="btnAdd" value="Add" onClick="addWord();" style="visibility:hidden" disabled> 145 147 </td> 146 148 </tr> 147 149 </table> -
editor/dialog/fck_spellerpages/spellerpages/controlWindow.js
4 4 function controlWindow( controlForm ) { 5 5 // private properties 6 6 this._form = controlForm; 7 this.bUndoDisabled = true; 8 this.bControlsDisabled = true; 9 this.bUseAddButton = false; 10 11 // private methods 12 this._setButtons = _setButtons; 7 13 8 14 // public properties 9 15 this.windowType = "controlWindow"; … … 23 29 this.setSuggestedText = setSuggestedText; 24 30 this.enableUndo = enableUndo; 25 31 this.disableUndo = disableUndo; 32 this.enableControls = enableControls; 26 33 } 27 34 28 35 function resetForm() { … … 71 78 } 72 79 73 80 function enableUndo() { 74 if( this.undoButton ) { 75 if( this.undoButton.disabled == true ) { 76 this.undoButton.disabled = false; 77 } 78 } 81 this.bUndoDisabled = false; 82 this._setButtons(); 79 83 } 80 84 81 85 function disableUndo() { 82 if( this.undoButton ) { 83 if( this.undoButton.disabled == false ) { 84 this.undoButton.disabled = true; 85 } 86 } 86 this.bUndoDisabled = true; 87 this._setButtons(); 87 88 } 89 90 function enableControls(bEnable) { 91 this.bControlsDisabled = bEnable ? false : true; 92 this._setButtons(); 93 } 94 95 function _setButtons() { 96 var oForm = this._form; 97 if(!oForm) 98 return; 99 100 var oBtnAdd = oForm.btnAdd; 101 oBtnAdd.style.visibility = (this.bUseAddButton ? "visible" : "hidden"); 102 oBtnAdd.disabled = this.bControlsDisabled; 103 oForm.btnUndo.disabled = (this.bControlsDisabled || this.bUndoDisabled) ? true : false; 104 105 oForm.btnReplaceAll.disabled = this.bControlsDisabled; 106 oForm.btnReplace.disabled = this.bControlsDisabled; 107 oForm.btnIgnoreAll.disabled = this.bControlsDisabled; 108 oForm.btnIgnore.disabled = this.bControlsDisabled; 109 } 110 No newline at end of file -
editor/dialog/fck_spellerpages/spellerpages/server-scripts/spellchecker.pl
1 #!/usr/bin/perl 2 3 use CGI qw/ :standard /; 4 use File::Temp qw/ tempfile tempdir /; 5 6 # my $spellercss = '/speller/spellerStyle.css'; # by FredCK 7 my $spellercss = '../spellerStyle.css'; # by FredCK 8 # my $wordWindowSrc = '/speller/wordWindow.js'; # by FredCK 9 my $wordWindowSrc = '../wordWindow.js'; # by FredCK 10 my @textinputs = param( 'textinputs[]' ); # array 11 # my $aspell_cmd = 'aspell'; # by FredCK (for Linux) 12 my $aspell_cmd = '"C:\Program Files\Aspell\bin\aspell.exe"'; # by FredCK (for Windows) 13 my $lang = 'en_US'; 14 # my $aspell_opts = "-a --lang=$lang --encoding=utf-8"; # by FredCK 15 my $aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"; # by FredCK 16 my $input_separator = "A"; 17 18 # set the 'wordtext' JavaScript variable to the submitted text. 19 sub printTextVar { 20 for( my $i = 0; $i <= $#textinputs; $i++ ) { 21 print "textinputs[$i] = decodeURIComponent('" . escapeQuote( $textinputs[$i] ) . "')\n"; 22 } 23 } 24 25 sub printTextIdxDecl { 26 my $idx = shift; 27 print "words[$idx] = [];\n"; 28 print "suggs[$idx] = [];\n"; 29 } 30 31 sub printWordsElem { 32 my( $textIdx, $wordIdx, $word ) = @_; 33 print "words[$textIdx][$wordIdx] = '" . escapeQuote( $word ) . "';\n"; 34 } 35 36 sub printSuggsElem { 37 my( $textIdx, $wordIdx, @suggs ) = @_; 38 print "suggs[$textIdx][$wordIdx] = ["; 39 for my $i ( 0..$#suggs ) { 40 print "'" . escapeQuote( $suggs[$i] ) . "'"; 41 if( $i < $#suggs ) { 42 print ", "; 43 } 44 } 45 print "];\n"; 46 } 47 48 sub printCheckerResults { 49 my $textInputIdx = -1; 50 my $wordIdx = 0; 51 my $unhandledText; 52 # create temp file 53 my $dir = tempdir( CLEANUP => 1 ); 54 my( $fh, $tmpfilename ) = tempfile( DIR => $dir ); 55 56 # temp file was created properly? 57 58 # open temp file, add the submitted text. 59 for( my $i = 0; $i <= $#textinputs; $i++ ) { 60 $text = url_decode( $textinputs[$i] ); 61 # Strip all tags for the text. (by FredCK - #339 / #681) 62 $text =~ s/<[^>]+>/ /g; 63 @lines = split( /\n/, $text ); 64 print $fh "\%\n"; # exit terse mode 65 print $fh "^$input_separator\n"; 66 print $fh "!\n"; # enter terse mode 67 for my $line ( @lines ) { 68 # use carat on each line to escape possible aspell commands 69 print $fh "^$line\n"; 70 } 71 72 } 73 # exec aspell command 74 my $cmd = "$aspell_cmd $aspell_opts < $tmpfilename 2>&1"; 75 open ASPELL, "$cmd |" or handleError( "Could not execute `$cmd`\\n$!" ) and return; 76 # parse each line of aspell return 77 for my $ret ( <ASPELL> ) { 78 chomp( $ret ); 79 # if '&', then not in dictionary but has suggestions 80 # if '#', then not in dictionary and no suggestions 81 # if '*', then it is a delimiter between text inputs 82 if( $ret =~ /^\*/ ) { 83 $textInputIdx++; 84 printTextIdxDecl( $textInputIdx ); 85 $wordIdx = 0; 86 87 } elsif( $ret =~ /^(&|#)/ ) { 88 my @tokens = split( " ", $ret, 5 ); 89 printWordsElem( $textInputIdx, $wordIdx, $tokens[1] ); 90 my @suggs = (); 91 if( $tokens[4] ) { 92 @suggs = split( ", ", $tokens[4] ); 93 } 94 printSuggsElem( $textInputIdx, $wordIdx, @suggs ); 95 $wordIdx++; 96 } else { 97 $unhandledText .= $ret; 98 } 99 } 100 close ASPELL or handleError( "Error executing `$cmd`\\n$unhandledText" ) and return; 101 } 102 103 sub escapeQuote { 104 my $str = shift; 105 $str =~ s/'/\\'/g; 106 return $str; 107 } 108 109 sub handleError { 110 my $err = shift; 111 print "error = '" . escapeQuote( $err ) . "';\n"; 112 } 113 114 sub url_decode { 115 local $_ = @_ ? shift : $_; 116 defined or return; 117 # change + signs to spaces 118 tr/+/ /; 119 # change hex escapes to the proper characters 120 s/%([a-fA-F0-9]{2})/pack "H2", $1/eg; 121 return $_; 122 } 123 124 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 125 # Display HTML 126 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 127 128 print <<EOF; 129 Content-type: text/html; charset=utf-8 130 131 <html> 132 <head> 133 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 134 <link rel="stylesheet" type="text/css" href="$spellercss"/> 135 <script src="$wordWindowSrc"></script> 136 <script type="text/javascript"> 137 var suggs = new Array(); 138 var words = new Array(); 139 var textinputs = new Array(); 140 var error; 141 EOF 142 143 printTextVar(); 144 145 printCheckerResults(); 146 147 print <<EOF; 148 var wordWindowObj = new wordWindow(); 149 wordWindowObj.originalSpellings = words; 150 wordWindowObj.suggestions = suggs; 151 wordWindowObj.textInputs = textinputs; 152 153 154 function init_spell() { 155 // check if any error occured during server-side processing 156 if( error ) { 157 alert( error ); 158 } else { 159 // call the init_spell() function in the parent frameset 160 if (parent.frames.length) { 161 parent.init_spell( wordWindowObj ); 162 } else { 163 error = "This page was loaded outside of a frameset. "; 164 error += "It might not display properly"; 165 alert( error ); 166 } 167 } 168 } 169 170 </script> 171 172 </head> 173 <body onLoad="init_spell();"> 174 175 <script type="text/javascript"> 176 wordWindowObj.writeBody(); 177 </script> 178 179 </body> 180 </html> 181 EOF 1 #!/usr/bin/perl 2 3 use CGI qw/ :standard /; 4 use File::Temp qw/ tempfile tempdir /; 5 6 # my $spellercss = '/speller/spellerStyle.css'; # by FredCK 7 my $spellercss = '../spellerStyle.css'; # by FredCK 8 # my $wordWindowSrc = '/speller/wordWindow.js'; # by FredCK 9 my $wordWindowSrc = '../wordWindow.js'; # by FredCK 10 my @textinputs = param( 'textinputs[]' ); # array 11 # my $aspell_cmd = 'aspell'; # by FredCK (for Linux) 12 my $aspell_cmd = '"C:\Program Files\Aspell\bin\aspell.exe"'; # by FredCK (for Windows) 13 my $lang = 'en_US'; 14 # my $aspell_opts = "-a --lang=$lang --encoding=utf-8"; # by FredCK 15 my $aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"; # by FredCK 16 my $input_separator = "A"; 17 18 # TBD: Define this function for your server environment 19 sub serverAddWords() { 20 my $rWords = shift; # arrayref of words to add to server 21 # TBD: server specific: add missing words in @{$rWords} to dictionary 22 return 1; # return 1 if OK, 0 if failed 23 } 24 25 # TBD: Define this function for your server environment 26 sub serverGetWords() { 27 my @Words; 28 # TBD: server specific: put words from dictionary into \@Words 29 return \@Words; 30 } 31 32 # see if called to add words 33 if(defined(param("addwords"))) { 34 &addWords(); 35 exit; 36 } 37 38 # set the 'wordtext' JavaScript variable to the submitted text. 39 sub printTextVar { 40 for( my $i = 0; $i <= $#textinputs; $i++ ) { 41 print "textinputs[$i] = decodeURIComponent('" . escapeQuote( $textinputs[$i] ) . "')\n"; 42 } 43 } 44 45 sub printTextIdxDecl { 46 my $idx = shift; 47 print "words[$idx] = [];\n"; 48 print "suggs[$idx] = [];\n"; 49 } 50 51 sub printWordsElem { 52 my( $textIdx, $wordIdx, $word ) = @_; 53 print "words[$textIdx][$wordIdx] = '" . $word . "';\n"; 54 } 55 56 sub printSuggsElem { 57 my( $textIdx, $wordIdx, @suggs ) = @_; 58 print "suggs[$textIdx][$wordIdx] = ["; 59 for my $i ( 0..$#suggs ) { 60 print "'" . escapeQuote( $suggs[$i] ) . "'"; 61 if( $i < $#suggs ) { 62 print ", "; 63 } 64 } 65 print "];\n"; 66 } 67 68 sub printCheckerResults { 69 my $textInputIdx = -1; 70 my $wordIdx = 0; 71 my $unhandledText; 72 # create temp file 73 my $dir = tempdir( CLEANUP => 1 ); 74 my( $fh, $tmpfilename ) = tempfile( DIR => $dir ); 75 76 # temp file was created properly? 77 78 # open temp file, add the submitted text. 79 for( my $i = 0; $i <= $#textinputs; $i++ ) { 80 $text = url_decode( $textinputs[$i] ); 81 # Strip all tags for the text. (by FredCK - #339 / #681) 82 $text =~ s/<[^>]+>/ /g; 83 @lines = split( /\n/, $text ); 84 print $fh "\%\n"; # exit terse mode 85 print $fh "^$input_separator\n"; 86 print $fh "!\n"; # enter terse mode 87 for my $line ( @lines ) { 88 # use carat on each line to escape possible aspell commands 89 print $fh "^$line\n"; 90 } 91 92 } 93 94 # get words from dictionary 95 my $rWords = &serverGetWords(); 96 my %WordMap = map{$_,1} @{$rWords}; # create hash <word> => 1 for each word 97 98 # exec aspell command 99 my $cmd = "$aspell_cmd $aspell_opts < $tmpfilename 2>&1"; 100 open ASPELL, "$cmd |" or handleError( "Could not execute `$cmd`\\n$!" ) and return; 101 # parse each line of aspell return 102 for my $ret ( <ASPELL> ) { 103 chomp( $ret ); 104 # if '&', then not in dictionary but has suggestions 105 # if '#', then not in dictionary and no suggestions 106 # if '*', then it is a delimiter between text inputs 107 if( $ret =~ /^\*/ ) { 108 $textInputIdx++; 109 printTextIdxDecl( $textInputIdx ); 110 $wordIdx = 0; 111 112 } elsif( $ret =~ /^(&|#)/ ) { 113 my @tokens = split( " ", $ret, 5 ); 114 115 # Ignore words that are in dictionary 116 my $sWord = escapeQuote($tokens[1]); 117 next if defined($WordMap{$sWord}); 118 119 printWordsElem( $textInputIdx, $wordIdx, $sWord ); 120 121 my @suggs = (); 122 if( $tokens[4] ) { 123 @suggs = split( ", ", $tokens[4] ); 124 } 125 printSuggsElem( $textInputIdx, $wordIdx, @suggs ); 126 $wordIdx++; 127 } else { 128 $unhandledText .= $ret; 129 } 130 } 131 close ASPELL or handleError( "Error executing `$cmd`\\n$unhandledText" ) and return; 132 } 133 134 sub escapeQuote { 135 my $str = shift; 136 $str =~ s/'/\\'/g; 137 return $str; 138 } 139 140 sub handleError { 141 my $err = shift; 142 print "error = '" . escapeQuote( $err ) . "';\n"; 143 } 144 145 sub url_decode { 146 local $_ = @_ ? shift : $_; 147 defined or return; 148 # change + signs to spaces 149 tr/+/ /; 150 # change hex escapes to the proper characters 151 s/%([a-fA-F0-9]{2})/pack "H2", $1/eg; 152 return $_; 153 } 154 155 # add words function 156 sub addWords() { 157 my $sWords = param("words"); 158 return (undef, "No words to add!") if(!defined($sWords)); 159 160 # URI decode: change + signs to spaces and unescape hex escapes 161 $sWords = &url_decode($sWords); 162 163 # Split into words 164 my @Words = split(/ /, $sWords); 165 166 my $bResult = &serverAddWords(\@Words); 167 &printAddWordsOutput($bResult); 168 } 169 170 sub printAddWordsOutput() { 171 my $bResult = shift; 172 173 print <<EOF; 174 Content-type: text/html; charset=utf-8 175 176 <html> 177 <head> 178 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 179 <link rel="stylesheet" type="text/css" href="$spellercss"/> 180 <script src="$wordWindowSrc"></script> 181 <script type="text/javascript"> 182 function close_spell() { // calls the closeSpeller() function in the parent frameset 183 if(parent.frames.length && parent.opener && !parent.opener.closed && parent.opener.speller) 184 parent.opener.speller.closeSpeller(); 185 } 186 </script> 187 </head> 188 <body onLoad="close_spell();"> 189 <p> </p> 190 </body></html> 191 EOF 192 } 193 194 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 195 # Display HTML 196 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 197 198 print <<EOF; 199 Content-type: text/html; charset=utf-8 200 201 <html> 202 <head> 203 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 204 <link rel="stylesheet" type="text/css" href="$spellercss"/> 205 <script src="$wordWindowSrc"></script> 206 <script type="text/javascript"> 207 var suggs = new Array(); 208 var words = new Array(); 209 var textinputs = new Array(); 210 var error; 211 EOF 212 213 printTextVar(); 214 215 printCheckerResults(); 216 217 print <<EOF; 218 var wordWindowObj = new wordWindow(); 219 wordWindowObj.originalSpellings = words; 220 wordWindowObj.suggestions = suggs; 221 wordWindowObj.textInputs = textinputs; 222 223 224 function init_spell() { 225 // check if any error occured during server-side processing 226 if( error ) { 227 alert( error ); 228 } else { 229 // call the init_spell() function in the parent frameset 230 if (parent.frames.length) { 231 parent.init_spell( wordWindowObj ); 232 } else { 233 error = "This page was loaded outside of a frameset. "; 234 error += "It might not display properly"; 235 alert( error ); 236 } 237 } 238 } 239 240 </script> 241 242 </head> 243 <body onLoad="init_spell();"> 244 245 <script type="text/javascript"> 246 wordWindowObj.writeBody(); 247 </script> 248 249 </body> 250 </html> 251 EOF 252 No newline at end of file -
editor/dialog/fck_spellerpages/spellerpages/spellchecker.html
57 57 bodyDoc.write('<\/html>'); 58 58 bodyDoc.close(); 59 59 } 60 61 // post the words the user added to the server 62 function postAddedWords(aWords) { 63 if (!opener) 64 return; 65 var speller = opener.speller, 66 bodyDoc = window.frames[0].document, 67 sWords = aWords.join(" "); 68 bodyDoc.open(); 69 bodyDoc.write('<html>'); 70 bodyDoc.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'); 71 bodyDoc.write('<link rel="stylesheet" type="text/css" href="spellerStyle.css"/>'); 72 // bodyDoc.write('<body class="normalText">'); 73 bodyDoc.write('<body class="normalText" onLoad="document.forms[0].submit();">'); 74 bodyDoc.write('<p>' + window.parent.FCKLang.DlgSpellAddingWords + '<\/p>'); 75 bodyDoc.write('<form action="' + speller.spellCheckScript + '" method="post">'); 76 bodyDoc.write('<input type="hidden" name="addwords" value="1">'); 77 bodyDoc.write('<input type="hidden" name="words" value="' + encodeForPost(sWords) + '">'); 78 bodyDoc.write('<\/form><\/body><\/html>'); 79 bodyDoc.close(); 80 } 81 60 82 </script> 61 83 62 84 <html> -
editor/dialog/fck_spellerpages/spellerpages/spellChecker.js
20 20 this.popUpProps = null ; // by FredCK 21 21 // this.spellCheckScript = '/speller/server-scripts/spellchecker.php'; // by FredCK 22 22 //this.spellCheckScript = '/cgi-bin/spellchecker.pl'; 23 this.bUseAddButton = false; 24 this.OnFinished = null; // termination callback 25 this.OnUpdateOkBtn = null; // changes made callback 23 26 24 27 // values used to keep track of what happened to a word 25 28 this.replWordFlag = "R"; // single replace … … 28 31 this.ignrAllFlag = "IA"; // ignore all occurances 29 32 this.fromReplAll = "~RA"; // an occurance of a "replace all" word 30 33 this.fromIgnrAll = "~IA"; // an occurance of a "ignore all" word 34 // HTB 35 this.addFlag = "A"; // add to dictionary & so ignore all occurances 36 this.fromAddAll = "~A"; // an occurance of a 'add' word 37 31 38 // properties set at run time 32 39 this.wordFlags = new Array(); 33 40 this.currentTextIndex = 0; … … 42 49 this._spellcheck = _spellcheck; 43 50 this._getSuggestions = _getSuggestions; 44 51 this._setAsIgnored = _setAsIgnored; 52 this._setIgnoreAll = _setIgnoreAll; 45 53 this._getTotalReplaced = _getTotalReplaced; 46 54 this._setWordText = _setWordText; 47 55 this._getFormInputs = _getFormInputs; 56 this._addWords = _addWords; 48 57 49 58 // public methods 50 59 this.openChecker = openChecker; … … 57 66 this.replaceWord = replaceWord; 58 67 this.replaceAll = replaceAll; 59 68 this.terminateSpell = terminateSpell; 69 this.addWord = addWord; 70 this.closeSpeller = closeSpeller; 60 71 this.undo = undo; 61 72 62 73 // set the current window's "speller" property to the instance of this class. … … 99 110 100 111 // reset properties 101 112 this.wordWin.resetForm(); 113 this.controlWin.bUseAddButton = this.bUseAddButton; 102 114 this.controlWin.resetForm(); 103 115 this.currentTextIndex = 0; 104 116 this.currentWordIndex = 0; … … 135 147 } 136 148 137 149 function ignoreAll() { 150 this._setIgnoreAll(this.ignrAllFlag, this.fromIgnrAll); 151 } 152 153 function _setIgnoreAll(sWordFlag, sOtherOccurrencesFlag) { 154 138 155 var wi = this.currentWordIndex; 139 156 var ti = this.currentTextIndex; 140 157 if( !this.wordWin ) { … … 148 165 return false; 149 166 } 150 167 151 // set this word as an "ignore all" word.152 this._setAsIgnored( ti, wi, this.ignrAllFlag);168 // set this word as an "ignore all"/"add" word. 169 this._setAsIgnored( ti, wi, sWordFlag); 153 170 154 171 // loop through all the words after this word 155 172 for( var i = ti; i < this.wordWin.textInputs.length; i++ ) { 156 173 for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) { 157 174 if(( i == ti && j > wi ) || i > ti ) { 158 // future word: set as "from ignore all" if175 // future word: set as "from ignore all"/"from add" if 159 176 // 1) do not already have a flag and 160 177 // 2) have the same value as current word 161 178 if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl ) 162 179 && ( !this.wordFlags[i][j] )) { 163 this._setAsIgnored( i, j, this.fromIgnrAll);180 this._setAsIgnored( i, j, sOtherOccurrencesFlag); 164 181 } 165 182 } 166 183 } … … 172 189 return true; 173 190 } 174 191 192 function addWord() { 193 this._setIgnoreAll(this.addFlag, this.fromAddAll); 194 195 // Update external Ok button 196 if (typeof(this.OnUpdateOkBtn) == 'function') 197 this.OnUpdateOkBtn(true); 198 } 199 175 200 function replaceWord() { 176 201 var wi = this.currentWordIndex; 177 202 var ti = this.currentTextIndex; … … 190 215 if( txt.value ) { 191 216 var newspell = new String( txt.value ); 192 217 if( this._setWordText( ti, wi, newspell, this.replWordFlag )) { 218 // Update external Ok button 219 if (typeof(this.OnUpdateOkBtn) == 'function') 220 this.OnUpdateOkBtn(true); 221 // Move to next word 193 222 this.currentWordIndex++; 194 223 this._spellcheck(); 195 224 } … … 213 242 if( !txt.value ) return false; 214 243 var newspell = new String( txt.value ); 215 244 245 // Update external Ok button 246 if (typeof(this.OnUpdateOkBtn) == 'function') 247 this.OnUpdateOkBtn(true); 248 216 249 // set this word as a "replace all" word. 217 250 this._setWordText( ti, wi, newspell, this.replAllFlag ); 218 251 … … 239 272 240 273 function terminateSpell() { 241 274 // called when we have reached the end of the spell checking. 275 276 // Disable controls 277 this.controlWin.enableControls(false); 278 279 // Get total number of words replaced and an array of words added. 280 this._getTotalReplaced(); 281 282 // Determine message to display, must be done prior to this._addWords since 283 // it reloads the word window to post new spellings to the server. 242 284 var msg = ""; // by FredCK 243 var numrepl = this. _getTotalReplaced();285 var numrepl = this.nNumReplaced; 244 286 if( numrepl == 0 ) { 245 287 // see if there were no misspellings to begin with 246 288 if( !this.wordWin ) { … … 261 303 // msg += numrepl + " words changed."; // by FredCK 262 304 msg += FCKLang.DlgSpellManyChanges.replace( /%1/g, numrepl ) ; 263 305 } 264 if( msg ) { 306 this.sMessage = msg; 307 308 // If words have been added post to the server (then finish up), otherwise 309 // just finish up 310 if(this.aAddedWords.length) 311 this._addWords(); 312 else 313 this.closeSpeller(); 314 315 return true; 316 } 317 318 // Post user-added words to the server 319 function _addWords() { 320 // We're about to destroy the existing word window, so lose the reference to 321 // the object inside it 322 delete this.wordWin; 323 324 // this.spellCheckerWin is the FrameSet window containing spellchecker.html 325 // (as returned by window.open). It's first frame is the word window. 326 this.spellCheckerWin.postAddedWords(this.aAddedWords); 327 328 // The above posts the user-added words to the server. The response page 329 // from the server will include JavaScript to make a call back to this 330 // object's closeSpeller method 331 } 332 333 // Close the speller dialog 334 function closeSpeller() { 335 var numrepl = this.nNumReplaced; 336 if(this.sMessage) { 265 337 // msg += "\n"; // by FredCK 266 alert( msg);338 alert(this.sMessage); 267 339 } 268 340 269 341 if( numrepl > 0 ) { … … 282 354 // this.spellCheckerWin.close(); // by FredCK 283 355 if ( typeof( this.OnFinished ) == 'function' ) // by FredCK 284 356 this.OnFinished(numrepl) ; // by FredCK 285 286 return true;287 357 } 288 358 289 359 function undo() { … … 309 379 } while ( 310 380 this.wordWin.totalWords( this.currentTextIndex ) == 0 311 381 || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromIgnrAll 382 || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromAddAll 312 383 || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromReplAll 313 384 ); 314 385 … … 342 413 // ignore all: go through all the future occurances of the word 343 414 // and clear their flags 344 415 case this.ignrAllFlag : 416 case this.addFlag : 345 417 for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) { 346 418 for( j = 0; j < this.wordWin.totalWords( i ); j++ ) { 347 419 if(( i == text_idx && j >= idx ) || i > text_idx ) { … … 362 434 363 435 // For all four cases, clear the wordFlag of this word. re-start the process 364 436 this.wordFlags[text_idx][idx] = undefined; 437 438 // Update external Ok button 439 if (typeof(this.OnUpdateOkBtn) == 'function') { 440 // Check for replacements or added words 441 this._getTotalReplaced(); 442 var bChanges = (this.nNumReplaced || this.aAddedWords.length) ? true : false; 443 this.OnUpdateOkBtn(bChanges); 444 } 445 365 446 this._spellcheck(); 366 447 } 367 448 } … … 399 480 this.controlWin.evaluatedText.value = evalText; 400 481 ww.setFocus( this.currentTextIndex, this.currentWordIndex ); 401 482 this._getSuggestions( this.currentTextIndex, this.currentWordIndex ); 483 484 // Enable controls 485 this.controlWin.enableControls(true); 402 486 } 403 487 } 404 488 } … … 427 511 } 428 512 429 513 function _getTotalReplaced() { 430 var i_replaced = 0; 514 var i_replaced = 0, 515 aAddedWords = [], 516 oWordWin = this.wordWin; 431 517 for( var i = 0; i < this.wordFlags.length; i++ ) { 432 518 for( var j = 0; j < this.wordFlags[i].length; j++ ) { 433 519 if(( this.wordFlags[i][j] == this.replWordFlag ) … … 435 521 || ( this.wordFlags[i][j] == this.fromReplAll )) { 436 522 i_replaced++; 437 523 } 524 525 // Find words to be added to dictionary 526 if(this.wordFlags[i][j] == this.addFlag) { 527 var sWord = oWordWin.getTextVal(i,j); 528 aAddedWords.push(sWord); 529 } 438 530 } 439 531 } 440 return i_replaced; 532 this.aAddedWords = aAddedWords; 533 this.nNumReplaced = i_replaced; 441 534 } 442 535 443 536 function _setWordText( text_num, word_num, newText, flag ) { -
editor/dialog/fck_spellerpages/spellerpages/wordWindow.js
12 12 this._adjustIndexes = _adjustIndexes; 13 13 this._isWordChar = _isWordChar; 14 14 this._lastPos = _lastPos; 15 this._inTag = _inTag; 15 16 16 17 // public properties 17 18 this.wordChar = /[a-zA-Z]/; … … 153 154 154 155 //!!! plain text, or HTML mode? 155 156 d.writeln( '<div class="plainText">' ); 157 158 // Find the positions of the tags so we don't match text within a 159 // tag - otherwise it will attempt to put an <input> element in the 160 // middle of an image's ALT text for example. 161 var reTag = /<(\/?)(\w+)([^>]*)>/gi, 162 aTagStart = [], 163 aTagEnd = [], 164 nTags = 0, 165 aResult; 166 while((aResult = reTag.exec(wordtxt)) != null) { 167 var sTag = aResult[0]; 168 aTagStart[nTags] = aResult.index; 169 aTagEnd[nTags++] = aResult.index + sTag.length - 1; 170 } 171 this.aTagStart = aTagStart; 172 this.aTagEnd = aTagEnd; 173 156 174 // iterate through each occurrence of a misspelled word. 157 175 for( var i = 0; i < orig.length; i++ ) { 158 176 // find the position of the current misspelled word, … … 170 188 } while ( 171 189 this._isWordChar( before_char ) 172 190 || this._isWordChar( after_char ) 191 || this._inTag(begin_idx) 173 192 ); 174 193 175 194 // keep track of its position in the original text. 176 195 this.indexes[txtid][i] = begin_idx; 177 196 178 197 // write out the characters before the current misspelled word 179 for( var j = this._lastPos( txtid, i ); j < begin_idx; j++ ) { 180 // !!! html mode? make it html compatible 181 d.write( this.printForHtml( wordtxt.charAt( j ))); 182 } 198 var nEndOfLastWordIdx = this._lastPos(txtid, i); 199 var nLength = begin_idx - nEndOfLastWordIdx; 200 d.write(this.printForHtml(wordtxt.substr(nEndOfLastWordIdx, nLength))); 183 201 184 202 // write out the misspelled word. 185 203 d.write( this._wordInputStr( orig[i] )); … … 207 225 d.close(); 208 226 } 209 227 228 // determine if the position at which a word was found is in the middle of a tag 229 function _inTag(nStartPos) { 230 var aTagStart = this.aTagStart, 231 aTagEnd = this.aTagEnd, 232 nTags = aTagStart.length; 233 for(var nTag=0; nTag<nTags; nTag++) { 234 var nTagStart = aTagStart[nTag]; 235 if(nTagStart > nStartPos) 236 break; 237 if(nStartPos >= nTagStart && nStartPos <= aTagEnd[nTag]) 238 return true; 239 } 240 return false; 241 } 242 210 243 // return the character index in the full text after the last word we evaluated 211 244 function _lastPos( txtid, idx ) { 212 245 if( idx > 0 ) … … 216 249 } 217 250 218 251 function printForHtml( n ) { 252 253 // Remove active hyperlinks <a ...> and end tags </a> 254 n = n.replace( /<a\s[^>]*>/gi, "").replace( /<\/a>/gi, ""); 255 219 256 return n ; // by FredCK 220 257 /* 221 258 var htmlstr = n;