JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.3
[ckeditor.git] / _source / plugins / scayt / plugin.js
index f64d25e..b789c5b 100644 (file)
@@ -10,20 +10,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       var commandName         = 'scaytcheck',\r
-               openPage                = '',\r
-               scayt_paused    = null,\r
-               scayt_control_id = null;\r
+       var commandName  = 'scaytcheck',\r
+               openPage = '';\r
 \r
        // Checks if a value exists in an array\r
-       function in_array(needle, haystack)\r
+       function in_array( needle, haystack )\r
        {\r
-               var found = false, key;\r
-               for (key in haystack)\r
+               var found = 0,\r
+                       key;\r
+               for ( key in haystack )\r
                {\r
-                       if ((haystack[key] === needle) || ( haystack[key] == needle))\r
+                       if ( haystack[ key ] == needle )\r
                        {\r
-                               found = true;\r
+                               found = 1;\r
                                break;\r
                        }\r
                }\r
@@ -36,39 +35,57 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                var createInstance = function() // Create new instance every time Document is created.\r
                {\r
+                       var config = editor.config;\r
                        // Initialise Scayt instance.\r
                        var oParams = {};\r
                        // Get the iframe.\r
                        oParams.srcNodeRef = editor.document.getWindow().$.frameElement;\r
                        // syntax : AppName.AppVersion@AppRevision\r
                        oParams.assocApp  = 'CKEDITOR.' + CKEDITOR.version + '@' + CKEDITOR.revision;\r
-                       oParams.customerid = editor.config.scayt_customerid  || '1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';\r
-                       oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds || '';\r
-                       oParams.userDictionaryName = editor.config.scayt_userDictionaryName || '';\r
-                       oParams.sLang = editor.config.scayt_sLang || 'en_US';\r
+                       oParams.customerid = config.scayt_customerid  || '1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';\r
+                       oParams.customDictionaryIds = config.scayt_customDictionaryIds || '';\r
+                       oParams.userDictionaryName = config.scayt_userDictionaryName || '';\r
+                       oParams.sLang = config.scayt_sLang || 'en_US';\r
+\r
+                       // Introduce SCAYT onLoad callback. (#5632)\r
+                       oParams.onLoad = function()\r
+                               {\r
+                                       // Draw down word marker to avoid being covered by background-color style.(#5466)\r
+                                       if ( !( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) )\r
+                                               this.addStyle( this.selectorCss(), 'padding-bottom: 2px !important;' );\r
+\r
+                                       // Call scayt_control.focus when SCAYT loaded\r
+                                       // and only if editor has focus and scayt control creates at first time (#5720)\r
+                                       if ( editor.focusManager.hasFocus && !plugin.isControlRestored( editor ) )\r
+                                               this.focus();\r
+\r
+                               };\r
 \r
                        oParams.onBeforeChange = function()\r
                        {\r
-                               if ( !editor.checkDirty() )\r
-                                       setTimeout( function(){ editor.resetDirty(); } );\r
+                               if ( plugin.getScayt( editor ) && !editor.checkDirty() )\r
+                                       setTimeout( function(){ editor.resetDirty(); }, 0 );\r
                        };\r
 \r
                        var scayt_custom_params = window.scayt_custom_params;\r
-                       if ( typeof scayt_custom_params == 'object')\r
+                       if ( typeof scayt_custom_params == 'object' )\r
                        {\r
                                for ( var k in scayt_custom_params )\r
-                               {\r
                                        oParams[ k ] = scayt_custom_params[ k ];\r
-                               }\r
                        }\r
                        // needs for restoring a specific scayt control settings\r
-                       if ( scayt_control_id )\r
-                               oParams.id = scayt_control_id;\r
+                       if ( plugin.getControlId( editor ) )\r
+                               oParams.id = plugin.getControlId( editor );\r
 \r
                        var scayt_control = new window.scayt( oParams );\r
 \r
+                       scayt_control.afterMarkupRemove.push( function( node )\r
+                       {\r
+                               ( new CKEDITOR.dom.element( node, scayt_control.document ) ).mergeSiblings();\r
+                       } );\r
+\r
                        // Copy config.\r
-                       var     lastInstance = plugin.instances[ editor.name ];\r
+                       var lastInstance = plugin.instances[ editor.name ];\r
                        if ( lastInstance )\r
                        {\r
                                scayt_control.sLang = lastInstance.sLang;\r
@@ -83,12 +100,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        var uiTabs = window.scayt.uiTags;\r
                        var fTabs  = [];\r
 \r
-                       for (var i = 0,l=4; i<l; i++)\r
+                       for ( var i = 0, l=4; i < l; i++ )\r
                            fTabs.push( uiTabs[i] && plugin.uiTabs[i] );\r
 \r
                        plugin.uiTabs = fTabs;\r
                        try {\r
-                               scayt_control.setDisabled( scayt_paused === false );\r
+                               scayt_control.setDisabled( plugin.isPaused( editor ) === false );\r
                        } catch (e) {}\r
 \r
                        editor.fire( 'showScaytState' );\r
@@ -115,35 +132,56 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                editor.on( 'beforeCommandExec', function( ev )          // Disable SCAYT before Source command execution.\r
                        {\r
-                               if ( (ev.data.name == 'source' ||  ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )\r
+                               if ( ( ev.data.name == 'source' || ev.data.name == 'newpage' ) && editor.mode == 'wysiwyg' )\r
                                {\r
                                        var scayt_instance = plugin.getScayt( editor );\r
                                        if ( scayt_instance )\r
                                        {\r
-                                               scayt_paused = scayt_instance.paused = !scayt_instance.disabled;\r
+                                               plugin.setPaused( editor, !scayt_instance.disabled );\r
                                                // store a control id for restore a specific scayt control settings\r
-                                               scayt_control_id = scayt_instance.id;\r
+                                               plugin.setControlId( editor, scayt_instance.id );\r
                                                scayt_instance.destroy( true );\r
                                                delete plugin.instances[ editor.name ];\r
                                        }\r
                                }\r
+                               // Catch on source mode switch off (#5720)\r
+                               else if ( ev.data.name == 'source'  && editor.mode == 'source' )\r
+                                       plugin.markControlRestore( editor );\r
+                       });\r
+\r
+               editor.on( 'afterCommandExec', function( ev )\r
+                       {\r
+                               if ( !plugin.isScaytEnabled( editor ) )\r
+                                       return;\r
+\r
+                               if ( editor.mode == 'wysiwyg' && ( ev.data.name == 'undo' || ev.data.name == 'redo' ) )\r
+                                       window.setTimeout( function() { plugin.getScayt( editor ).refresh(); }, 10 );\r
                        });\r
 \r
                editor.on( 'destroy', function( ev )\r
                        {\r
                                var editor = ev.editor,\r
                                        scayt_instance = plugin.getScayt( editor );\r
+\r
+                               // SCAYT instance might already get destroyed by mode switch (#5744).\r
+                               if ( !scayt_instance )\r
+                                       return;\r
+\r
+                               delete plugin.instances[ editor.name ];\r
                                // store a control id for restore a specific scayt control settings\r
-                               scayt_control_id = scayt_instance.id;\r
+                               plugin.setControlId( editor, scayt_instance.id );\r
                                scayt_instance.destroy( true );\r
-                               delete plugin.instances[ editor.name ];\r
                        });\r
 \r
                // Listen to data manipulation to reflect scayt markup.\r
                editor.on( 'afterSetData', function()\r
                        {\r
                                if ( plugin.isScaytEnabled( editor ) ) {\r
-                                       window.setTimeout( function(){ plugin.getScayt( editor ).refresh(); }, 10 );\r
+                                       window.setTimeout( function()\r
+                                               {\r
+                                                       var instance = plugin.getScayt( editor );\r
+                                                       instance && instance.refresh();\r
+                                               }, 10 );\r
                                }\r
                        });\r
 \r
@@ -158,8 +196,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( CKEDITOR.env.ie )\r
                                                editor.getSelection().unlock( true );\r
 \r
-                                       // Swallow any SCAYT engine errors.\r
-                                       window.setTimeout( function(){ scayt_instance.refresh(); }, 10 );\r
+                                       // Return focus to the editor and refresh SCAYT markup (#5573).\r
+                                       window.setTimeout( function()\r
+                                       {\r
+                                               scayt_instance.focus();\r
+                                               scayt_instance.refresh();\r
+                                       }, 10 );\r
                                }\r
                        }, this, null, 50 );\r
 \r
@@ -173,8 +215,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( CKEDITOR.env.ie )\r
                                                editor.getSelection().unlock( true );\r
 \r
-                                       // Swallow any SCAYT engine errors.\r
-                                       window.setTimeout( function(){ scayt_instance.refresh(); },10 );\r
+                                       // Return focus to the editor (#5573)\r
+                                       // Refresh SCAYT markup\r
+                                       window.setTimeout( function()\r
+                                       {\r
+                                               scayt_instance.focus();\r
+                                               scayt_instance.refresh();\r
+                                       }, 10 );\r
                                }\r
                        }, this, null, 50 );\r
 \r
@@ -197,7 +244,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        {\r
                                                span : function( element )\r
                                                {\r
-                                                       if ( element.attributes.scayt_word && element.attributes.scaytid )\r
+                                                       if ( element.attributes[ 'data-scayt_word' ]\r
+                                                                       && element.attributes[ 'data-scaytid' ] )\r
                                                        {\r
                                                                delete element.name;    // Write children, but don't write this node.\r
                                                                return element;\r
@@ -208,14 +256,92 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        );\r
                }\r
 \r
+               // Override Image.equals method avoid CK snapshot module to add SCAYT markup to snapshots. (#5546)\r
+               var undoImagePrototype = CKEDITOR.plugins.undo.Image.prototype;\r
+               undoImagePrototype.equals = CKEDITOR.tools.override( undoImagePrototype.equals, function( org )\r
+               {\r
+                       return function( otherImage )\r
+                       {\r
+                               var thisContents = this.contents,\r
+                                       otherContents = otherImage.contents;\r
+                               var scayt_instance = plugin.getScayt( this.editor );\r
+                               // Making the comparison based on content without SCAYT word markers.\r
+                               if ( scayt_instance && plugin.isScaytReady( this.editor ) )\r
+                               {\r
+                                       // scayt::reset might return value undefined. (#5742)\r
+                                       this.contents = scayt_instance.reset( thisContents ) || '';\r
+                                       otherImage.contents = scayt_instance.reset( otherContents ) || '';\r
+                               }\r
+\r
+                               var retval = org.apply( this, arguments );\r
+\r
+                               this.contents = thisContents;\r
+                               otherImage.contents = otherContents;\r
+                               return retval;\r
+                       };\r
+               });\r
+\r
                if ( editor.document )\r
                        createInstance();\r
        };\r
 \r
-       CKEDITOR.plugins.scayt =\r
+CKEDITOR.plugins.scayt =\r
        {\r
                engineLoaded : false,\r
                instances : {},\r
+               // Data storage for SCAYT control, based on editor instances\r
+               controlInfo : {},\r
+               setControlInfo : function( editor, o )\r
+               {\r
+                       if ( editor && editor.name && typeof ( this.controlInfo[ editor.name ] ) != 'object' )\r
+                               this.controlInfo[ editor.name ] = {};\r
+\r
+                       for ( var infoOpt in o )\r
+                               this.controlInfo[ editor.name ][ infoOpt ] = o[ infoOpt ];\r
+               },\r
+               isControlRestored : function( editor )\r
+               {\r
+                       if ( editor &&\r
+                                       editor.name &&\r
+                                       this.controlInfo[ editor.name ] )\r
+                       {\r
+                               return this.controlInfo[ editor.name ].restored ;\r
+                       }\r
+                       return false;\r
+               },\r
+               markControlRestore : function( editor )\r
+               {\r
+                       this.setControlInfo( editor, { restored:true } );\r
+               },\r
+               setControlId: function( editor, id )\r
+               {\r
+                       this.setControlInfo( editor, { id:id } );\r
+               },\r
+               getControlId: function( editor )\r
+               {\r
+                       if ( editor &&\r
+                                       editor.name &&\r
+                                       this.controlInfo[ editor.name ] &&\r
+                                       this.controlInfo[ editor.name ].id )\r
+                       {\r
+                               return this.controlInfo[ editor.name ].id;\r
+                       }\r
+                       return null;\r
+               },\r
+               setPaused: function( editor , bool )\r
+               {\r
+                       this.setControlInfo( editor, { paused:bool } );\r
+               },\r
+               isPaused: function( editor )\r
+               {\r
+                       if ( editor &&\r
+                                       editor.name &&\r
+                                       this.controlInfo[editor.name] )\r
+                       {\r
+                               return this.controlInfo[editor.name].paused;\r
+                       }\r
+                       return undefined;\r
+               },\r
                getScayt : function( editor )\r
                {\r
                        return this.instances[ editor.name ];\r
@@ -232,9 +358,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                },\r
                loadEngine : function( editor )\r
                {\r
-                       // SCAYT doesn't work with Opera.\r
-                       if ( CKEDITOR.env.opera )\r
-                               return null;\r
+                       // SCAYT doesn't work with Firefox2, Opera.\r
+                       if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera )\r
+                               return editor.fire( 'showScaytState' );\r
 \r
                        if ( this.engineLoaded === true )\r
                                return onEngineLoad.apply( editor );    // Add new instance.\r
@@ -257,34 +383,40 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        var protocol = document.location.protocol;\r
                        // Default to 'http' for unknown.\r
                        protocol = protocol.search( /https?:/) != -1? protocol : 'http:';\r
-                       var baseUrl  = 'svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js';\r
+                       var baseUrl  = 'svc.spellchecker.net/scayt26/loader__base.js';\r
 \r
                        var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl );\r
                        var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  '/';\r
 \r
-                       CKEDITOR._djScaytConfig =\r
+                       if( window.scayt == undefined )\r
                        {\r
-                               baseUrl: scaytConfigBaseUrl,\r
-                               addOnLoad:\r
-                               [\r
-                                       function()\r
-                                       {\r
-                                               CKEDITOR.fireOnce( 'scaytReady' );\r
-                                       }\r
-                               ],\r
-                               isDebug: false\r
-                       };\r
-                       // Append javascript code.\r
-                       CKEDITOR.document.getHead().append(\r
-                               CKEDITOR.document.createElement( 'script',\r
-                                       {\r
-                                               attributes :\r
-                                                       {\r
-                                                               type : 'text/javascript',\r
-                                                               src : scaytUrl\r
-                                                       }\r
-                                       })\r
-                       );\r
+                               CKEDITOR._djScaytConfig =\r
+                               {\r
+                                       baseUrl: scaytConfigBaseUrl,\r
+                                       addOnLoad:\r
+                                       [\r
+                                               function()\r
+                                               {\r
+                                                       CKEDITOR.fireOnce( 'scaytReady' );\r
+                                               }\r
+                                       ],\r
+                                       isDebug: false\r
+                               };\r
+                               // Append javascript code.\r
+                               CKEDITOR.document.getHead().append(\r
+                                       CKEDITOR.document.createElement( 'script',\r
+                                               {\r
+                                                       attributes :\r
+                                                               {\r
+                                                                       type : 'text/javascript',\r
+                                                                       async : 'true',\r
+                                                                       src : scaytUrl\r
+                                                               }\r
+                                               })\r
+                               );\r
+                       }\r
+                       else\r
+                               CKEDITOR.fireOnce( 'scaytReady' );\r
 \r
                        return null;\r
                },\r
@@ -319,6 +451,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        {\r
                preserveState : true,\r
                editorFocus : false,\r
+               canUndo : false,\r
 \r
                exec: function( editor )\r
                {\r
@@ -329,19 +462,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );\r
 \r
                                var scayt_control = plugin.getScayt( editor );\r
+                               // the place where the status of editor focus should be restored\r
+                               // after there will be ability to store its state before SCAYT button click\r
+                               // if (storedFocusState is focused )\r
+                               //   scayt_control.focus();\r
+                               //\r
+                               // now focus is set certainly\r
+                               scayt_control.focus();\r
                                scayt_control.setDisabled( isEnabled );\r
                        }\r
                        else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 )        // Load first time\r
                        {\r
                                this.setState( CKEDITOR.TRISTATE_DISABLED );\r
-\r
-                               editor.on( 'showScaytState', function()\r
-                                       {\r
-                                               this.removeListener();\r
-                                               this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
-                                       },\r
-                                       this);\r
-\r
                                plugin.loadEngine( editor );\r
                        }\r
                }\r
@@ -354,14 +486,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                beforeInit : function( editor )\r
                {\r
-                       // Register own rbc menu group.\r
-                       editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups;\r
+                       var items_order = editor.config.scayt_contextMenuItemsOrder\r
+                                       || 'suggest|moresuggest|control',\r
+                               items_order_str = "";\r
+\r
+                       items_order = items_order.split( '|' );\r
+\r
+                       if ( items_order && items_order.length )\r
+                       {\r
+                               for ( var pos = 0 ; pos < items_order.length ; pos++ )\r
+                                       items_order_str += 'scayt_' + items_order[ pos ] + ( items_order.length != parseInt( pos, 10 ) + 1 ? ',' : '' );\r
+                       }\r
+\r
+                       // Put it on top of all context menu items (#5717)\r
+                       editor.config.menu_groups =  items_order_str + ',' + editor.config.menu_groups;\r
                },\r
 \r
                init : function( editor )\r
                {\r
-                       var moreSuggestions = {};\r
-                       var mainSuggestions = {};\r
+                       var moreSuggestions = {},\r
+                               mainSuggestions = {};\r
 \r
                        // Scayt command.\r
                        var command = editor.addCommand( commandName, commandDefinition );\r
@@ -374,9 +518,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // string to array convert\r
                        confuiTabs = confuiTabs.split( ',' );\r
                        // check array length ! always must be 3 filled with 1 or 0\r
-                       for (var i=0,l=3; i<l; i++)\r
+                       for ( var i=0, l=3; i < l; i++ )\r
                        {\r
-                               var flag = parseInt(confuiTabs[i] || '1' ,10);\r
+                               var flag = parseInt( confuiTabs[i] || '1', 10 );\r
                                uiTabs.push( flag );\r
                        }\r
 \r
@@ -385,18 +529,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // combine menu items to render\r
                        var uiMuneItems = {};\r
 \r
+                       var lang = editor.lang.scayt;\r
+\r
                        // always added\r
                        uiMuneItems.scaytToggle =\r
                                {\r
-                                       label : editor.lang.scayt.enable,\r
+                                       label : lang.enable,\r
                                        command : commandName,\r
                                        group : menuGroup\r
                                };\r
 \r
-                       if (uiTabs[0] == 1)\r
+                       if ( uiTabs[0] == 1 )\r
                                uiMuneItems.scaytOptions =\r
                                {\r
-                                       label : editor.lang.scayt.options,\r
+                                       label : lang.options,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -405,10 +551,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        }\r
                                };\r
 \r
-                       if (uiTabs[1] == 1)\r
+                       if ( uiTabs[1] == 1 )\r
                                uiMuneItems.scaytLangs =\r
                                {\r
-                                       label : editor.lang.scayt.langs,\r
+                                       label : lang.langs,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -416,10 +562,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                editor.openDialog( commandName );\r
                                        }\r
                                };\r
-                       if (uiTabs[2] == 1)\r
+                       if ( uiTabs[2] == 1 )\r
                                uiMuneItems.scaytDict =\r
                                {\r
-                                       label : editor.lang.scayt.dictionariesTab,\r
+                                       label : lang.dictionariesTab,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -437,8 +583,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                openPage = 'about';\r
                                                editor.openDialog( commandName );\r
                                        }\r
-                               }\r
-                       ;\r
+                               };\r
 \r
                        uiTabs[3] = 1; // about us tab is always on\r
                        plugin.uiTabs = uiTabs;\r
@@ -447,9 +592,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,\r
                                        {\r
-                                               label : editor.lang.scayt.title,\r
-                                               title : editor.lang.scayt.title,\r
+                                               label : lang.title,\r
+                                               title : CKEDITOR.env.opera ? lang.opera_title : lang.title,\r
                                                className : 'cke_button_scayt',\r
+                                               modes : { wysiwyg : 1 },\r
                                                onRender: function()\r
                                                {\r
                                                        command.on( 'state', function()\r
@@ -462,7 +608,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                {\r
                                                        var isEnabled = plugin.isScaytEnabled( editor );\r
 \r
-                                                       editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ];\r
+                                                       editor.getMenuItem( 'scaytToggle' ).label = lang[ isEnabled ? 'disable' : 'enable' ];\r
 \r
                                                        return {\r
                                                                scaytToggle  : CKEDITOR.TRISTATE_OFF,\r
@@ -477,9 +623,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // If the "contextmenu" plugin is loaded, register the listeners.\r
                        if ( editor.contextMenu && editor.addMenuItems )\r
                        {\r
-                               editor.contextMenu.addListener( function(  )\r
+                               editor.contextMenu.addListener( function( element, selection )\r
                                        {\r
-                                               if ( !plugin.isScaytEnabled( editor ) )\r
+                                               if ( !plugin.isScaytEnabled( editor )\r
+                                                               || selection.getCommonAncestor().isReadOnly() )\r
                                                        return null;\r
 \r
                                                var scayt_control = plugin.getScayt( editor ),\r
@@ -530,7 +677,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        return {\r
                                                                                exec: function()\r
                                                                                {\r
-                                                                                       scayt_control.replace(el, s);\r
+                                                                                       scayt_control.replace( el, s );\r
                                                                                }\r
                                                                        };\r
                                                                })( node, items_suggestion[i] );\r
@@ -556,7 +703,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        // Register the More suggestions group;\r
                                                        editor.addMenuItem( 'scayt_moresuggest',\r
                                                        {\r
-                                                               label : editor.lang.scayt.moreSuggestions,\r
+                                                               label : lang.moreSuggestions,\r
                                                                group : 'scayt_moresuggest',\r
                                                                order : 10,\r
                                                                getItems : function()\r
@@ -574,7 +721,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        scayt_control.ignore( node );\r
                                                                }\r
                                                        };\r
-                                                       addButtonCommand( editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1 );\r
+                                                       addButtonCommand( editor, 'ignore', lang.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1 );\r
                                                        mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;\r
                                                }\r
 \r
@@ -585,7 +732,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        scayt_control.ignoreAll( node );\r
                                                                }\r
                                                        };\r
-                                                       addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);\r
+                                                       addButtonCommand(editor, 'ignore_all', lang.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);\r
                                                        mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;\r
                                                }\r
 \r
@@ -596,7 +743,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                        window.scayt.addWordToUserDictionary( node );\r
                                                                }\r
                                                        };\r
-                                                       addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);\r
+                                                       addButtonCommand(editor, 'add_word', lang.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);\r
                                                        mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF;\r
                                                }\r
 \r
@@ -607,15 +754,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        });\r
                        }\r
 \r
-                       // Start plugin\r
-                       if ( editor.config.scayt_autoStartup )\r
-                       {\r
-                               var showInitialState = function()\r
+                       var showInitialState = function()\r
                                {\r
                                        editor.removeListener( 'showScaytState', showInitialState );\r
-                                       command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
+\r
+                                       if ( !CKEDITOR.env.opera )\r
+                                               command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
+                                       else\r
+                                               command.setState( CKEDITOR.TRISTATE_DISABLED );\r
                                };\r
-                               editor.on( 'showScaytState', showInitialState );\r
+\r
+                       editor.on( 'showScaytState', showInitialState );\r
+\r
+                       if ( CKEDITOR.env.opera )\r
+                       {\r
+                               editor.on( 'instanceReady', function()\r
+                               {\r
+                                       showInitialState();\r
+                               });\r
+                       }\r
+\r
+                       // Start plugin\r
+                       if ( editor.config.scayt_autoStartup )\r
+                       {\r
                                editor.on( 'instanceReady', function()\r
                                {\r
                                        plugin.loadEngine( editor );\r
@@ -625,16 +786,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                afterInit : function( editor )\r
                {\r
-                       // Prevent word marker line from displaying in elements path. (#3570)\r
-                       var elementsPathFilters;\r
+                       // Prevent word marker line from displaying in elements path and been removed when cleaning format. (#3570) (#4125)\r
+                       var elementsPathFilters,\r
+                                       scaytFilter = function( element )\r
+                                       {\r
+                                               if ( element.hasAttribute( 'data-scaytid' ) )\r
+                                                       return false;\r
+                                       };\r
+\r
                        if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )\r
-                       {\r
-                               elementsPathFilters.push( function( element )\r
-                               {\r
-                                       if ( element.hasAttribute( 'scaytid' ) )\r
-                                               return false;\r
-                               } );\r
-                       }\r
+                               elementsPathFilters.push( scaytFilter );\r
+\r
+                       editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter );\r
 \r
                }\r
        });\r
@@ -765,3 +928,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * @example\r
  * config.scayt_userDictionaryName = 'MyDictionary';\r
  */\r
+\r
+/**\r
+ * Define order of placing of SCAYT context menu items by groups.\r
+ * It must be a string with one or more of the following\r
+ * words separated by a pipe ("|"):\r
+ * <ul>\r
+ *     <li>'suggest'     - main suggestion word list,</li>\r
+ *     <li>'moresuggest' - more suggestions word list,</li>\r
+ *     <li>'control'     - SCAYT commands, such as 'Ignore' and 'Add Word'</li>\r
+ * </ul>\r
+ *\r
+ * @name CKEDITOR.config.scayt_contextMenuItemsOrder\r
+ * @type String\r
+ * @default 'suggest|moresuggest|control'\r
+ * @example\r
+ * config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest';\r
+ */\r