JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.6.1
[ckeditor.git] / _source / plugins / scayt / plugin.js
index ec64fed..84756ba 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -10,18 +10,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       var commandName         = 'scaytcheck',\r
-               openPage                = '';\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
@@ -34,16 +35,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                var createInstance = function() // Create new instance every time Document is created.\r
                {\r
+                       if( plugin.instances[ editor.name ] )\r
+                               plugin.instances[ editor.name ].destroy();\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
@@ -66,26 +71,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        };\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 ( plugin.getControlId(editor) )\r
-                               oParams.id = plugin.getControlId(editor);\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
@@ -95,15 +97,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        plugin.instances[ editor.name ] = scayt_control;\r
 \r
-                       //window.scayt.uiTags\r
-                       var menuGroup = 'scaytButton';\r
-                       var uiTabs = window.scayt.uiTags;\r
-                       var fTabs  = [];\r
-\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( plugin.isPaused( editor ) === false );\r
                        } catch (e) {}\r
@@ -111,13 +104,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        editor.fire( 'showScaytState' );\r
                };\r
 \r
-               editor.on( 'contentDom', createInstance );\r
+               editor.on( 'contentDom', function(ev)\r
+                       {\r
+                               createInstance();\r
+                       });\r
                editor.on( 'contentDomUnload', function()\r
                        {\r
                                // Remove scripts.\r
                                var scripts = CKEDITOR.document.getElementsByTag( 'script' ),\r
                                        scaytIdRegex =  /^dojoIoScript(\d+)$/i,\r
-                                       scaytSrcRegex =  /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;\r
+                                       scaytSrcRegex =  /^https?:\/\/svc\.webspellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;\r
 \r
                                for ( var i=0; i < scripts.count(); i++ )\r
                                {\r
@@ -132,20 +128,7 @@ 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
-                               {\r
-                                       var scayt_instance = plugin.getScayt( editor );\r
-                                       if ( scayt_instance )\r
-                                       {\r
-                                               plugin.setPaused( editor, !scayt_instance.disabled );\r
-                                               // store a control id for restore a specific scayt control settings\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
+                               if ( ev.data.name == 'source'  && editor.mode == 'source' )\r
                                        plugin.markControlRestore( editor );\r
                        });\r
 \r
@@ -157,7 +140,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                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
@@ -172,17 +154,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                plugin.setControlId( editor, scayt_instance.id );\r
                                scayt_instance.destroy( true );\r
                        });\r
-\r
-               // Listen to data manipulation to reflect scayt markup.\r
-               editor.on( 'afterSetData', function()\r
+               //#9439 after SetData method fires contentDom event and SCAYT create additional instanse\r
+               // This way we should destroy SCAYT on setData event when contenteditable Iframe was re-created\r
+               editor.on( 'setData', function( ev )\r
                        {\r
-                               if ( plugin.isScaytEnabled( editor ) ) {\r
-                                       window.setTimeout( function()\r
-                                               {\r
-                                                       var instance = plugin.getScayt( editor );\r
-                                                       instance && instance.refresh();\r
-                                               }, 10 );\r
-                               }\r
+                               var scayt_instance = plugin.getScayt( editor );\r
+                                       if ( scayt_instance )\r
+                                       {\r
+                                               plugin.setPaused( editor, !scayt_instance.disabled );\r
+                                               // store a control id for restore a specific scayt control settings\r
+                                               plugin.setControlId( editor, scayt_instance.id );\r
+                                               scayt_instance.destroy( true );\r
+                                               delete plugin.instances[ editor.name ];\r
+                                       }\r
                        });\r
 \r
                // Reload spell-checking for current word after insertion completed.\r
@@ -244,7 +228,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
@@ -257,7 +242,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \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
+               undoImagePrototype.equals = CKEDITOR.tools.override( undoImagePrototype.equals, function( org )\r
                {\r
                        return function( otherImage )\r
                        {\r
@@ -298,7 +283,7 @@ CKEDITOR.plugins.scayt =
                        for ( var infoOpt in o )\r
                                this.controlInfo[ editor.name ][ infoOpt ] = o[ infoOpt ];\r
                },\r
-               isControlRestored : function ( editor )\r
+               isControlRestored : function( editor )\r
                {\r
                        if ( editor &&\r
                                        editor.name &&\r
@@ -308,15 +293,15 @@ CKEDITOR.plugins.scayt =
                        }\r
                        return false;\r
                },\r
-               markControlRestore : function ( editor )\r
+               markControlRestore : function( editor )\r
                {\r
-                       this.setControlInfo( editor,{ restored:true } );\r
+                       this.setControlInfo( editor, { restored:true } );\r
                },\r
-               setControlId: function (editor, id)\r
+               setControlId: function( editor, id )\r
                {\r
-                       this.setControlInfo( editor,{ id:id } );\r
+                       this.setControlInfo( editor, { id:id } );\r
                },\r
-               getControlId: function (editor)\r
+               getControlId: function( editor )\r
                {\r
                        if ( editor &&\r
                                        editor.name &&\r
@@ -327,17 +312,17 @@ CKEDITOR.plugins.scayt =
                        }\r
                        return null;\r
                },\r
-               setPaused: function ( editor , bool )\r
+               setPaused: function( editor , bool )\r
                {\r
-                       this.setControlInfo( editor,{ paused:bool } );\r
+                       this.setControlInfo( editor, { paused:bool } );\r
                },\r
-               isPaused: function (editor)\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
+                               return this.controlInfo[editor.name].paused;\r
                        }\r
                        return undefined;\r
                },\r
@@ -355,16 +340,41 @@ CKEDITOR.plugins.scayt =
                        var scayt_instance = this.getScayt( editor );\r
                        return ( scayt_instance ) ? scayt_instance.disabled === false : false;\r
                },\r
+               getUiTabs : function( editor )\r
+               {\r
+                       var uiTabs = [];\r
+\r
+                       // read UI tabs value from config\r
+                       var configUiTabs = editor.config.scayt_uiTabs || "1,1,1";\r
+\r
+                       // convert string to array\r
+                       configUiTabs = configUiTabs.split( ',' );\r
+\r
+                       // "About us" should be always shown for standard config\r
+                       configUiTabs[3] = "1";\r
+\r
+                       for ( var i = 0; i < 4; i++ ) {\r
+                               uiTabs[i] = (typeof window.scayt != "undefined" && typeof window.scayt.uiTags != "undefined")\r
+                                                               ? (parseInt(configUiTabs[i],10) && window.scayt.uiTags[i])\r
+                                                               : parseInt(configUiTabs[i],10);\r
+                       }\r
+                       return uiTabs;\r
+               },\r
                loadEngine : function( editor )\r
                {\r
-                       // SCAYT doesn't work with Firefox2, Opera.\r
-                       if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera )\r
+                       // SCAYT doesn't work with Firefox2, Opera and AIR.\r
+                       if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera || CKEDITOR.env.air )\r
                                return editor.fire( 'showScaytState' );\r
 \r
                        if ( this.engineLoaded === true )\r
-                               return onEngineLoad.apply( editor );    // Add new instance.\r
-                       else if ( this.engineLoaded == -1 )                     // We are waiting.\r
+                       {\r
+                               return onEngineLoad.apply( editor );\r
+                       }\r
+                               // Add new instance.\r
+                       else if ( this.engineLoaded == -1 )\r
+                       {       // We are waiting.\r
                                return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor ); } );        // Use function(){} to avoid rejection as duplicate.\r
+                       }\r
 \r
                        CKEDITOR.on( 'scaytReady', onEngineLoad, editor );\r
                        CKEDITOR.on( 'scaytReady', function()\r
@@ -382,7 +392,7 @@ CKEDITOR.plugins.scayt =
                        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/scayt25/loader__base.js';\r
+                       var baseUrl  = 'svc.webspellchecker.net/scayt26/loader__base.js';\r
 \r
                        var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl );\r
                        var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  '/';\r
@@ -415,7 +425,9 @@ CKEDITOR.plugins.scayt =
                                );\r
                        }\r
                        else\r
+                       {\r
                                CKEDITOR.fireOnce( 'scaytReady' );\r
+                       }\r
 \r
                        return null;\r
                },\r
@@ -450,6 +462,7 @@ CKEDITOR.plugins.scayt =
        {\r
                preserveState : true,\r
                editorFocus : false,\r
+               canUndo : false,\r
 \r
                exec: function( editor )\r
                {\r
@@ -466,7 +479,7 @@ CKEDITOR.plugins.scayt =
                                //   scayt_control.focus();\r
                                //\r
                                // now focus is set certainly\r
-                               scayt_control.focus( );\r
+                               scayt_control.focus();\r
                                scayt_control.setDisabled( isEnabled );\r
                        }\r
                        else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 )        // Load first time\r
@@ -492,7 +505,7 @@ CKEDITOR.plugins.scayt =
 \r
                        if ( items_order && items_order.length )\r
                        {\r
-                               for ( var pos in items_order )\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
@@ -502,43 +515,52 @@ CKEDITOR.plugins.scayt =
 \r
                init : function( editor )\r
                {\r
-                       var moreSuggestions = {};\r
-                       var mainSuggestions = {};\r
+                       // Delete span[data-scaytid] when text pasting in editor (#6921)\r
+                       var dataFilter = editor.dataProcessor && editor.dataProcessor.dataFilter;\r
+                       var dataFilterRules =\r
+                       {\r
+                                       elements :\r
+                                       {\r
+                                                       span : function( element )\r
+                                                       {\r
+                                                                       var attrs = element.attributes;\r
+                                                                       if ( attrs && attrs[ 'data-scaytid' ] )\r
+                                                                                       delete element.name;\r
+                                                       }\r
+                                       }\r
+                       };\r
+                       dataFilter && dataFilter.addRules( dataFilterRules );\r
+\r
+                       var moreSuggestions = {},\r
+                               mainSuggestions = {};\r
 \r
                        // Scayt command.\r
                        var command = editor.addCommand( commandName, commandDefinition );\r
 \r
                        // Add Options dialog.\r
                        CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );\r
-                       // read ui tags\r
-                       var confuiTabs = editor.config.scayt_uiTabs || '1,1,1';\r
-                       var uiTabs =[];\r
-                       // 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
-                       {\r
-                               var flag = parseInt(confuiTabs[i] || '1' ,10);\r
-                               uiTabs.push( flag );\r
-                       }\r
+\r
+                       var uiTabs = plugin.getUiTabs( editor );\r
 \r
                        var menuGroup = 'scaytButton';\r
                        editor.addMenuGroup( menuGroup );\r
                        // combine menu items to render\r
-                       var uiMuneItems = {};\r
+                       var uiMenuItems = {};\r
+\r
+                       var lang = editor.lang.scayt;\r
 \r
                        // always added\r
-                       uiMuneItems.scaytToggle =\r
+                       uiMenuItems.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
-                               uiMuneItems.scaytOptions =\r
+                       if ( uiTabs[0] == 1 )\r
+                               uiMenuItems.scaytOptions =\r
                                {\r
-                                       label : editor.lang.scayt.options,\r
+                                       label : lang.options,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -547,10 +569,10 @@ CKEDITOR.plugins.scayt =
                                        }\r
                                };\r
 \r
-                       if (uiTabs[1] == 1)\r
-                               uiMuneItems.scaytLangs =\r
+                       if ( uiTabs[1] == 1 )\r
+                               uiMenuItems.scaytLangs =\r
                                {\r
-                                       label : editor.lang.scayt.langs,\r
+                                       label : lang.langs,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -558,10 +580,10 @@ CKEDITOR.plugins.scayt =
                                                editor.openDialog( commandName );\r
                                        }\r
                                };\r
-                       if (uiTabs[2] == 1)\r
-                               uiMuneItems.scaytDict =\r
+                       if ( uiTabs[2] == 1 )\r
+                               uiMenuItems.scaytDict =\r
                                {\r
-                                       label : editor.lang.scayt.dictionariesTab,\r
+                                       label : lang.dictionariesTab,\r
                                        group : menuGroup,\r
                                        onClick : function()\r
                                        {\r
@@ -570,7 +592,7 @@ CKEDITOR.plugins.scayt =
                                        }\r
                                };\r
                        // always added\r
-                       uiMuneItems.scaytAbout =\r
+                       uiMenuItems.scaytAbout =\r
                                {\r
                                        label : editor.lang.scayt.about,\r
                                        group : menuGroup,\r
@@ -579,19 +601,16 @@ CKEDITOR.plugins.scayt =
                                                openPage = 'about';\r
                                                editor.openDialog( commandName );\r
                                        }\r
-                               }\r
-                       ;\r
-\r
-                       uiTabs[3] = 1; // about us tab is always on\r
-                       plugin.uiTabs = uiTabs;\r
+                               };\r
 \r
-                       editor.addMenuItems( uiMuneItems );\r
+                       editor.addMenuItems( uiMenuItems );\r
 \r
                                editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,\r
                                        {\r
-                                               label : editor.lang.scayt.title,\r
-                                               title : CKEDITOR.env.opera ? editor.lang.scayt.opera_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
@@ -604,14 +623,16 @@ CKEDITOR.plugins.scayt =
                                                {\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
+                                                       var uiTabs = plugin.getUiTabs( editor );\r
 \r
                                                        return {\r
                                                                scaytToggle  : CKEDITOR.TRISTATE_OFF,\r
-                                                               scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
-                                                               scaytLangs   : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
-                                                               scaytDict    : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
-                                                               scaytAbout   : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED\r
+                                                               scaytOptions : isEnabled && uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                               scaytLangs   : isEnabled && uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                               scaytDict    : isEnabled && uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
+                                                               scaytAbout   : isEnabled && uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED\r
                                                        };\r
                                                }\r
                                        });\r
@@ -622,7 +643,7 @@ CKEDITOR.plugins.scayt =
                                editor.contextMenu.addListener( function( element, selection )\r
                                        {\r
                                                if ( !plugin.isScaytEnabled( editor )\r
-                                                               || selection.getCommonAncestor().isReadOnly() )\r
+                                                               || selection.getRanges()[ 0 ].checkReadOnly() )\r
                                                        return null;\r
 \r
                                                var scayt_control = plugin.getScayt( editor ),\r
@@ -637,20 +658,17 @@ CKEDITOR.plugins.scayt =
                                                        return null;\r
 \r
                                                var sLang = scayt_control.getLang(),\r
-                                                       _r = {},\r
                                                        items_suggestion = window.scayt.getSuggestion( word, sLang );\r
-                                               if ( !items_suggestion || !items_suggestion.length )\r
-                                                       return null;\r
                                                // Remove unused commands and menuitems\r
-                                               for ( i in moreSuggestions )\r
+                                               for ( var m in moreSuggestions )\r
                                                {\r
-                                                       delete editor._.menuItems[ i ];\r
-                                                       delete editor._.commands[ i ];\r
+                                                       delete editor._.menuItems[ m ];\r
+                                                       delete editor._.commands[ m ];\r
                                                }\r
-                                               for ( i in mainSuggestions )\r
+                                               for ( m in mainSuggestions )\r
                                                {\r
-                                                       delete editor._.menuItems[ i ];\r
-                                                       delete editor._.commands[ i ];\r
+                                                       delete editor._.menuItems[ m ];\r
+                                                       delete editor._.commands[ m ];\r
                                                }\r
                                                moreSuggestions = {};           // Reset items.\r
                                                mainSuggestions = {};\r
@@ -665,49 +683,60 @@ CKEDITOR.plugins.scayt =
                                                var contextCommands = editor.config.scayt_contextCommands || 'all';\r
                                                contextCommands = contextCommands.split( '|' );\r
 \r
-                                               for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )\r
-                                               {\r
-                                                       var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );\r
-                                                       var exec = ( function( el, s )\r
-                                                               {\r
-                                                                       return {\r
-                                                                               exec: function()\r
-                                                                               {\r
-                                                                                       scayt_control.replace(el, s);\r
-                                                                               }\r
-                                                                       };\r
-                                                               })( node, items_suggestion[i] );\r
-\r
-                                                       if ( i < maxSuggestions )\r
+                                               if ( items_suggestion && items_suggestion.length ) {\r
+                                                       for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )\r
                                                        {\r
-                                                               addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
-                                                                       commandName, exec, 'scayt_suggest', i + 1 );\r
-                                                               _r[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
-                                                               mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
+                                                               var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );\r
+                                                               var exec = ( function( el, s )\r
+                                                                       {\r
+                                                                               return {\r
+                                                                                       exec: function()\r
+                                                                                       {\r
+                                                                                               scayt_control.replace(el, s);\r
+                                                                                       }\r
+                                                                               };\r
+                                                                       })( node, items_suggestion[i] );\r
+\r
+                                                               if ( i < maxSuggestions )\r
+                                                               {\r
+                                                                       addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
+                                                                               commandName, exec, 'scayt_suggest', i + 1 );\r
+                                                                       mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
+                                                               }\r
+                                                               else if ( moreSuggestionsUnable == 'on' )\r
+                                                               {\r
+                                                                       addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
+                                                                               commandName, exec, 'scayt_moresuggest', i + 1 );\r
+                                                                       moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
+                                                                       moreSuggestionsUnableAdded = true;\r
+                                                               }\r
                                                        }\r
-                                                       else if ( moreSuggestionsUnable == 'on' )\r
+\r
+                                                       if ( moreSuggestionsUnableAdded )\r
                                                        {\r
-                                                               addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
-                                                                       commandName, exec, 'scayt_moresuggest', i + 1 );\r
-                                                               moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
-                                                               moreSuggestionsUnableAdded = true;\r
+                                                               // Register the More suggestions group;\r
+                                                               editor.addMenuItem( 'scayt_moresuggest',\r
+                                                               {\r
+                                                                       label : editor.lang.scayt.moreSuggestions,\r
+                                                                       group : 'scayt_moresuggest',\r
+                                                                       order : 10,\r
+                                                                       getItems : function()\r
+                                                                       {\r
+                                                                               return moreSuggestions;\r
+                                                                       }\r
+                                                               });\r
+                                                               mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;\r
                                                        }\r
                                                }\r
-\r
-                                               if ( moreSuggestionsUnableAdded )\r
-                                               {\r
-                                                       // Register the More suggestions group;\r
-                                                       editor.addMenuItem( 'scayt_moresuggest',\r
+                                               else {\r
+                                                       // "No suggestions" feature\r
+                                                       editor.addMenuItem( 'scayt_nosuggest',\r
                                                        {\r
-                                                               label : editor.lang.scayt.moreSuggestions,\r
-                                                               group : 'scayt_moresuggest',\r
-                                                               order : 10,\r
-                                                               getItems : function()\r
-                                                               {\r
-                                                                       return moreSuggestions;\r
-                                                               }\r
+                                                               label : editor.lang.scayt.noSuggestions ? editor.lang.scayt.noSuggestions : (editor.lang.spellCheck.noSuggestions ? editor.lang.spellCheck.noSuggestions : 'No suggestions'),\r
+                                                               group : 'scayt_suggest',\r
+                                                               order : 1\r
                                                        });\r
-                                                       mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;\r
+                                                       mainSuggestions[ 'scayt_nosuggest' ] = CKEDITOR.TRISTATE_OFF;\r
                                                }\r
 \r
                                                if ( in_array( 'all', contextCommands )  || in_array( 'ignore', contextCommands)  )\r
@@ -717,7 +746,7 @@ CKEDITOR.plugins.scayt =
                                                                        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
@@ -728,7 +757,7 @@ CKEDITOR.plugins.scayt =
                                                                        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
@@ -739,7 +768,7 @@ CKEDITOR.plugins.scayt =
                                                                        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
@@ -754,7 +783,7 @@ CKEDITOR.plugins.scayt =
                                {\r
                                        editor.removeListener( 'showScaytState', showInitialState );\r
 \r
-                                       if ( !CKEDITOR.env.opera )\r
+                                       if ( !CKEDITOR.env.opera && !CKEDITOR.env.air )\r
                                                command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
                                        else\r
                                                command.setState( CKEDITOR.TRISTATE_DISABLED );\r
@@ -762,7 +791,7 @@ CKEDITOR.plugins.scayt =
 \r
                        editor.on( 'showScaytState', showInitialState );\r
 \r
-                       if ( CKEDITOR.env.opera )\r
+                       if ( CKEDITOR.env.opera || CKEDITOR.env.air )\r
                        {\r
                                editor.on( 'instanceReady', function()\r
                                {\r
@@ -786,7 +815,7 @@ CKEDITOR.plugins.scayt =
                        var elementsPathFilters,\r
                                        scaytFilter = function( element )\r
                                        {\r
-                                               if ( element.hasAttribute( 'scaytid' ) )\r
+                                               if ( element.hasAttribute( 'data-scaytid' ) )\r
                                                        return false;\r
                                        };\r
 \r
@@ -800,27 +829,28 @@ CKEDITOR.plugins.scayt =
 })();\r
 \r
 /**\r
- * If enabled (true), turns on SCAYT automatically after loading the editor.\r
+ * If enabled (set to <code>true</code>), turns on SCAYT automatically\r
+ * after loading the editor.\r
  * @name CKEDITOR.config.scayt_autoStartup\r
  * @type Boolean\r
- * @default false\r
+ * @default <code>false</code>\r
  * @example\r
  * config.scayt_autoStartup = true;\r
  */\r
 \r
 /**\r
  * Defines the number of SCAYT suggestions to show in the main context menu.\r
- * The possible values are:\r
+ * Possible values are:\r
  * <ul>\r
- *     <li>0 (zero): All suggestions are displayed in the main context menu.</li>\r
- *     <li>Positive number: The maximum number of suggestions to shown in context\r
- *             menu. Other entries will be shown in "More Suggestions" sub-menu.</li>\r
- *     <li>Negative number: No suggestions are shown in the main context menu. All\r
- *             entries will be listed in the "Suggestions" sub-menu.</li>\r
+ *     <li><code>0</code> (zero) &ndash; All suggestions are displayed in the main context menu.</li>\r
+ *     <li>Positive number &ndash; The maximum number of suggestions to show in the context\r
+ *             menu. Other entries will be shown in the "More Suggestions" sub-menu.</li>\r
+ *     <li>Negative number &ndash; No suggestions are shown in the main context menu. All\r
+ *             entries will be listed in the the "Suggestions" sub-menu.</li>\r
  * </ul>\r
  * @name CKEDITOR.config.scayt_maxSuggestions\r
  * @type Number\r
- * @default 5\r
+ * @default <code>5</code>\r
  * @example\r
  * // Display only three suggestions in the main context menu.\r
  * config.scayt_maxSuggestions = 3;\r
@@ -830,11 +860,11 @@ CKEDITOR.plugins.scayt =
  */\r
 \r
 /**\r
- * Sets the customer ID for SCAYT. Required for migration from free version\r
- * with banner to paid version.\r
+ * Sets the customer ID for SCAYT. Required for migration from free,\r
+ * ad-supported version to paid, ad-free version.\r
  * @name CKEDITOR.config.scayt_customerid\r
  * @type String\r
- * @default ''\r
+ * @default <code>''</code>\r
  * @example\r
  * // Load SCAYT using my customer ID.\r
  * config.scayt_customerid  = 'your-encrypted-customer-id';\r
@@ -842,10 +872,10 @@ CKEDITOR.plugins.scayt =
 \r
 /**\r
  * Enables/disables the "More Suggestions" sub-menu in the context menu.\r
- * The possible values are "on" or "off".\r
+ * Possible values are <code>on</code> and <code>off</code>.\r
  * @name CKEDITOR.config.scayt_moreSuggestions\r
  * @type String\r
- * @default 'on'\r
+ * @default <code>'on'</code>\r
  * @example\r
  * // Disables the "More Suggestions" sub-menu.\r
  * config.scayt_moreSuggestions = 'off';\r
@@ -853,91 +883,99 @@ CKEDITOR.plugins.scayt =
 \r
 /**\r
  * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore"\r
- * and "Ignore All"). It must be a string with one or more of the following\r
- * words separated by a pipe ("|"):\r
+ * and "Ignore All"). This must be a string with one or more of the following\r
+ * words separated by a pipe character ("|"):\r
  * <ul>\r
- *     <li>"off": disables all options.</li>\r
- *     <li>"all": enables all options.</li>\r
- *     <li>"ignore": enables the "Ignore" option.</li>\r
- *     <li>"ignoreall": enables the "Ignore All" option.</li>\r
- *     <li>"add": enables the "Add Word" option.</li>\r
+ *     <li><code>off</code> &ndash; disables all options.</li>\r
+ *     <li><code>all</code> &ndash; enables all options.</li>\r
+ *     <li><code>ignore</code> &ndash; enables the "Ignore" option.</li>\r
+ *     <li><code>ignoreall</code> &ndash; enables the "Ignore All" option.</li>\r
+ *     <li><code>add</code> &ndash; enables the "Add Word" option.</li>\r
  * </ul>\r
  * @name CKEDITOR.config.scayt_contextCommands\r
  * @type String\r
- * @default 'all'\r
+ * @default <code>'all'</code>\r
  * @example\r
  * // Show only "Add Word" and "Ignore All" in the context menu.\r
  * config.scayt_contextCommands = 'add|ignoreall';\r
  */\r
 \r
 /**\r
- * Sets the default spellchecking language for SCAYT.\r
+ * Sets the default spell checking language for SCAYT. Possible values are:\r
+ * <code>en_US</code>, <code>en_GB</code>, <code>pt_BR</code>, <code>da_DK</code>,\r
+ * <code>nl_NL</code>, <code>en_CA</code>, <code>fi_FI</code>, <code>fr_FR</code>,\r
+ * <code>fr_CA</code>, <code>de_DE</code>, <code>el_GR</code>, <code>it_IT</code>,\r
+ * <code>nb_NO</code>, <code>pt_PT</code>, <code>es_ES</code>, <code>sv_SE</code>.\r
  * @name CKEDITOR.config.scayt_sLang\r
  * @type String\r
- * @default 'en_US'\r
+ * @default <code>'en_US'</code>\r
  * @example\r
  * // Sets SCAYT to German.\r
  * config.scayt_sLang = 'de_DE';\r
  */\r
 \r
 /**\r
- * Sets the visibility of the SCAYT tabs in the settings dialog and toolbar\r
- * button. The value must contain a "1" (enabled) or "0" (disabled) number for\r
- * each of the following entries, in this precise order, separated by a\r
- * comma (","): "Options", "Languages" and "Dictionary".\r
+ * Sets the visibility of particular tabs in the SCAYT dialog window and toolbar\r
+ * button. This setting must contain a <code>1</code> (enabled) or <code>0</code>\r
+ * (disabled) value for each of the following entries, in this precise order,\r
+ * separated by a comma (","): "Options", "Languages", and "Dictionary".\r
  * @name CKEDITOR.config.scayt_uiTabs\r
  * @type String\r
- * @default '1,1,1'\r
+ * @default <code>'1,1,1'</code>\r
  * @example\r
- * // Hide the "Languages" tab.\r
+ * // Hides the "Languages" tab.\r
  * config.scayt_uiTabs = '1,0,1';\r
  */\r
 \r
 \r
 /**\r
- * Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application.\r
- * Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l .\r
+ * Sets the URL to SCAYT core. Required to switch to the licensed version of SCAYT application.\r
+ * Further details available at\r
+ * <a href="http://wiki.webspellchecker.net/doku.php?id=migration:hosredfreetolicensedck">\r
+ * http://wiki.webspellchecker.net/doku.php?id=migration:hosredfreetolicensedck</a>.\r
  * @name CKEDITOR.config.scayt_srcUrl\r
  * @type String\r
- * @default ''\r
+ * @default <code>''</code>\r
  * @example\r
  * config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js";\r
  */\r
 \r
 /**\r
- * Links SCAYT to custom dictionaries. It's a string containing dictionary ids\r
- * separared by commas (","). Available only for licensed version.\r
- * Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support .\r
+ * Links SCAYT to custom dictionaries. This is a string containing dictionary IDs\r
+ * separared by commas (","). Available only for the licensed version.\r
+ * Further details at\r
+ * <a href="http://wiki.webspellchecker.net/doku.php?id=installationandconfiguration:customdictionaries:licensed">\r
+ * http://wiki.webspellchecker.net/doku.php?id=installationandconfiguration:customdictionaries:licensed</a>.\r
  * @name CKEDITOR.config.scayt_customDictionaryIds\r
  * @type String\r
- * @default ''\r
+ * @default <code>''</code>\r
  * @example\r
  * config.scayt_customDictionaryIds = '3021,3456,3478"';\r
  */\r
 \r
 /**\r
- * Makes it possible to activate a custom dictionary on SCAYT. The user\r
- * dictionary name must be used. Available only for licensed version.\r
+ * Makes it possible to activate a custom dictionary in SCAYT. The user\r
+ * dictionary name must be used. Available only for the licensed version.\r
  * @name CKEDITOR.config.scayt_userDictionaryName\r
  * @type String\r
- * @default ''\r
+ * @default <code>''</code>\r
  * @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
+ * Defines the order SCAYT context menu items by groups.\r
+ * This must be a string with one or more of the following\r
+ * words separated by a pipe character ("|"):\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
+ *     <li><code>suggest</code> &ndash; main suggestion word list,</li>\r
+ *     <li><code>moresuggest</code> &ndash; more suggestions word list,</li>\r
+ *     <li><code>control</code> &ndash; 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
+ * @default <code>'suggest|moresuggest|control'</code>\r
  * @example\r
  * config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest';\r
  */\r