Ticket #5720: 5720_3.patch

File 5720_3.patch, 4.8 KB (added by WebSpellChecker.net, 14 years ago)
  • _source/plugins/scayt/plugin.js

     
    1111(function()
    1212{
    1313        var commandName         = 'scaytcheck',
    14                 openPage                = '',
    15                 scayt_paused    = null,
    16                 scayt_control_id = null;
     14                openPage                = '';
     15               
    1716
    1817        // Checks if a value exists in an array
    1918        function in_array(needle, haystack)
     
    5554                                                this.addStyle( this.selectorCss(), 'padding-bottom: 2px !important;' );
    5655
    5756                                        // Call scayt_control.focus when SCAYT loaded
    58                                         // and only if editor has focus
    59                                         if ( editor.focusManager.hasFocus )
     57                                        // and only if editor has focus and scayt control creates at first time (5720 ticket)
     58                                        if ( editor.focusManager.hasFocus && !plugin.isControlRestored( editor ) )
    6059                                                this.focus();
    6160
    6261                                };
     
    7675                                }
    7776                        }
    7877                        // needs for restoring a specific scayt control settings
    79                         if ( scayt_control_id )
    80                                 oParams.id = scayt_control_id;
     78                        if ( plugin.getControlId(editor) )
     79                                oParams.id = plugin.getControlId(editor);
    8180
    8281                        var scayt_control = new window.scayt( oParams );
    8382
     
    107106
    108107                        plugin.uiTabs = fTabs;
    109108                        try {
    110                                 scayt_control.setDisabled( scayt_paused === false );
     109                                scayt_control.setDisabled( plugin.isPaused(editor) === false );
    111110                        } catch (e) {}
    112111
    113112                        editor.fire( 'showScaytState' );
     
    139138                                        var scayt_instance = plugin.getScayt( editor );
    140139                                        if ( scayt_instance )
    141140                                        {
    142                                                 scayt_paused = scayt_instance.paused = !scayt_instance.disabled;
     141                                                plugin.setPaused(editor,!scayt_instance.disabled);
    143142                                                // store a control id for restore a specific scayt control settings
    144                                                 scayt_control_id = scayt_instance.id;
     143                                                plugin.setControlId( editor , scayt_instance.id );
    145144                                                scayt_instance.destroy( true );
    146145                                                delete plugin.instances[ editor.name ];
    147146                                        }
    148147                                }
     148                                // Catch on source mode switch off (5720 ticket)
     149                                else if ( ev.data.name == 'source'  && editor.mode == 'source' )
     150                                {
     151                                        plugin.markControlRestore( editor )
     152                                }
    149153                        });
    150154
    151155                editor.on( 'afterCommandExec', function( ev )
     
    163167                                        scayt_instance = plugin.getScayt( editor );
    164168                                delete plugin.instances[ editor.name ];
    165169                                // store a control id for restore a specific scayt control settings
    166                                 scayt_control_id = scayt_instance.id;
     170                                plugin.setControlId(editor, scayt_instance.id);
    167171                                scayt_instance.destroy( true );
    168172                        });
    169173
     
    276280                if ( editor.document )
    277281                        createInstance();
    278282        };
    279 
    280         CKEDITOR.plugins.scayt =
     283       
     284CKEDITOR.plugins.scayt =
    281285        {
    282286                engineLoaded : false,
    283287                instances : {},
     288                // Data storage for SCAYT control, based on editor instances
     289                controlInfo : {},
     290                setControlInfo : function( editor, o ){
     291                        if ( editor && editor.name && typeof (this.controlInfo[editor.name]) != 'object' )
     292                                this.controlInfo[editor.name] = {};
     293                       
     294                        for ( var infoOpt in o)
     295                                this.controlInfo[editor.name][infoOpt] = o[infoOpt];
     296                },
     297                isControlRestored : function ( editor ){
     298                        if (    editor &&
     299                                        editor.name &&
     300                                        this.controlInfo[editor.name] )
     301                                return this.controlInfo[editor.name].restored ;
     302                        return false;
     303                },
     304                markControlRestore : function ( editor ){
     305                        this.setControlInfo(editor,{restored:true});
     306                },
     307                setControlId: function (editor, id)
     308                {
     309                        this.setControlInfo(editor,{id:id});
     310                },
     311                getControlId: function (editor)
     312                {
     313                        if (    editor &&
     314                                        editor.name &&
     315                                        this.controlInfo[editor.name] &&
     316                                        this.controlInfo[editor.name].id )
     317                                return this.controlInfo[editor.name].id
     318                        return null;
     319                },
     320                setPaused: function ( editor , bool )
     321                {
     322                        this.setControlInfo(editor,{paused:bool});
     323                },
     324                isPaused: function (editor){
     325                        if (    editor &&
     326                                        editor.name &&
     327                                        this.controlInfo[editor.name] )
     328                                return this.controlInfo[editor.name].paused ;
     329                        return undefined;
     330                },
    284331                getScayt : function( editor )
    285332                {
    286333                        return this.instances[ editor.name ];
     
    297344                },
    298345                loadEngine : function( editor )
    299346                {
     347                       
    300348                        // SCAYT doesn't work with Opera.
    301349                        if ( CKEDITOR.env.opera )
    302350                                return editor.fire( 'showScaytState' );
     
    305353                                return onEngineLoad.apply( editor );    // Add new instance.
    306354                        else if ( this.engineLoaded == -1 )                     // We are waiting.
    307355                                return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor ); } );        // Use function(){} to avoid rejection as duplicate.
    308 
     356                       
    309357                        CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
    310358                        CKEDITOR.on( 'scaytReady', function()
    311359                                {
     
    739787                                elementsPathFilters.push( scaytFilter );
    740788
    741789                        editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter );
    742 
     790                       
    743791                }
    744792        });
    745793})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy