Ticket #3910: 3910.patch

File 3910.patch, 31.5 KB (added by Harry, 15 years ago)

patch file for diffs from http://svn.fckeditor.net/FCKeditor/tags/2.6.4

  • editor/dialog/fck_spellerpages.html

     
    3232
    3333var oEditor = window.parent.InnerDialogLoaded() ;
    3434var FCKLang = oEditor.FCKLang ;
     35var oSpeller;
    3536
    3637window.onload = function()
    3738{
    3839        document.getElementById('txtHtml').value = oEditor.FCK.EditorDocument.body.innerHTML ;
    39 
    40         var oSpeller = new spellChecker( document.getElementById('txtHtml') ) ;
     40       
     41        oSpeller = new spellChecker( document.getElementById('txtHtml') ) ;
    4142        oSpeller.spellCheckScript = oEditor.FCKConfig.SpellerPagesServerScript || 'server-scripts/spellchecker.php' ;
    4243        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();
    4447}
    4548
    4649function OnSpellerControlsLoad( controlsWindow )
     
    6164        window.parent.Cancel() ;
    6265}
    6366
     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 */
     74function 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 */
     85function Ok() {
     86        // Apply any spelling changes made then close the dialog
     87        oSpeller.terminateSpell();
     88}
    6489                </script>
    6590        </head>
    6691        <body style="OVERFLOW: hidden" scroll="no" style="padding:0px;">
  • editor/dialog/fck_spellerpages/spellerpages/controls.html

     
    4646        }
    4747}
    4848
     49function addWord() {
     50        if(spellerObject)
     51                spellerObject.addWord();
     52}
     53
    4954function suggText() {
    5055        if( controlWindowObj ) {
    5156                controlWindowObj.setSuggestedText();
     
    110115                                                <table border="0" cellpadding="0" cellspacing="0" border="0">
    111116                                                        <tr>
    112117                                                                <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>
    114119                                                                </td>
    115120                                                                <td>&nbsp;&nbsp;</td>
    116121                                                                <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>
    118123                                                                </td>
    119124                                                        </tr>
    120125                                                        <tr>
     
    122127                                                        </tr>
    123128                                                        <tr>
    124129                                                                <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>
    126131                                                                </td>
    127132                                                                <td>&nbsp;&nbsp;</td>
    128133                                                                <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>
    130135                                                                </td>
    131136                                                        </tr>
    132137                                                        <tr>
     
    134139                                                        </tr>
    135140                                                        <tr>
    136141                                                                <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>
    139143                                                                </td>
    140144                                                                <td>&nbsp;&nbsp;</td>
    141145                                                                <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>
    145147                                                                </td>
    146148                                                        </tr>
    147149                                                </table>
  • editor/dialog/fck_spellerpages/spellerpages/controlWindow.js

     
    44function controlWindow( controlForm ) {
    55        // private properties
    66        this._form = controlForm;
     7        this.bUndoDisabled = true;
     8        this.bControlsDisabled = true;
     9        this.bUseAddButton = false;
     10       
     11        // private methods
     12        this._setButtons = _setButtons;
    713
    814        // public properties
    915        this.windowType = "controlWindow";
     
    2329        this.setSuggestedText = setSuggestedText;
    2430        this.enableUndo = enableUndo;
    2531        this.disableUndo = disableUndo;
     32        this.enableControls = enableControls;
    2633}
    2734
    2835function resetForm() {
     
    7178}
    7279
    7380function 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();
    7983}
    8084
    8185function 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();
    8788}
     89
     90function enableControls(bEnable) {
     91        this.bControlsDisabled = bEnable ? false : true;
     92        this._setButtons();
     93}
     94
     95function _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
     3use CGI qw/ :standard /;
     4use File::Temp qw/ tempfile tempdir /;
     5
     6# my $spellercss = '/speller/spellerStyle.css';                                 # by FredCK
     7my $spellercss = '../spellerStyle.css';                                                 # by FredCK
     8# my $wordWindowSrc = '/speller/wordWindow.js';                                 # by FredCK
     9my $wordWindowSrc = '../wordWindow.js';                                                 # by FredCK
     10my @textinputs = param( 'textinputs[]' ); # array
     11# my $aspell_cmd = 'aspell';                                                                    # by FredCK (for Linux)
     12my $aspell_cmd = '"C:\Program Files\Aspell\bin\aspell.exe"';    # by FredCK (for Windows)
     13my $lang = 'en_US';
     14# my $aspell_opts = "-a --lang=$lang --encoding=utf-8";                 # by FredCK
     15my $aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt";           # by FredCK
     16my $input_separator = "A";
     17
     18# TBD: Define this function for your server environment
     19sub 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
     26sub 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
     33if(defined(param("addwords"))) {
     34        &addWords();
     35        exit;
     36}
     37
     38# set the 'wordtext' JavaScript variable to the submitted text.
     39sub printTextVar {
     40        for( my $i = 0; $i <= $#textinputs; $i++ ) {
     41                print "textinputs[$i] = decodeURIComponent('" . escapeQuote( $textinputs[$i] ) . "')\n";
     42        }
     43}
     44
     45sub printTextIdxDecl {
     46        my $idx = shift;
     47        print "words[$idx] = [];\n";
     48        print "suggs[$idx] = [];\n";
     49}
     50
     51sub printWordsElem {
     52        my( $textIdx, $wordIdx, $word ) = @_;
     53        print "words[$textIdx][$wordIdx] = '" . $word . "';\n";
     54}
     55
     56sub 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
     68sub 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
     134sub escapeQuote {
     135        my $str = shift;
     136        $str =~ s/'/\\'/g;
     137        return $str;
     138}
     139
     140sub handleError {
     141        my $err = shift;
     142        print "error = '" . escapeQuote( $err ) . "';\n";
     143}
     144
     145sub 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
     156sub 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
     170sub printAddWordsOutput() {
     171        my $bResult = shift;
     172       
     173        print <<EOF;
     174Content-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">
     182function close_spell() {        // calls the closeSpeller() function in the parent frameset
     183if(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>&nbsp;</p>
     190</body></html>
     191EOF
     192}
     193
     194# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
     195# Display HTML
     196# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
     197
     198print <<EOF;
     199Content-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">
     207var suggs = new Array();
     208var words = new Array();
     209var textinputs = new Array();
     210var error;
     211EOF
     212
     213printTextVar();
     214
     215printCheckerResults();
     216
     217print <<EOF;
     218var wordWindowObj = new wordWindow();
     219wordWindowObj.originalSpellings = words;
     220wordWindowObj.suggestions = suggs;
     221wordWindowObj.textInputs = textinputs;
     222
     223
     224function 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">
     246wordWindowObj.writeBody();
     247</script>
     248
     249</body>
     250</html>
     251EOF
     252 No newline at end of file
  • editor/dialog/fck_spellerpages/spellerpages/spellchecker.html

     
    5757        bodyDoc.write('<\/html>');
    5858        bodyDoc.close();
    5959}
     60
     61// post the words the user added to the server
     62function 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
    6082</script>
    6183
    6284<html>
  • editor/dialog/fck_spellerpages/spellerpages/spellChecker.js

     
    2020        this.popUpProps = null ;                                                                                                                                        // by FredCK
    2121//      this.spellCheckScript = '/speller/server-scripts/spellchecker.php';             // by FredCK
    2222        //this.spellCheckScript = '/cgi-bin/spellchecker.pl';
     23        this.bUseAddButton = false;
     24        this.OnFinished = null;                 // termination callback
     25        this.OnUpdateOkBtn = null;      // changes made callback
    2326
    2427        // values used to keep track of what happened to a word
    2528        this.replWordFlag = "R";        // single replace
     
    2831        this.ignrAllFlag = "IA";        // ignore all occurances
    2932        this.fromReplAll = "~RA";       // an occurance of a "replace all" word
    3033        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
    3138        // properties set at run time
    3239        this.wordFlags = new Array();
    3340        this.currentTextIndex = 0;
     
    4249        this._spellcheck = _spellcheck;
    4350        this._getSuggestions = _getSuggestions;
    4451        this._setAsIgnored = _setAsIgnored;
     52        this._setIgnoreAll = _setIgnoreAll;
    4553        this._getTotalReplaced = _getTotalReplaced;
    4654        this._setWordText = _setWordText;
    4755        this._getFormInputs = _getFormInputs;
     56        this._addWords = _addWords;
    4857
    4958        // public methods
    5059        this.openChecker = openChecker;
     
    5766        this.replaceWord = replaceWord;
    5867        this.replaceAll = replaceAll;
    5968        this.terminateSpell = terminateSpell;
     69        this.addWord = addWord;
     70        this.closeSpeller = closeSpeller;
    6071        this.undo = undo;
    6172
    6273        // set the current window's "speller" property to the instance of this class.
     
    99110
    100111        // reset properties
    101112        this.wordWin.resetForm();
     113        this.controlWin.bUseAddButton = this.bUseAddButton;
    102114        this.controlWin.resetForm();
    103115        this.currentTextIndex = 0;
    104116        this.currentWordIndex = 0;
     
    135147}
    136148
    137149function ignoreAll() {
     150        this._setIgnoreAll(this.ignrAllFlag, this.fromIgnrAll);
     151}
     152
     153function _setIgnoreAll(sWordFlag, sOtherOccurrencesFlag) {
     154
    138155        var wi = this.currentWordIndex;
    139156        var ti = this.currentTextIndex;
    140157        if( !this.wordWin ) {
     
    148165                return false;
    149166        }
    150167
    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);
    153170
    154171        // loop through all the words after this word
    155172        for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
    156173                for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
    157174                        if(( i == ti && j > wi ) || i > ti ) {
    158                                 // future word: set as "from ignore all" if
     175                                // future word: set as "from ignore all"/"from add" if
    159176                                // 1) do not already have a flag and
    160177                                // 2) have the same value as current word
    161178                                if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
    162179                                && ( !this.wordFlags[i][j] )) {
    163                                         this._setAsIgnored( i, j, this.fromIgnrAll );
     180                                        this._setAsIgnored( i, j, sOtherOccurrencesFlag);
    164181                                }
    165182                        }
    166183                }
     
    172189        return true;
    173190}
    174191
     192function 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
    175200function replaceWord() {
    176201        var wi = this.currentWordIndex;
    177202        var ti = this.currentTextIndex;
     
    190215        if( txt.value ) {
    191216                var newspell = new String( txt.value );
    192217                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
    193222                        this.currentWordIndex++;
    194223                        this._spellcheck();
    195224                }
     
    213242        if( !txt.value ) return false;
    214243        var newspell = new String( txt.value );
    215244
     245        // Update external Ok button
     246        if (typeof(this.OnUpdateOkBtn) == 'function')
     247                this.OnUpdateOkBtn(true);
     248
    216249        // set this word as a "replace all" word.
    217250        this._setWordText( ti, wi, newspell, this.replAllFlag );
    218251
     
    239272
    240273function terminateSpell() {
    241274        // 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.
    242284        var msg = "";           // by FredCK
    243         var numrepl = this._getTotalReplaced();
     285        var numrepl = this.nNumReplaced;
    244286        if( numrepl == 0 ) {
    245287                // see if there were no misspellings to begin with
    246288                if( !this.wordWin ) {
     
    261303//              msg += numrepl + " words changed.";     // by FredCK
    262304                msg += FCKLang.DlgSpellManyChanges.replace( /%1/g, numrepl ) ;
    263305        }
    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
     319function _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
     334function closeSpeller() {
     335        var numrepl = this.nNumReplaced;
     336        if(this.sMessage) {
    265337//              msg += "\n";    // by FredCK
    266                 alert( msg );
     338                alert(this.sMessage);
    267339        }
    268340
    269341        if( numrepl > 0 ) {
     
    282354//      this.spellCheckerWin.close();                                   // by FredCK
    283355        if ( typeof( this.OnFinished ) == 'function' )  // by FredCK
    284356                this.OnFinished(numrepl) ;                                      // by FredCK
    285 
    286         return true;
    287357}
    288358
    289359function undo() {
     
    309379                } while (
    310380                        this.wordWin.totalWords( this.currentTextIndex ) == 0
    311381                        || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromIgnrAll
     382                        || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromAddAll
    312383                        || this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromReplAll
    313384                );
    314385
     
    342413                        // ignore all: go through all the future occurances of the word
    343414                        // and clear their flags
    344415                        case this.ignrAllFlag :
     416                        case this.addFlag :
    345417                                for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
    346418                                        for( j = 0; j < this.wordWin.totalWords( i ); j++ ) {
    347419                                                if(( i == text_idx && j >= idx ) || i > text_idx ) {
     
    362434
    363435                // For all four cases, clear the wordFlag of this word. re-start the process
    364436                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
    365446                this._spellcheck();
    366447        }
    367448}
     
    399480                        this.controlWin.evaluatedText.value = evalText;
    400481                        ww.setFocus( this.currentTextIndex, this.currentWordIndex );
    401482                        this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
     483
     484                        // Enable controls
     485                        this.controlWin.enableControls(true);
    402486                }
    403487        }
    404488}
     
    427511}
    428512
    429513function _getTotalReplaced() {
    430         var i_replaced = 0;
     514        var i_replaced = 0,
     515                aAddedWords = [],
     516                oWordWin = this.wordWin;
    431517        for( var i = 0; i < this.wordFlags.length; i++ ) {
    432518                for( var j = 0; j < this.wordFlags[i].length; j++ ) {
    433519                        if(( this.wordFlags[i][j] == this.replWordFlag )
     
    435521                        || ( this.wordFlags[i][j] == this.fromReplAll )) {
    436522                                i_replaced++;
    437523                        }
     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                        }
    438530                }
    439531        }
    440         return i_replaced;
     532        this.aAddedWords = aAddedWords;
     533        this.nNumReplaced = i_replaced;
    441534}
    442535
    443536function _setWordText( text_num, word_num, newText, flag ) {
  • editor/dialog/fck_spellerpages/spellerpages/wordWindow.js

     
    1212        this._adjustIndexes = _adjustIndexes;
    1313        this._isWordChar = _isWordChar;
    1414        this._lastPos = _lastPos;
     15        this._inTag = _inTag;
    1516
    1617        // public properties
    1718        this.wordChar = /[a-zA-Z]/;
     
    153154
    154155                        //!!! plain text, or HTML mode?
    155156                        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               
    156174                        // iterate through each occurrence of a misspelled word.
    157175                        for( var i = 0; i < orig.length; i++ ) {
    158176                                // find the position of the current misspelled word,
     
    170188                                } while (
    171189                                        this._isWordChar( before_char )
    172190                                        || this._isWordChar( after_char )
     191                                        || this._inTag(begin_idx)
    173192                                );
    174193
    175194                                // keep track of its position in the original text.
    176195                                this.indexes[txtid][i] = begin_idx;
    177196
    178197                                // 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)));
    183201
    184202                                // write out the misspelled word.
    185203                                d.write( this._wordInputStr( orig[i] ));
     
    207225        d.close();
    208226}
    209227
     228// determine if the position at which a word was found is in the middle of a tag
     229function _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
    210243// return the character index in the full text after the last word we evaluated
    211244function _lastPos( txtid, idx ) {
    212245        if( idx > 0 )
     
    216249}
    217250
    218251function printForHtml( n ) {
     252
     253        // Remove active hyperlinks <a ...> and end tags </a>
     254        n = n.replace( /<a\s[^>]*>/gi, "").replace( /<\/a>/gi, "");
     255
    219256        return n ;              // by FredCK
    220257/*
    221258        var htmlstr = n;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy