Ticket #4814: #4814.diff

File #4814.diff, 11.1 KB (added by WebSpellChecker.net, 14 years ago)

patch_4814

  • C:\www\home\spellclient.int\www\CKEditor

    old new  
    1212{
    1313        var commandName         = 'scaytcheck',
    1414                openPage                = '';
     15        // Checks if a value exists in an array
     16        function in_array(needle, haystack)
     17    {
     18            var found = false, key;
     19            for (key in haystack)
     20        {
     21                if ((haystack[key] === needle) || ( haystack[key] == needle))
     22            {
     23                    found = true;
     24                    break;
     25                }
     26            }
     27            return found;
     28        }
    1529
    1630        var onEngineLoad = function()
    1731        {
     
    2438                        oParams.srcNodeRef = editor.document.getWindow().$.frameElement;                // Get the iframe.
    2539                        // syntax : AppName.AppVersion@AppRevision
    2640                        oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;
    27 
    28                         oParams.customerid = editor.config.scayt_customerid  || "1:11111111111111111111111111111111111111";
    29                         oParams.customDictionaryName = editor.config.scayt_customDictionaryName;
     41                        oParams.customerid = editor.config.scayt_customerid  || "";
     42                        oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds;
    3043                        oParams.userDictionaryName = editor.config.scayt_userDictionaryName;
    31                         oParams.defLang = editor.scayt_defLang;
     44                        oParams.sLang = editor.config.scayt_sLang || "en_US";
    3245
    3346                        if ( CKEDITOR._scaytParams )
    3447                        {
     
    5164
    5265                        plugin.instances[ editor.name ] = scayt_control;
    5366
     67                        //window.scayt.uiTags
     68                        var menuGroup = 'scaytButton';
     69                        var uiTabs = window.scayt.uiTags;
     70                        var fTabs  = [];
     71                       
     72                        for (var i = 0,l=4; i<l; i++)
     73                                fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
     74                       
     75                        plugin.uiTabs = fTabs;
     76                       
    5477                        try {
    55                                 scayt_control.setDisabled( scayt_control.paused === false );                            // I really don't know why it causes JS error in IE
     78                                scayt_control.setDisabled( scayt_control.paused === false );
    5679                        } catch (e) {}
    5780                        editor.fire( 'showScaytState' );
    5881                };
     
    90113                                }
    91114                        });
    92115
     116
     117                editor.on( 'destroy', function()
     118        {
     119            plugin.getScayt( editor ).destroy();
     120        });
    93121                // Listen to data manipulation to reflect scayt markup.
    94122                editor.on( 'afterSetData', function()
    95123                        {
     
    116144                                }
    117145                        }, this, null, 50 );
    118146
     147        editor.on( 'insertHtml', function()
     148        {
     149           
     150            var scayt_instance = plugin.getScayt( editor );
     151            if ( plugin.isScaytEnabled( editor ) )
     152            {
     153                // Unlock the selection before reload, SCAYT will take
     154                // care selection update.
     155                if ( CKEDITOR.env.ie )
     156                    editor.getSelection().unlock( true );
     157
     158                // Swallow any SCAYT engine errors.
     159                try{
     160                    scayt_instance.refresh();
     161                }catch( er )
     162                {}
     163            }
     164        }, this, null, 50 );
     165
     166
     167
    119168                editor.on( 'scaytDialog', function( ev )        // Communication with dialog.
    120169                        {
    121170                                ev.data.djConfig = window.djConfig;
     
    300349
    301350                        // Add Options dialog.
    302351                        CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
     352                        // read ui tags
     353                        var confuiTabs = editor.config.scayt_uiTabs || "1,1,1";
     354                        var uiTabs =[];
     355                        // string tp array convert
     356                        confuiTabs = confuiTabs.split(",");
     357                        // check array length ! allwaays must be 3 filled with 1 or 0
     358                        for (var i=0,l=3; i<l; i++){
     359                                var flag = parseInt(confuiTabs[i] || "1" ,10);
     360                                uiTabs.push(  flag  );
     361                        }
     362                       
    303363
    304364                        var menuGroup = 'scaytButton';
    305365                        editor.addMenuGroup( menuGroup );
    306                         editor.addMenuItems(
    307                                 {
    308                                         scaytToggle :
     366                        // combine menu items to render
     367                        var uiMuneItems = {};
     368                       
     369                        // allways added
     370                        uiMuneItems.scaytToggle =
    309371                                        {
    310372                                                label : editor.lang.scayt.enable,
    311373                                                command : commandName,
    312374                                                group : menuGroup
    313                                         },
     375                                };
    314376
    315                                         scaytOptions :
     377                        if (uiTabs[0] == 1)
     378                                uiMuneItems.scaytOptions =
    316379                                        {
    317380                                                label : editor.lang.scayt.options,
    318381                                                group : menuGroup,
     
    321384                                                        openPage = 'options';
    322385                                                        editor.openDialog( commandName );
    323386                                                }
    324                                         },
     387                                };
    325388
    326                                         scaytLangs :
     389                        if (uiTabs[1] == 1)
     390                                uiMuneItems.scaytLangs =
    327391                                        {
    328392                                                label : editor.lang.scayt.langs,
    329393                                                group : menuGroup,
     
    332396                                                        openPage = 'langs';
    333397                                                        editor.openDialog( commandName );
    334398                                                }
    335                                         },
    336 
    337                                         scaytAbout :
     399                                };
     400                        if (uiTabs[2] == 1)
     401                                uiMuneItems.scaytDict =
     402                                {
     403                                        label : editor.lang.scayt.dictionariesTab,
     404                                        group : menuGroup,
     405                                        onClick : function()
     406                                        {
     407                                                openPage = 'dictionaries';
     408                                                editor.openDialog( commandName );
     409                                        }
     410                                };
     411                        // allways added
     412                        uiMuneItems.scaytAbout =
    338413                                        {
    339414                                                label : editor.lang.scayt.about,
    340415                                                group : menuGroup,
     
    344419                                                        editor.openDialog( commandName );
    345420                                                }
    346421                                        }
    347                                 });
     422                        ;
     423                       
     424                        uiTabs[3] = 1; // about us tab is allways on
     425                        plugin.uiTabs = uiTabs;
     426                       
     427                        editor.addMenuItems( uiMuneItems );
    348428
    349429                                editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
    350430                                        {
     
    358438                                                                this.setState( command.state );
    359439                                                        },
    360440                                                        this);
     441                                                       
    361442                                        },
    362443                                        onMenu : function()
    363444                                        {
     
    367448
    368449                                                        return {
    369450                                                                scaytToggle : CKEDITOR.TRISTATE_OFF,
    370                                                                 scaytOptions : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
    371                                                                 scaytLangs : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
    372                                                                 scaytAbout : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
     451                                                                        scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
     452                                                                        scaytLangs   : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
     453                                                                        scaytDict    : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
     454                                                                        scaytAbout   : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
    373455                                                        };
    374456                                                }
    375457                                        });
     
    379461                        {
    380462                                editor.contextMenu.addListener( function( element )
    381463                                        {
     464                                               
    382465                                                if ( !( plugin.isScaytEnabled( editor ) && element ) )
    383466                                                        return null;
    384467
     
    394477                                                if (!items_suggestion || !items_suggestion.length )
    395478                                                        return null;
    396479                                                // Remove unused commands and menuitems
     480
    397481                                                for ( i in moreSuggestions )
    398482                                                {
    399483                                                        delete editor._.menuItems[ i ];
     
    407491                                                moreSuggestions = {};           // Reset items.
    408492                                                mainSuggestions = {};
    409493
    410                                                 var moreSuggestionsUnable = false;
     494                                                var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on";
     495                                                var moreSuggestionsUnableAdded = false;
     496                                                var maxSuggestions = ( editor.config.scayt_maxSuggestions <= 0)
     497                                                                                          ? items_suggestion.length
     498                                                                                          : editor.config.scayt_maxSuggestions;
     499                                                var contextCommands = editor.config.scayt_contextCommands || "all";
     500                                                contextCommands = contextCommands.split("|");
    411501
    412502                                                for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
    413503                                                {
     
    422512                                                                        };
    423513                                                                })( element.$, items_suggestion[i] );
    424514
    425                                                         if ( i < editor.config.scayt_maxSuggestions )
     515                                                        if ( i < maxSuggestions )
    426516                                                        {
    427517                                                                addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
    428518                                                                        commandName, exec, 'scayt_suggest', i + 1 );
    429519                                                                _r[ commandName ] = CKEDITOR.TRISTATE_OFF;
    430520                                                                mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
    431521                                                        }
    432                                                         else
     522                                                        else if ( moreSuggestionsUnable == "on" )
    433523                                                        {
     524
    434525                                                                addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
    435526                                                                        commandName, exec, 'scayt_moresuggest', i + 1 );
    436527                                                                moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
    437                                                                 moreSuggestionsUnable = true;
     528                                                                moreSuggestionsUnableAdded = true;
     529
     530
     531
     532
    438533                                                        }
    439534                                                }
    440                                                 if ( moreSuggestionsUnable )
     535
     536                                                if ( moreSuggestionsUnableAdded ){
    441537                                                        // Rgister the More suggestions group;
    442538                                                        editor.addMenuItem( 'scayt_moresuggest',
    443539                                                                {
     
    449545                                                                                return moreSuggestions;
    450546                                                                        }
    451547                                                                });
     548                            mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
    452549
     550                                                }
    453551
    454                                                 var ignore_command =
    455                                                 {
    456                                                         exec: function()
     552
     553                                               
     554                                                if ( in_array( "all",contextCommands )  || in_array("ignore",contextCommands)  )
    457555                                                        {
     556                                                        var ignore_command = {
     557                                                                exec: function(){
    458558                                                                scayt_control.ignore( element.$ );
    459559                                                        }
    460560                                                };
    461                                                 var ignore_all_command =
    462                                                 {
    463                                                         exec: function()
     561                                                        addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);
     562                                                        mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF;
     563                                                }
     564                                               
     565                                                if ( in_array( "all",contextCommands )  || in_array("ignoreall",contextCommands)  )
    464566                                                        {
     567                                                        var ignore_all_command = {
     568                                                                exec: function(){
    465569                                                                scayt_control.ignoreAll( element.$ );
    466570                                                        }
    467571                                                };
    468                                                 var addword_command =
    469                                                 {
    470                                                         exec: function()
     572                                                        addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
     573                                                        mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;
     574                                                }
     575                                               
     576                                                if ( in_array( "all",contextCommands )  || in_array("add",contextCommands)  )
    471577                                                        {
     578                                                        var addword_command = {
     579                                                                exec: function(){
    472580                                                                window.scayt.addWordToUserDictionary( element.$ );
    473581                                                        }
    474582                                                };
    475 
    476                                                 addButtonCommand( editor, 'ignore', editor.lang.scayt.ignore,
    477                                                         'scayt_ignore', ignore_command, 'scayt_control', 1);
    478                                                 addButtonCommand( editor, 'ignore_all', editor.lang.scayt.ignoreAll,
    479                                                         'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
    480                                                 addButtonCommand( editor, 'add_word', editor.lang.scayt.addWord,
    481                                                         'scayt_add_word', addword_command, 'scayt_control', 3);
    482 
    483                                                 mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
    484                                                 mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
    485                                                 mainSuggestions[ 'scayt_ignore_all' ] = CKEDITOR.TRISTATE_OFF;
     583                                                        addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
    486584                                                mainSuggestions[ 'scayt_add_word' ] = CKEDITOR.TRISTATE_OFF;
     585                                                }
    487586
    488587                                                if ( scayt_control.fireOnContextMenu )
    489588                                                        scayt_control.fireOnContextMenu( editor );
     
    507606                }
    508607        });
    509608})();
    510 
    511 CKEDITOR.config.scayt_maxSuggestions =  5;
    512 CKEDITOR.config.scayt_autoStartup = false;
     609CKEDITOR.config.scayt_maxSuggestions =  CKEDITOR.config.scayt_maxSuggestions || 5;
     610CKEDITOR.config.scayt_autoStartup = (typeof CKEDITOR.config.scayt_autoStartup !== 'undefined') ? CKEDITOR.config.scayt_autoStartup : false;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy