Ticket #4814: #4814_3.patch

File #4814_3.patch, 54.1 KB (added by WebSpellChecker.net, 14 years ago)

final patch

  • plugin.js

     
    44*/
    55
    66/**
    7  * @fileOverview Spell Check As You Type (SCAYT).
    8  * Button name : Scayt.
    9  */
     7* @fileOverview Spell Check As You Type (SCAYT).
     8* Button name : Scayt.
     9*/
    1010
    1111(function()
    1212{
    13         var commandName         = 'scaytcheck',
    14                 openPage                = '';
     13    var commandName     = 'scaytcheck',
     14        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    }
     29   
     30    var onEngineLoad = function()
     31    {
     32        var editor = this;
    1533
    16         var onEngineLoad = function()
    17         {
    18                 var editor = this;
     34        var createInstance = function() // Create new instance every time Document is created.
     35        {
     36            // Initialise Scayt instance.
     37            var oParams = {};
     38            oParams.srcNodeRef = editor.document.getWindow().$.frameElement;            // Get the iframe.
     39            // syntax : AppName.AppVersion@AppRevision
     40            oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;
     41            oParams.customerid = editor.config.scayt_customerid  || "";
     42            oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds;
     43            oParams.userDictionaryName = editor.config.scayt_userDictionaryName;
     44            oParams.sLang = editor.config.scayt_sLang || "en_US";
     45           
     46            if ( CKEDITOR._scaytParams )
     47            {
     48                for ( var k in CKEDITOR._scaytParams )
     49                {
     50                    oParams[ k ] = CKEDITOR._scaytParams[ k ];
     51                }
     52            }
    1953
    20                 var createInstance = function() // Create new instance every time Document is created.
    21                 {
    22                         // Initialise Scayt instance.
    23                         var oParams = {};
    24                         oParams.srcNodeRef = editor.document.getWindow().$.frameElement;                // Get the iframe.
    25                         // syntax : AppName.AppVersion@AppRevision
    26                         oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;
     54            var scayt_control = new window.scayt( oParams );
    2755
    28                         oParams.customerid = editor.config.scayt_customerid  || "1:11111111111111111111111111111111111111";
    29                         oParams.customDictionaryName = editor.config.scayt_customDictionaryName;
    30                         oParams.userDictionaryName = editor.config.scayt_userDictionaryName;
    31                         oParams.defLang = editor.scayt_defLang;
     56            // Copy config.
     57            var lastInstance = plugin.instances[ editor.name ];
     58            if ( lastInstance )
     59            {
     60                scayt_control.sLang = lastInstance.sLang;
     61                scayt_control.option( lastInstance.option() );
     62                scayt_control.paused = lastInstance.paused;
     63            }
    3264
    33                         if ( CKEDITOR._scaytParams )
    34                         {
    35                                 for ( var k in CKEDITOR._scaytParams )
    36                                 {
    37                                         oParams[ k ] = CKEDITOR._scaytParams[ k ];
    38                                 }
    39                         }
     65            plugin.instances[ editor.name ] = scayt_control;
     66           
     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           
     77            try {
     78                scayt_control.setDisabled( scayt_control.paused === false );
     79            } catch (e) {}
     80            editor.fire( 'showScaytState' );
     81        };
    4082
    41                         var scayt_control = new window.scayt( oParams );
     83        editor.on( 'contentDom', createInstance );
     84        editor.on( 'contentDomUnload', function()
     85            {
     86                // Remove scripts.
     87                var scripts = CKEDITOR.document.getElementsByTag( 'script' ),
     88                    scaytIdRegex =  /^dojoIoScript(\d+)$/i,
     89                    scaytSrcRegex =  /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;
    4290
    43                         // Copy config.
    44                         var     lastInstance = plugin.instances[ editor.name ];
    45                         if ( lastInstance )
    46                         {
    47                                 scayt_control.sLang = lastInstance.sLang;
    48                                 scayt_control.option( lastInstance.option() );
    49                                 scayt_control.paused = lastInstance.paused;
    50                         }
     91                for ( var i=0; i < scripts.count(); i++ )
     92                {
     93                    var script = scripts.getItem( i ),
     94                        id = script.getId(),
     95                        src = script.getAttribute( 'src' );
    5196
    52                         plugin.instances[ editor.name ] = scayt_control;
     97                    if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))
     98                        script.remove();
     99                }
     100            });
    53101
    54                         try {
    55                                 scayt_control.setDisabled( scayt_control.paused === false );                            // I really don't know why it causes JS error in IE
    56                         } catch (e) {}
    57                         editor.fire( 'showScaytState' );
    58                 };
     102        editor.on( 'beforeCommandExec', function( ev )          // Disable SCAYT before Source command execution.
     103        {
     104            if ( (ev.data.name == 'source' ||  ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )
     105            {
     106                var scayt_instanse = plugin.getScayt( editor );
     107                if ( scayt_instanse )
     108                {
     109                    scayt_instanse.paused = !scayt_instanse.disabled;
     110                    scayt_instanse.destroy();
     111                    delete plugin.instances[ editor.name ];
     112                }
     113            }
     114        });
     115       
    59116
    60                 editor.on( 'contentDom', createInstance );
    61                 editor.on( 'contentDomUnload', function()
    62                         {
    63                                 // Remove scripts.
    64                                 var scripts = CKEDITOR.document.getElementsByTag( 'script' ),
    65                                         scaytIdRegex =  /^dojoIoScript(\d+)$/i,
    66                                         scaytSrcRegex =  /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;
     117        editor.on( 'destroy', function()
     118        {
     119            plugin.getScayt( editor ).destroy();
     120        });
     121        // Listen to data manipulation to reflect scayt markup.
     122        editor.on( 'afterSetData', function()
     123        {
     124            if ( plugin.isScaytEnabled( editor ) )
     125                plugin.getScayt( editor ).refresh();
     126        });
    67127
    68                                 for ( var i=0; i < scripts.count(); i++ )
    69                                 {
    70                                         var script = scripts.getItem( i ),
    71                                                 id = script.getId(),
    72                                                 src = script.getAttribute( 'src' );
     128        // Reload spell-checking for current word after insertion completed.
     129        editor.on( 'insertElement', function()
     130        {
     131            var scayt_instance = plugin.getScayt( editor );
     132            if ( plugin.isScaytEnabled( editor ) )
     133            {
     134                // Unlock the selection before reload, SCAYT will take
     135                // care selection update.
     136                if ( CKEDITOR.env.ie )
     137                    editor.getSelection().unlock( true );
    73138
    74                                         if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))
    75                                                 script.remove();
    76                                 }
    77                         });
     139                // Swallow any SCAYT engine errors.
     140                try{
     141                    scayt_instance.refresh();
     142                }catch( er )
     143                {}
     144            }
     145        }, this, null, 50 );
    78146
    79                 editor.on( 'beforeCommandExec', function( ev )          // Disable SCAYT before Source command execution.
    80                         {
    81                                 if ( (ev.data.name == 'source' ||  ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )
    82                                 {
    83                                         var scayt_instanse = plugin.getScayt( editor );
    84                                         if ( scayt_instanse )
    85                                         {
    86                                                 scayt_instanse.paused = !scayt_instanse.disabled;
    87                                                 scayt_instanse.destroy();
    88                                                 delete plugin.instances[ editor.name ];
    89                                         }
    90                                 }
    91                         });
     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 );
    92157
    93                 // Listen to data manipulation to reflect scayt markup.
    94                 editor.on( 'afterSetData', function()
    95                         {
    96                                 if ( plugin.isScaytEnabled( editor ) )
    97                                         plugin.getScayt( editor ).refresh();
    98                         });
     158                // Swallow any SCAYT engine errors.
     159                try{
     160                    scayt_instance.refresh();
     161                }catch( er )
     162                {}
     163            }
     164        }, this, null, 50 );
    99165
    100                 // Reload spell-checking for current word after insertion completed.
    101                 editor.on( 'insertElement', function()
    102                         {
    103                                 var scayt_instance = plugin.getScayt( editor );
    104                                 if ( plugin.isScaytEnabled( editor ) )
    105                                 {
    106                                         // Unlock the selection before reload, SCAYT will take
    107                                         // care selection update.
    108                                         if ( CKEDITOR.env.ie )
    109                                                 editor.getSelection().unlock( true );
    110166
    111                                         // Swallow any SCAYT engine errors.
    112                                         try{
    113                                                 scayt_instance.refresh();
    114                                         }catch( er )
    115                                         {}
    116                                 }
    117                         }, this, null, 50 );
    118167
    119                 editor.on( 'scaytDialog', function( ev )        // Communication with dialog.
    120                         {
    121                                 ev.data.djConfig = window.djConfig;
    122                                 ev.data.scayt_control = plugin.getScayt( editor );
    123                                 ev.data.tab = openPage;
    124                                 ev.data.scayt = window.scayt;
    125                         });
     168        editor.on( 'scaytDialog', function( ev )        // Communication with dialog.
     169        {
     170            ev.data.djConfig = window.djConfig;
     171            ev.data.scayt_control = plugin.getScayt( editor );
     172            ev.data.tab = openPage;
     173            ev.data.scayt = window.scayt;
     174        });
    126175
    127                 var dataProcessor = editor.dataProcessor,
    128                         htmlFilter = dataProcessor && dataProcessor.htmlFilter;
    129                 if ( htmlFilter )
    130                 {
    131                         htmlFilter.addRules(
    132                                 {
    133                                         elements :
    134                                         {
    135                                                 span : function( element )
    136                                                 {
    137                                                         if ( element.attributes.scayt_word && element.attributes.scaytid )
    138                                                         {
    139                                                                 delete element.name;    // Write children, but don't write this node.
    140                                                                 return element;
    141                                                         }
    142                                                 }
    143                                         }
    144                                 }
    145                         );
    146                 }
     176        var dataProcessor = editor.dataProcessor,
     177            htmlFilter = dataProcessor && dataProcessor.htmlFilter;
     178        if ( htmlFilter )
     179        {
     180            htmlFilter.addRules(
     181                {
     182                    elements :
     183                    {
     184                        span : function( element )
     185                        {
     186                            if ( element.attributes.scayt_word && element.attributes.scaytid )
     187                            {
     188                                delete element.name;    // Write children, but don't write this node.
     189                                return element;
     190                            }
     191                        }
     192                    }
     193                }
     194            );
     195        }
    147196
    148                 if ( editor.document )
    149                         createInstance();
    150         };
     197        if ( editor.document )
     198            createInstance();
     199    };
    151200
    152         CKEDITOR.plugins.scayt =
    153         {
    154                 engineLoaded : false,
    155                 instances : {},
    156                 getScayt : function( editor )
    157                 {
    158                         return this.instances[ editor.name ];
    159                 },
    160                 isScaytReady : function( editor )
    161                 {
    162                         return this.engineLoaded === true &&
    163                                 'undefined' !== typeof window.scayt && this.getScayt( editor );
    164                 },
    165                 isScaytEnabled : function( editor )
    166                 {
    167                         var scayt_instanse = this.getScayt( editor );
    168                         return ( scayt_instanse ) ? scayt_instanse.disabled === false : false;
    169                 },
    170                 loadEngine : function( editor )
    171                 {
    172                         if ( this.engineLoaded === true )
    173                                 return onEngineLoad.apply( editor );    // Add new instance.
    174                         else if ( this.engineLoaded == -1 )                     // We are waiting.
    175                                 return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor );} ); // Use function(){} to avoid rejection as duplicate.
     201    CKEDITOR.plugins.scayt =
     202    {
     203        engineLoaded : false,
     204        instances : {},
     205        getScayt : function( editor )
     206        {
     207            return this.instances[ editor.name ];
     208        },
     209        isScaytReady : function( editor )
     210        {
     211            return this.engineLoaded === true &&
     212                'undefined' !== typeof window.scayt && this.getScayt( editor );
     213        },
     214        isScaytEnabled : function( editor )
     215        {
     216            var scayt_instanse = this.getScayt( editor );
     217            return ( scayt_instanse ) ? scayt_instanse.disabled === false : false;
     218        },
     219        loadEngine : function( editor )
     220        {
     221            if ( this.engineLoaded === true )
     222                return onEngineLoad.apply( editor );    // Add new instance.
     223            else if ( this.engineLoaded == -1 )                 // We are waiting.
     224                return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor );} ); // Use function(){} to avoid rejection as duplicate.
    176225
    177                         CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
    178                         CKEDITOR.on( 'scaytReady', function()
    179                                 {
    180                                         this.engineLoaded = true;
    181                                 },
    182                                 this,
    183                                 null,
    184                                 0 );    // First to run.
     226            CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
     227            CKEDITOR.on( 'scaytReady', function()
     228            {
     229                this.engineLoaded = true;
     230            },
     231            this,
     232            null,
     233            0 );// First to run.
    185234
    186                         this.engineLoaded = -1; // Loading in progress.
     235            this.engineLoaded = -1;     // Loading in progress.
    187236
    188                         // compose scayt url
    189                         var protocol = document.location.protocol;
    190                         // Default to 'http' for unknown.
    191                         protocol = protocol.search( /https?:/) != -1? protocol : 'http:';
    192                         var baseUrl  = "svc.spellchecker.net/spellcheck/lf/scayt/scayt1.js";
     237            // compose scayt url
     238            var protocol = document.location.protocol;
     239            // Default to 'http' for unknown.
     240            protocol = protocol.search( /https?:/) != -1? protocol : 'http:';
     241            var baseUrl  = "svc.spellchecker.net/spellcheck/lf/scayt/scayt1.js";
    193242
    194                         var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl );
    195                         var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  "/";
     243            var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl );
     244            var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  "/";
    196245
    197                         CKEDITOR._djScaytConfig =
    198                         {
    199                                 baseUrl: scaytConfigBaseUrl,
    200                                 addOnLoad:
    201                                 [
    202                                         function()
    203                                         {
    204                                                 CKEDITOR.fireOnce( "scaytReady" );
    205                                         }
    206                                 ],
    207                                 isDebug: false
    208                         };
    209                         // Append javascript code.
    210                         CKEDITOR.document.getHead().append(
    211                                 CKEDITOR.document.createElement( 'script',
    212                                         {
    213                                                 attributes :
    214                                                         {
    215                                                                 type : 'text/javascript',
    216                                                                 src : scaytUrl
    217                                                         }
    218                                         })
    219                         );
     246            CKEDITOR._djScaytConfig =
     247            {
     248                baseUrl: scaytConfigBaseUrl,
     249                addOnLoad:
     250                [
     251                    function()
     252                    {
     253                        CKEDITOR.fireOnce( "scaytReady" );
     254                    }
     255                ],
     256                isDebug: false
     257            };
     258            // Append javascript code.
     259            CKEDITOR.document.getHead().append(
     260                CKEDITOR.document.createElement( 'script',
     261                    {
     262                        attributes :
     263                            {
     264                                type : 'text/javascript',
     265                                src : scaytUrl
     266                            }
     267                    })
     268            );
    220269
    221                         return null;
    222                 },
    223                 parseUrl : function ( data )
    224                 {
    225                         var match;
    226                         if ( data.match && ( match = data.match(/(.*)[\/\\](.*?\.\w+)$/) ) )
    227                                 return { path: match[1], file: match[2] };
    228                         else
    229                                 return data;
    230                 }
    231         };
     270            return null;
     271        },
     272        parseUrl : function ( data )
     273        {
     274            var match;
     275            if ( data.match && ( match = data.match(/(.*)[\/\\](.*?\.\w+)$/) ) )
     276                return { path: match[1], file: match[2] };
     277            else
     278                return data;
     279        }
     280    };
    232281
    233         var plugin = CKEDITOR.plugins.scayt;
     282    var plugin = CKEDITOR.plugins.scayt;
    234283
    235         // Context menu constructing.
    236         var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder )
    237         {
    238                 editor.addCommand( commandName, command );
     284    // Context menu constructing.
     285    var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder )
     286    {
     287        editor.addCommand( commandName, command );
    239288
    240                 // If the "menu" plugin is loaded, register the menu item.
    241                 editor.addMenuItem( commandName,
    242                         {
    243                                 label : buttonLabel,
    244                                 command : commandName,
    245                                 group : menugroup,
    246                                 order : menuOrder
    247                         });
    248         };
     289        // If the "menu" plugin is loaded, register the menu item.
     290        editor.addMenuItem( commandName,
     291            {
     292                label : buttonLabel,
     293                command : commandName,
     294                group : menugroup,
     295                order : menuOrder
     296            });
     297    };
    249298
    250         var commandDefinition =
    251         {
    252                 preserveState : true,
    253                 editorFocus : false,
     299    var commandDefinition =
     300    {
     301        preserveState : true,
     302        editorFocus : false,
    254303
    255                 exec: function( editor )
    256                 {
    257                         if ( plugin.isScaytReady( editor ) )
    258                         {
    259                                 var isEnabled = plugin.isScaytEnabled( editor );
     304        exec: function( editor )
     305        {
     306            if ( plugin.isScaytReady( editor ) )
     307            {
     308                var isEnabled = plugin.isScaytEnabled( editor );
    260309
    261                                 this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );
     310                this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );
    262311
    263                                 var scayt_control = plugin.getScayt( editor );
    264                                 scayt_control.setDisabled( isEnabled );
    265                         }
    266                         else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 )        // Load first time
    267                         {
    268                                 this.setState( CKEDITOR.TRISTATE_DISABLED );
     312                var scayt_control = plugin.getScayt( editor );
     313                scayt_control.setDisabled( isEnabled );
     314            }
     315            else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 )    // Load first time
     316            {
     317                this.setState( CKEDITOR.TRISTATE_DISABLED );
    269318
    270                                 editor.on( 'showScaytState', function()
    271                                         {
    272                                                 this.removeListener();
    273                                                 this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
    274                                         },
    275                                         this);
     319                editor.on( 'showScaytState', function()
     320                    {
     321                        this.removeListener();
     322                        this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
     323                    },
     324                    this);
    276325
    277                                 plugin.loadEngine( editor );
    278                         }
    279                 }
    280         };
     326                plugin.loadEngine( editor );
     327            }
     328        }
     329    };
    281330
    282         // Add scayt plugin.
    283         CKEDITOR.plugins.add( 'scayt',
    284         {
    285                 requires : [ 'menubutton' ],
     331    // Add scayt plugin.
     332    CKEDITOR.plugins.add( 'scayt',
     333    {
     334        requires : [ 'menubutton' ],
    286335
    287                 beforeInit : function( editor )
    288                 {
    289                         // Register own rbc menu group.
    290                         editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups;
    291                 },
     336        beforeInit : function( editor )
     337        {
     338            // Register own rbc menu group.
     339            editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups;
     340        },
    292341
    293                 init : function( editor )
    294                 {
    295                         var moreSuggestions = {};
    296                         var mainSuggestions = {};
     342        init : function( editor )
     343        {
     344            var moreSuggestions = {};
     345            var mainSuggestions = {};
    297346
    298                         // Scayt command.
    299                         var command = editor.addCommand( commandName, commandDefinition );
     347            // Scayt command.
     348            var command = editor.addCommand( commandName, commandDefinition );
    300349
    301                         // Add Options dialog.
    302                         CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
     350            // Add Options dialog.
     351            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           
     363           
     364            var menuGroup = 'scaytButton';
     365            editor.addMenuGroup( menuGroup );                   
     366            // combine menu items to render
     367            var uiMuneItems = {};
     368           
     369            // allways added
     370            uiMuneItems.scaytToggle =
     371                {
     372                    label : editor.lang.scayt.enable,
     373                    command : commandName,
     374                    group : menuGroup
     375                };
     376               
     377            if (uiTabs[0] == 1)
     378                uiMuneItems.scaytOptions =
     379                {
     380                    label : editor.lang.scayt.options,
     381                    group : menuGroup,
     382                    onClick : function()
     383                    {
     384                        openPage = 'options';
     385                        editor.openDialog( commandName );
     386                    }
     387                };
    303388
    304                         var menuGroup = 'scaytButton';
    305                         editor.addMenuGroup( menuGroup );
    306                         editor.addMenuItems(
    307                                 {
    308                                         scaytToggle :
    309                                         {
    310                                                 label : editor.lang.scayt.enable,
    311                                                 command : commandName,
    312                                                 group : menuGroup
    313                                         },
     389            if (uiTabs[1] == 1)
     390                uiMuneItems.scaytLangs =
     391                {
     392                    label : editor.lang.scayt.langs,
     393                    group : menuGroup,
     394                    onClick : function()
     395                    {
     396                        openPage = 'langs';
     397                        editor.openDialog( commandName );
     398                    }
     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 =
     413                {
     414                    label : editor.lang.scayt.about,
     415                    group : menuGroup,
     416                    onClick : function()
     417                    {
     418                        openPage = 'about';
     419                        editor.openDialog( commandName );
     420                    }
     421                }
     422            ;
     423           
     424            uiTabs[3] = 1; // about us tab is allways on
     425            plugin.uiTabs = uiTabs;
     426           
     427            editor.addMenuItems( uiMuneItems );
    314428
    315                                         scaytOptions :
    316                                         {
    317                                                 label : editor.lang.scayt.options,
    318                                                 group : menuGroup,
    319                                                 onClick : function()
    320                                                 {
    321                                                         openPage = 'options';
    322                                                         editor.openDialog( commandName );
    323                                                 }
    324                                         },
     429                editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
     430                    {
     431                        label : editor.lang.scayt.title,
     432                        title : editor.lang.scayt.title,
     433                        className : 'cke_button_scayt',
     434                        onRender: function()
     435                        {
     436                            command.on( 'state', function()
     437                            {
     438                                this.setState( command.state );
     439                            },
     440                            this);
     441                           
     442                        },
     443                        onMenu : function()
     444                        {
     445                            var isEnabled = plugin.isScaytEnabled( editor );
     446   
     447                            editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ];
     448   
     449                                return {
     450                                    scaytToggle  : CKEDITOR.TRISTATE_OFF,
     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
     455                                };
     456                        }
     457                    });
    325458
    326                                         scaytLangs :
    327                                         {
    328                                                 label : editor.lang.scayt.langs,
    329                                                 group : menuGroup,
    330                                                 onClick : function()
    331                                                 {
    332                                                         openPage = 'langs';
    333                                                         editor.openDialog( commandName );
    334                                                 }
    335                                         },
     459            // If the "contextmenu" plugin is loaded, register the listeners.
     460            if ( editor.contextMenu && editor.addMenuItems )
     461            {
     462                editor.contextMenu.addListener( function( element )
     463                    {
     464                       
     465                        if ( !( plugin.isScaytEnabled( editor ) && element ) )
     466                            return null;
    336467
    337                                         scaytAbout :
    338                                         {
    339                                                 label : editor.lang.scayt.about,
    340                                                 group : menuGroup,
    341                                                 onClick : function()
    342                                                 {
    343                                                         openPage = 'about';
    344                                                         editor.openDialog( commandName );
    345                                                 }
    346                                         }
    347                                 });
     468                        var scayt_control = plugin.getScayt( editor ),
     469                            word = scayt_control.getWord( element.$ );
    348470
    349                                 editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
    350                                         {
    351                                                 label : editor.lang.scayt.title,
    352                                                 title : editor.lang.scayt.title,
    353                                                 className : 'cke_button_scayt',
    354                                                 onRender: function()
    355                                                 {
    356                                                 command.on( 'state', function()
    357                                                         {
    358                                                                 this.setState( command.state );
    359                                                         },
    360                                                         this);
    361                                         },
    362                                         onMenu : function()
    363                                         {
    364                                                 var isEnabled = plugin.isScaytEnabled( editor );
     471                        if ( !word )
     472                            return null;
    365473
    366                                                 editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ];
     474                        var sLang = scayt_control.getLang(),
     475                            _r = {},
     476                            items_suggestion = window.scayt.getSuggestion( word, sLang );
     477                        if (!items_suggestion || !items_suggestion.length )
     478                            return null;
     479                        // Remove unused commands and menuitems
    367480
    368                                                         return {
    369                                                                 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
    373                                                         };
    374                                                 }
    375                                         });
     481                        for ( i in moreSuggestions )
     482                        {
     483                            delete editor._.menuItems[ i ];
     484                            delete editor._.commands[ i ];
     485                        }
     486                        for ( i in mainSuggestions )
     487                        {
     488                            delete editor._.menuItems[ i ];
     489                            delete editor._.commands[ i ];
     490                        }
     491                        moreSuggestions = {};           // Reset items.
     492                        mainSuggestions = {};
    376493
    377                         // If the "contextmenu" plugin is loaded, register the listeners.
    378                         if ( editor.contextMenu && editor.addMenuItems )
    379                         {
    380                                 editor.contextMenu.addListener( function( element )
    381                                         {
    382                                                 if ( !( plugin.isScaytEnabled( editor ) && element ) )
    383                                                         return null;
     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("|");
    384501
    385                                                 var scayt_control = plugin.getScayt( editor ),
    386                                                         word = scayt_control.getWord( element.$ );
     502                        for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
     503                        {
     504                            var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );
     505                            var exec = ( function( el, s )
     506                            {
     507                                return {
     508                                    exec: function()
     509                                    {
     510                                        scayt_control.replace(el, s);
     511                                    }
     512                                };
     513                            })( element.$, items_suggestion[i] );
    387514
    388                                                 if ( !word )
    389                                                         return null;
     515                            if ( i < maxSuggestions )
     516                            {
     517                                addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
     518                                    commandName, exec, 'scayt_suggest', i + 1 );
     519                                _r[ commandName ] = CKEDITOR.TRISTATE_OFF;
     520                                mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
     521                            }
     522                            else if ( moreSuggestionsUnable == "on" )
     523                            {
    390524
    391                                                 var sLang = scayt_control.getLang(),
    392                                                         _r = {},
    393                                                         items_suggestion = window.scayt.getSuggestion( word, sLang );
    394                                                 if (!items_suggestion || !items_suggestion.length )
    395                                                         return null;
    396                                                 // Remove unused commands and menuitems
    397                                                 for ( i in moreSuggestions )
    398                                                 {
    399                                                         delete editor._.menuItems[ i ];
    400                                                         delete editor._.commands[ i ];
    401                                                 }
    402                                                 for ( i in mainSuggestions )
    403                                                 {
    404                                                         delete editor._.menuItems[ i ];
    405                                                         delete editor._.commands[ i ];
    406                                                 }
    407                                                 moreSuggestions = {};           // Reset items.
    408                                                 mainSuggestions = {};
     525                                addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
     526                                    commandName, exec, 'scayt_moresuggest', i + 1 );
     527                                moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
     528                                moreSuggestionsUnableAdded = true;
    409529
    410                                                 var moreSuggestionsUnable = false;
    411530
    412                                                 for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
    413                                                 {
    414                                                         var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );
    415                                                         var exec = ( function( el, s )
    416                                                                 {
    417                                                                         return {
    418                                                                                 exec: function()
    419                                                                                 {
    420                                                                                         scayt_control.replace(el, s);
    421                                                                                 }
    422                                                                         };
    423                                                                 })( element.$, items_suggestion[i] );
    424531
    425                                                         if ( i < editor.config.scayt_maxSuggestions )
    426                                                         {
    427                                                                 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
    428                                                                         commandName, exec, 'scayt_suggest', i + 1 );
    429                                                                 _r[ commandName ] = CKEDITOR.TRISTATE_OFF;
    430                                                                 mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
    431                                                         }
    432                                                         else
    433                                                         {
    434                                                                 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
    435                                                                         commandName, exec, 'scayt_moresuggest', i + 1 );
    436                                                                 moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
    437                                                                 moreSuggestionsUnable = true;
    438                                                         }
    439                                                 }
    440                                                 if ( moreSuggestionsUnable )
    441                                                         // Rgister the More suggestions group;
    442                                                         editor.addMenuItem( 'scayt_moresuggest',
    443                                                                 {
    444                                                                         label : editor.lang.scayt.moreSuggestions,
    445                                                                         group : 'scayt_moresuggest',
    446                                                                         order : 10,
    447                                                                         getItems : function()
    448                                                                         {
    449                                                                                 return moreSuggestions;
    450                                                                         }
    451                                                                 });
    452532
     533                            }
     534                        }
    453535
    454                                                 var ignore_command =
    455                                                 {
    456                                                         exec: function()
    457                                                         {
    458                                                                 scayt_control.ignore( element.$ );
    459                                                         }
    460                                                 };
    461                                                 var ignore_all_command =
    462                                                 {
    463                                                         exec: function()
    464                                                         {
    465                                                                 scayt_control.ignoreAll( element.$ );
    466                                                         }
    467                                                 };
    468                                                 var addword_command =
    469                                                 {
    470                                                         exec: function()
    471                                                         {
    472                                                                 window.scayt.addWordToUserDictionary( element.$ );
    473                                                         }
    474                                                 };
     536                        if ( moreSuggestionsUnableAdded ){
     537                            // Rgister the More suggestions group;
     538                            editor.addMenuItem( 'scayt_moresuggest',
     539                            {
     540                                label : editor.lang.scayt.moreSuggestions,
     541                                group : 'scayt_moresuggest',
     542                                order : 10,
     543                                getItems : function()
     544                                {
     545                                    return moreSuggestions;
     546                                }
     547                            });
     548                            mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
     549                           
     550                        }
     551                           
    475552
    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);
     553                       
     554                        if ( in_array( "all",contextCommands )  || in_array("ignore",contextCommands)  )
     555                        {
     556                            var ignore_command = {
     557                                exec: function(){
     558                                    scayt_control.ignore(element.$);
     559                                }
     560                            };
     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)  )
     566                        {
     567                            var ignore_all_command = {
     568                                exec: function(){
     569                                    scayt_control.ignoreAll(element.$);
     570                                }
     571                            };
     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)  )
     577                        {
     578                            var addword_command = {
     579                                exec: function(){
     580                                    window.scayt.addWordToUserDictionary(element.$);
     581                                }
     582                            };
     583                            addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
     584                            mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF;
     585                        }
    482586
    483                                                 mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
    484                                                 mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
    485                                                 mainSuggestions[ 'scayt_ignore_all' ] = CKEDITOR.TRISTATE_OFF;
    486                                                 mainSuggestions[ 'scayt_add_word' ] = CKEDITOR.TRISTATE_OFF;
     587                        if ( scayt_control.fireOnContextMenu )
     588                            scayt_control.fireOnContextMenu( editor );
     589                       
     590                        return mainSuggestions;
     591                    });
     592            }
    487593
    488                                                 if ( scayt_control.fireOnContextMenu )
    489                                                         scayt_control.fireOnContextMenu( editor );
     594            // Start plugin
     595            if ( editor.config.scayt_autoStartup )
     596            {
     597                var showInitialState = function()
     598                {
     599                    editor.removeListener( 'showScaytState', showInitialState );
     600                    command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
     601                };
     602                editor.on( 'showScaytState', showInitialState );
    490603
    491                                                 return mainSuggestions;
    492                                         });
    493                         }
    494 
    495                         // Start plugin
    496                         if ( editor.config.scayt_autoStartup )
    497                         {
    498                                 var showInitialState = function()
    499                                 {
    500                                         editor.removeListener( 'showScaytState', showInitialState );
    501                                         command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
    502                                 };
    503                                 editor.on( 'showScaytState', showInitialState );
    504 
    505                                 plugin.loadEngine( editor );
    506                         }
    507                 }
    508         });
     604                plugin.loadEngine( editor );
     605            }
     606        }
     607    });
    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;
  • dialogs/options.js

     
    7070                                                {
    7171                                                        type : 'html',
    7272                                                        style: '',
    73                                                         id : 'dic',
    74                                                         html :  '<div class="inner_dictionary" style="text-align:left; white-space:normal;">' +
     73                                                        id : 'dictionaries',
     74                                                        html :  '<div class="inner_dictionary" style="text-align:left; white-space:normal; width:340px; overflow: hidden;">' +
    7575                                                                        '       <div style="margin:5px auto; width:80%;white-space:normal; overflow:hidden;" id="dic_message"> </div>' +
    7676                                                                        '       <div style="margin:5px auto; width:80%;white-space:normal;"> ' +
    7777                                                                        '       <span class="cke_dialog_ui_labeled_label" >Dictionary name</span><br>'+
     
    129129                        if ( firstLoad )
    130130                        {
    131131                                dialog.data.scayt.getCaption( 'en', function( caps )
    132                                         {
    133                                                 if ( stop++ > 0 )       // Once only
    134                                                         return;
    135                                                 captions = caps;
    136                                                 init_with_captions.apply( dialog );
    137                                                 reload.apply( dialog );
    138                                                 firstLoad = false;
    139                                         });
     132                {
     133                    if ( stop++ > 0 )   // Once only
     134                        return;
     135                    captions = caps;
     136                    init_with_captions.apply( dialog );
     137                    reload.apply( dialog );
     138                    firstLoad = false;
     139                });
    140140                        }
    141141                        else
    142                                 reload.apply( dialog );
     142            {
     143                 reload.apply( dialog );
     144            }
    143145
     146
    144147                        dialog.selectPage( dialog.data.tab );
    145148                },
    146149                onOk : function()
    147150                {
    148                         var scayt_control =  this.data.scayt_control,
    149                                 o = scayt_control.option(),
    150                                 c = 0;
    151 
    152                         // Set up options if any was set.
    153                         for ( var i in this.options )
    154                         {
    155                                 if (o[i] != this.options[ i ] && c === 0 )
    156                                 {
    157                                         scayt_control.option( this.options );
    158                                         c++;
    159                                 }
    160                         }
    161 
     151                        var scayt_control =  this.data.scayt_control;
     152            scayt_control.option( this.options );
    162153                        // Setup languge if it was changed.
    163154                        var csLang = this.chosed_lang;
    164                         if ( csLang && this.data.sLang != csLang )
    165                         {
    166                                 scayt_control.setLang( csLang );
    167                                 c++;
    168                         }
    169                         if ( c > 0 )
    170                                 scayt_control.refresh();
    171                 },
     155                        scayt_control.setLang( csLang );
     156                        scayt_control.refresh();
     157        },
    172158                contents : contents
    173         };
     159    };
    174160
    175161        var scayt_control = CKEDITOR.plugins.scayt.getScayt( editor );
    176         if ( scayt_control )
    177         {
    178                 tags = scayt_control.uiTags;
    179         }
    180162
    181         for ( i in tags ) {
     163    tags = CKEDITOR.plugins.scayt.uiTabs;
     164
     165        for ( i in tags )
     166    {
    182167                if ( tags[ i ] == 1 )
    183168                        contents[ contents.length ] = tags_contents[ i ];
    184169        }
    185170        if ( tags[2] == 1 )
    186171                userDicActive = true;
    187172
    188         function onDicButtonClick()
    189         {
    190                 var dic_name = doc.getById('dic_name').getValue();
    191                 if ( !dic_name )
    192                 {
    193                         dic_error_message(" Dictionary name should not be empty. ");
    194                         return false;
    195                 }
    196                 //apply handler
    197                 window.dic[ this.getId() ].apply( null, [ this, dic_name, dic_buttons ] );
    198 
    199                 return true;
    200         }
     173       
    201174        var init_with_captions = function()
    202175        {
    203176                var dialog = this,
     
    219192
    220193
    221194                // Fill options and dictionary labels.
    222                 for ( i in labels )
    223                 {
    224                         var label = 'label_' + labels[ i ],
    225                                 labelElement = doc.getById( label );
    226 
    227                         if (  'undefined' != typeof labelElement
    228                            && 'undefined' != typeof captions[ label ]
    229                            && 'undefined' != typeof dialog.options[labels[ i ]] )
     195                if (tags[0] == 1)
     196        {
     197            for ( i in labels )
    230198                        {
    231                                 labelElement.setHtml( captions[ label ] );
    232                                 var labelParent = labelElement.getParent();
    233                                 labelParent.$.style.display = "block";
    234                         }
    235                 }
     199                                var label = 'label_' + labels[ i ],
     200                                        labelElement = doc.getById( label );
    236201
     202                                if (  'undefined' != typeof labelElement
     203                                   && 'undefined' != typeof captions[ label ]
     204                                   && 'undefined' != typeof dialog.options[labels[ i ]] )
     205                                {
     206                                        labelElement.setHtml( captions[ label ] );
     207                                        var labelParent = labelElement.getParent();
     208                                        labelParent.$.style.display = "block";
     209                                }
     210                        }   
     211        }
     212
     213
    237214                var about = '<p>' + captions[ 'about_throwt_image' ] + '</p>'+
    238215                                        '<p>' + captions[ 'version' ]  + dialog.data.scayt.version.toString() + '</p>' +
    239216                                        '<p>' + captions[ 'about_throwt_copy' ] + '</p>';
     
    257234                                        ' value="' + option + '" name="scayt_lang" />' );
    258235
    259236                        radio.on( 'click', function()
    260                                 {
    261                                         this.$.checked = true;
    262                                         dialog.chosed_lang = option;
    263                                 });
     237            {
     238                this.$.checked = true;
     239                dialog.chosed_lang = option;
     240            });
    264241
    265242                        div.append( radio );
    266243                        div.append( label );
     
    273250                };
    274251
    275252                var langList = [];
    276                 for ( i in lang_list.rtl )
    277                         langList[ langList.length ] = createOption( i, lang_list.ltr );
    278 
    279                 for ( i in lang_list.ltr )
    280                         langList[ langList.length  ] = createOption( i, lang_list.ltr );
    281 
    282                 langList.sort(  function( lang1, lang2 )
     253                if (tags[1] ==1 )
     254        {
     255                        for ( i in lang_list.rtl )
     256                                langList[ langList.length ] = createOption( i, lang_list.ltr );
     257       
     258                        for ( i in lang_list.ltr )
     259                                langList[ langList.length  ] = createOption( i, lang_list.ltr );
     260       
     261                        langList.sort(  function( lang1, lang2 )
     262                                {
     263                                        return ( lang2.lang > lang1.lang ) ? -1 : 1 ;
     264                                });
     265       
     266                        var fieldL = doc.getById( 'scayt_lcol' ),
     267                                fieldR = doc.getById( 'scayt_rcol' );
     268                        for ( i=0; i < langList.length; i++ )
    283269                        {
    284                                 return ( lang2.lang > lang1.lang ) ? -1 : 1 ;
    285                         });
    286 
    287                 var fieldL = doc.getById( 'scayt_lcol' ),
    288                         fieldR = doc.getById( 'scayt_rcol' );
    289                 for ( i=0; i < langList.length; i++ )
    290                 {
    291                         var field = ( i < langList.length / 2 ) ? fieldL : fieldR;
    292                         field.append( langList[ i ].radio );
     270                                var field = ( i < langList.length / 2 ) ? fieldL : fieldR;
     271                                field.append( langList[ i ].radio );
     272                        }
    293273                }
     274               
    294275
    295276                // user dictionary handlers
    296277                var dic = {};
    297278                dic.dic_create = function( el, dic_name , dic_buttons )
    298                         {
    299                                 // comma separated button's ids include repeats if exists
    300                                 var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
     279        {
     280            // comma separated button's ids include repeats if exists
     281            var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
    301282
    302                                 var err_massage = captions["err_dic_create"];
    303                                 var suc_massage = captions["succ_dic_create"];
    304                                 //console.info("--plugin ");
     283            var err_massage = captions["err_dic_create"];
     284            var suc_massage = captions["succ_dic_create"];
    305285
    306                                 window.scayt.createUserDictionary(dic_name,
    307                                         function(arg)
    308                                                 {
    309                                                         //console.info( "dic_create callback called with args" , arg );
    310                                                         hide_dic_buttons ( all_buttons );
    311                                                         display_dic_buttons ( dic_buttons[1] );
    312                                                         suc_massage = suc_massage.replace("%s" , arg.dname );
    313                                                         dic_success_message (suc_massage);
    314                                                 },
    315                                         function(arg)
    316                                                 {
    317                                                         //console.info( "dic_create errorback called with args" , arg )
    318                                                         err_massage = err_massage.replace("%s" ,arg.dname );
    319                                                         dic_error_message ( err_massage + "( "+ (arg.message || "") +")");
    320                                                 });
     286            window.scayt.createUserDictionary(dic_name,
     287                function(arg)
     288                {
     289                    hide_dic_buttons ( all_buttons );
     290                    display_dic_buttons ( dic_buttons[1] );
     291                    suc_massage = suc_massage.replace("%s" , arg.dname );
     292                    dic_success_message (suc_massage);
     293                },
     294                function(arg)
     295                {
     296                    err_massage = err_massage.replace("%s" ,arg.dname );
     297                    dic_error_message ( err_massage + "( "+ (arg.message || "") +")");
     298                });
    321299
    322                         };
     300        };
    323301
    324302                dic.dic_rename = function( el, dic_name )
    325                         {
    326                                 //
    327                                 // try to rename dictionary
    328                                 // @TODO: rename dict
    329                                 //console.info ( captions["err_dic_rename"] )
    330                                 var err_massage = captions["err_dic_rename"] || "";
    331                                 var suc_massage = captions["succ_dic_rename"] || "";
    332                                 window.scayt.renameUserDictionary(dic_name,
    333                                         function(arg)
    334                                                 {
    335                                                         //console.info( "dic_rename callback called with args" , arg );
    336                                                         suc_massage = suc_massage.replace("%s" , arg.dname );
    337                                                         set_dic_name( dic_name );
    338                                                         dic_success_message ( suc_massage );
    339                                                 },
    340                                         function(arg)
    341                                                 {
    342                                                         //console.info( "dic_rename errorback called with args" , arg )
    343                                                         err_massage = err_massage.replace("%s" , arg.dname  );
    344                                                         set_dic_name( dic_name );
    345                                                         dic_error_message( err_massage + "( " + ( arg.message || "" ) + " )" );
    346                                                 });
    347                         };
     303        {
     304            //
     305            // try to rename dictionary
     306            var err_massage = captions["err_dic_rename"] || "";
     307            var suc_massage = captions["succ_dic_rename"] || "";
     308            window.scayt.renameUserDictionary(dic_name,
     309                function(arg)
     310                    {
     311                        suc_massage = suc_massage.replace("%s" , arg.dname );
     312                        set_dic_name( dic_name );
     313                        dic_success_message ( suc_massage );
     314                    },
     315                function(arg)
     316                    {
     317                        err_massage = err_massage.replace("%s" , arg.dname  );
     318                        set_dic_name( dic_name );
     319                        dic_error_message( err_massage + "( " + ( arg.message || "" ) + " )" );
     320                    });
     321        };
    348322
    349323                dic.dic_delete = function ( el, dic_name , dic_buttons )
    350                         {
    351                                 var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
    352                                 var err_massage = captions["err_dic_delete"];
    353                                 var suc_massage = captions["succ_dic_delete"];
     324        {
     325            var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
     326            var err_massage = captions["err_dic_delete"];
     327            var suc_massage = captions["succ_dic_delete"];
    354328
    355                                 // try to delete dictionary
    356                                 // @TODO: delete dict
    357                                 window.scayt.deleteUserDictionary(
    358                                         function(arg)
    359                                                 {
    360                                                         //console.info( "dic_delete callback " , dic_name ,arg );
    361                                                         suc_massage = suc_massage.replace("%s" , arg.dname );
    362                                                         hide_dic_buttons ( all_buttons );
    363                                                         display_dic_buttons ( dic_buttons[0] );
    364                                                         set_dic_name( "" ); // empty input field
    365                                                         dic_success_message( suc_massage );
    366                                                 },
    367                                         function(arg)
    368                                                 {
    369                                                         //console.info( " dic_delete errorback called with args" , arg )
    370                                                         err_massage = err_massage.replace("%s" , arg.dname );
    371                                                         dic_error_message(err_massage);
    372                                                 });
    373                         };
     329            // try to delete dictionary
     330            window.scayt.deleteUserDictionary(
     331                function(arg)
     332                {
     333                    suc_massage = suc_massage.replace("%s" , arg.dname );
     334                    hide_dic_buttons ( all_buttons );
     335                    display_dic_buttons ( dic_buttons[0] );
     336                    set_dic_name( "" ); // empty input field
     337                    dic_success_message( suc_massage );
     338                },
     339                function(arg)
     340                {
     341                    err_massage = err_massage.replace("%s" , arg.dname );
     342                    dic_error_message(err_massage);
     343                });
     344        };
    374345
    375346                dic.dic_restore = dialog.dic_restore || function ( el, dic_name , dic_buttons )
    376347                        {
     
    380351                                var suc_massage = captions["succ_dic_restore"];
    381352
    382353                                window.scayt.restoreUserDictionary(dic_name,
     354                    function(arg)
     355                    {
     356                        suc_massage = suc_massage.replace("%s" , arg.dname );
     357                        hide_dic_buttons ( all_buttons );
     358                        display_dic_buttons(dic_buttons[1]);
     359                        dic_success_message( suc_massage );
     360                    },
    383361                                        function(arg)
    384                                                 {
    385                                                         //console.info( "dic_restore callback called with args" , arg );
    386                                                         suc_massage = suc_massage.replace("%s" , arg.dname );
    387                                                         hide_dic_buttons ( all_buttons );
    388                                                         display_dic_buttons(dic_buttons[1]);
    389                                                         dic_success_message( suc_massage );
    390                                                 },
    391                                         function(arg)
    392                                                 {
    393                                                         //console.info( " dic_restore errorback called with args" , arg )
    394                                                         err_massage = err_massage.replace("%s" , arg.dname );
    395                                                         dic_error_message( err_massage );
    396                                                 });
     362                    {
     363                        err_massage = err_massage.replace("%s" , arg.dname );
     364                        dic_error_message( err_massage );
     365                    });
    397366                        };
    398 
     367function onDicButtonClick( ev )
     368        {
     369                var dic_name = doc.getById('dic_name').getValue();
     370                if ( !dic_name )
     371                {
     372                        dic_error_message(" Dictionary name should not be empty. ");
     373                        return false;
     374                }
     375                try{
     376                        var el = id = ev.data.getTarget().getParent();
     377                        var id = el.getId();
     378                        dic[ id ].apply( null, [ el, dic_name, dic_buttons ] );
     379                }catch(err){
     380                        dic_error_message(" Dictionary error. ");
     381                }
     382               
     383                return true;
     384        }
    399385                // ** bind event listeners
    400386                var arr_buttons = ( dic_buttons[0] + ',' + dic_buttons[1] ).split( ',' ),
    401387                        l;
     
    416402                for ( var i in dialog.options )
    417403                {
    418404                        var checkbox = doc.getById( i );
     405
    419406                        if ( checkbox )
    420407                        {
    421408                                checkbox.removeAttribute( 'checked' );
     409                checkbox.$.removeAttribute( 'checked' );
     410               
     411                var opt = dialog.data.scayt_control.option();
     412
    422413                                if ( dialog.options[ i ] == 1 )
    423414                                        checkbox.setAttribute( 'checked', 'checked' );
    424415
     
    426417                                if ( firstLoad )
    427418                                {
    428419                                        checkbox.on( 'click', function()
    429                                                 {
    430                                                         dialog.options[ this.getId() ] = this.$.checked ? 1 : 0 ;
    431                                                 } );
     420                    {
     421                        dialog.options[ this.getId() ] = this.$.checked ? 1 : 0 ;
     422                    });
    432423                                }
    433424                        }
    434425                }
     
    458449        };
    459450
    460451        function dic_error_message ( m )
    461                 {
    462                         doc.getById('dic_message').setHtml('<span style="color:red;">' + m + '</span>' );
    463                 }
     452    {
     453        doc.getById('dic_message').setHtml('<span style="color:red;">' + m + '</span>' );
     454    }
    464455    function dic_success_message ( m )
    465                 {
    466                         doc.getById('dic_message').setHtml('<span style="color:blue;">' + m + '</span>') ;
    467                 }
     456    {
     457        doc.getById('dic_message').setHtml('<span style="color:blue;">' + m + '</span>') ;
     458    }
    468459        function display_dic_buttons ( sIds )
    469                 {
     460    {
    470461
    471                         sIds = String( sIds );
    472                         var aIds = sIds.split(',');
    473                         for ( var i=0, l = aIds.length; i < l ; i+=1)
    474                         {
    475                                 doc.getById( aIds[i] ).$.style.display = "inline";
    476                         }
     462        sIds = String( sIds );
     463        var aIds = sIds.split(',');
     464        for ( var i=0, l = aIds.length; i < l ; i+=1)
     465        {
     466            doc.getById( aIds[i] ).$.style.display = "inline";
     467        }
    477468
    478                 }
     469    }
    479470        function hide_dic_buttons ( sIds )
    480                 {
    481                         sIds = String( sIds );
    482                         var aIds = sIds.split(',');
    483                         for ( var i = 0, l = aIds.length; i < l ; i += 1 )
    484                         {
    485                                 doc.getById( aIds[i] ).$.style.display = "none";
    486                         }
    487                 }
     471    {
     472        sIds = String( sIds );
     473        var aIds = sIds.split(',');
     474        for ( var i = 0, l = aIds.length; i < l ; i += 1 )
     475        {
     476            doc.getById( aIds[i] ).$.style.display = "none";
     477        }
     478    }
    488479        function set_dic_name ( dic_name )
    489                 {
    490                         doc.getById('dic_name').$.value= dic_name;
    491                 }
     480    {
     481        doc.getById('dic_name').$.value= dic_name;
     482    }
    492483
    493484        return dialogDefiniton;
    494485});
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy