X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fscayt%2Fplugin.js;h=84756ba157152fdf2f2b774cdca074fbe03e5381;hb=3fe9cac293e090ea459a3ee10d78cbe9e1dd0e03;hp=5a03d5b4c1cb6a2fef3e4751958b0d369f9c3127;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/scayt/plugin.js b/_source/plugins/scayt/plugin.js index 5a03d5b..84756ba 100644 --- a/_source/plugins/scayt/plugin.js +++ b/_source/plugins/scayt/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -35,6 +35,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var createInstance = function() // Create new instance every time Document is created. { + if( plugin.instances[ editor.name ] ) + plugin.instances[ editor.name ].destroy(); + var config = editor.config; // Initialise Scayt instance. var oParams = {}; @@ -78,7 +81,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license oParams.id = plugin.getControlId( editor ); var scayt_control = new window.scayt( oParams ); - scayt_control.afterMarkupRemove.push( function( node ) { ( new CKEDITOR.dom.element( node, scayt_control.document ) ).mergeSiblings(); @@ -95,15 +97,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license plugin.instances[ editor.name ] = scayt_control; - //window.scayt.uiTags - var menuGroup = 'scaytButton'; - var uiTabs = window.scayt.uiTags; - var fTabs = []; - - for ( var i = 0, l=4; i < l; i++ ) - fTabs.push( uiTabs[i] && plugin.uiTabs[i] ); - - plugin.uiTabs = fTabs; try { scayt_control.setDisabled( plugin.isPaused( editor ) === false ); } catch (e) {} @@ -111,13 +104,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.fire( 'showScaytState' ); }; - editor.on( 'contentDom', createInstance ); + editor.on( 'contentDom', function(ev) + { + createInstance(); + }); editor.on( 'contentDomUnload', function() { // Remove scripts. var scripts = CKEDITOR.document.getElementsByTag( 'script' ), scaytIdRegex = /^dojoIoScript(\d+)$/i, - scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i; + scaytSrcRegex = /^https?:\/\/svc\.webspellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i; for ( var i=0; i < scripts.count(); i++ ) { @@ -132,20 +128,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution. { - if ( ( ev.data.name == 'source' || ev.data.name == 'newpage' ) && editor.mode == 'wysiwyg' ) - { - var scayt_instance = plugin.getScayt( editor ); - if ( scayt_instance ) - { - plugin.setPaused( editor, !scayt_instance.disabled ); - // store a control id for restore a specific scayt control settings - plugin.setControlId( editor, scayt_instance.id ); - scayt_instance.destroy( true ); - delete plugin.instances[ editor.name ]; - } - } - // Catch on source mode switch off (#5720) - else if ( ev.data.name == 'source' && editor.mode == 'source' ) + if ( ev.data.name == 'source' && editor.mode == 'source' ) plugin.markControlRestore( editor ); }); @@ -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' ) ) window.setTimeout( function() { plugin.getScayt( editor ).refresh(); }, 10 ); }); - editor.on( 'destroy', function( ev ) { var editor = ev.editor, @@ -172,17 +154,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license plugin.setControlId( editor, scayt_instance.id ); scayt_instance.destroy( true ); }); - - // Listen to data manipulation to reflect scayt markup. - editor.on( 'afterSetData', function() + //#9439 after SetData method fires contentDom event and SCAYT create additional instanse + // This way we should destroy SCAYT on setData event when contenteditable Iframe was re-created + editor.on( 'setData', function( ev ) { - if ( plugin.isScaytEnabled( editor ) ) { - window.setTimeout( function() - { - var instance = plugin.getScayt( editor ); - instance && instance.refresh(); - }, 10 ); - } + var scayt_instance = plugin.getScayt( editor ); + if ( scayt_instance ) + { + plugin.setPaused( editor, !scayt_instance.disabled ); + // store a control id for restore a specific scayt control settings + plugin.setControlId( editor, scayt_instance.id ); + scayt_instance.destroy( true ); + delete plugin.instances[ editor.name ]; + } }); // Reload spell-checking for current word after insertion completed. @@ -356,6 +340,26 @@ CKEDITOR.plugins.scayt = var scayt_instance = this.getScayt( editor ); return ( scayt_instance ) ? scayt_instance.disabled === false : false; }, + getUiTabs : function( editor ) + { + var uiTabs = []; + + // read UI tabs value from config + var configUiTabs = editor.config.scayt_uiTabs || "1,1,1"; + + // convert string to array + configUiTabs = configUiTabs.split( ',' ); + + // "About us" should be always shown for standard config + configUiTabs[3] = "1"; + + for ( var i = 0; i < 4; i++ ) { + uiTabs[i] = (typeof window.scayt != "undefined" && typeof window.scayt.uiTags != "undefined") + ? (parseInt(configUiTabs[i],10) && window.scayt.uiTags[i]) + : parseInt(configUiTabs[i],10); + } + return uiTabs; + }, loadEngine : function( editor ) { // SCAYT doesn't work with Firefox2, Opera and AIR. @@ -363,9 +367,14 @@ CKEDITOR.plugins.scayt = return editor.fire( 'showScaytState' ); if ( this.engineLoaded === true ) - return onEngineLoad.apply( editor ); // Add new instance. - else if ( this.engineLoaded == -1 ) // We are waiting. + { + return onEngineLoad.apply( editor ); + } + // Add new instance. + else if ( this.engineLoaded == -1 ) + { // We are waiting. return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor ); } ); // Use function(){} to avoid rejection as duplicate. + } CKEDITOR.on( 'scaytReady', onEngineLoad, editor ); CKEDITOR.on( 'scaytReady', function() @@ -383,7 +392,7 @@ CKEDITOR.plugins.scayt = var protocol = document.location.protocol; // Default to 'http' for unknown. protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; - var baseUrl = 'svc.spellchecker.net/scayt26/loader__base.js'; + var baseUrl = 'svc.webspellchecker.net/scayt26/loader__base.js'; var scaytUrl = editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl ); var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + '/'; @@ -416,7 +425,9 @@ CKEDITOR.plugins.scayt = ); } else + { CKEDITOR.fireOnce( 'scaytReady' ); + } return null; }, @@ -504,6 +515,22 @@ CKEDITOR.plugins.scayt = init : function( editor ) { + // Delete span[data-scaytid] when text pasting in editor (#6921) + var dataFilter = editor.dataProcessor && editor.dataProcessor.dataFilter; + var dataFilterRules = + { + elements : + { + span : function( element ) + { + var attrs = element.attributes; + if ( attrs && attrs[ 'data-scaytid' ] ) + delete element.name; + } + } + }; + dataFilter && dataFilter.addRules( dataFilterRules ); + var moreSuggestions = {}, mainSuggestions = {}; @@ -512,27 +539,18 @@ CKEDITOR.plugins.scayt = // Add Options dialog. CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) ); - // read ui tags - var confuiTabs = editor.config.scayt_uiTabs || '1,1,1'; - var uiTabs =[]; - // string to array convert - confuiTabs = confuiTabs.split( ',' ); - // check array length ! always must be 3 filled with 1 or 0 - for ( var i=0, l=3; i < l; i++ ) - { - var flag = parseInt( confuiTabs[i] || '1', 10 ); - uiTabs.push( flag ); - } + + var uiTabs = plugin.getUiTabs( editor ); var menuGroup = 'scaytButton'; editor.addMenuGroup( menuGroup ); // combine menu items to render - var uiMuneItems = {}; + var uiMenuItems = {}; var lang = editor.lang.scayt; // always added - uiMuneItems.scaytToggle = + uiMenuItems.scaytToggle = { label : lang.enable, command : commandName, @@ -540,7 +558,7 @@ CKEDITOR.plugins.scayt = }; if ( uiTabs[0] == 1 ) - uiMuneItems.scaytOptions = + uiMenuItems.scaytOptions = { label : lang.options, group : menuGroup, @@ -552,7 +570,7 @@ CKEDITOR.plugins.scayt = }; if ( uiTabs[1] == 1 ) - uiMuneItems.scaytLangs = + uiMenuItems.scaytLangs = { label : lang.langs, group : menuGroup, @@ -563,7 +581,7 @@ CKEDITOR.plugins.scayt = } }; if ( uiTabs[2] == 1 ) - uiMuneItems.scaytDict = + uiMenuItems.scaytDict = { label : lang.dictionariesTab, group : menuGroup, @@ -574,7 +592,7 @@ CKEDITOR.plugins.scayt = } }; // always added - uiMuneItems.scaytAbout = + uiMenuItems.scaytAbout = { label : editor.lang.scayt.about, group : menuGroup, @@ -585,10 +603,7 @@ CKEDITOR.plugins.scayt = } }; - uiTabs[3] = 1; // about us tab is always on - plugin.uiTabs = uiTabs; - - editor.addMenuItems( uiMuneItems ); + editor.addMenuItems( uiMenuItems ); editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON, { @@ -610,12 +625,14 @@ CKEDITOR.plugins.scayt = editor.getMenuItem( 'scaytToggle' ).label = lang[ isEnabled ? 'disable' : 'enable' ]; + var uiTabs = plugin.getUiTabs( editor ); + return { scaytToggle : CKEDITOR.TRISTATE_OFF, - scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, - scaytLangs : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, - scaytDict : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, - scaytAbout : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED + scaytOptions : isEnabled && uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, + scaytLangs : isEnabled && uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, + scaytDict : isEnabled && uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, + scaytAbout : isEnabled && uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED }; } }); @@ -641,20 +658,17 @@ CKEDITOR.plugins.scayt = return null; var sLang = scayt_control.getLang(), - _r = {}, items_suggestion = window.scayt.getSuggestion( word, sLang ); - if ( !items_suggestion || !items_suggestion.length ) - return null; // Remove unused commands and menuitems - for ( i in moreSuggestions ) + for ( var m in moreSuggestions ) { - delete editor._.menuItems[ i ]; - delete editor._.commands[ i ]; + delete editor._.menuItems[ m ]; + delete editor._.commands[ m ]; } - for ( i in mainSuggestions ) + for ( m in mainSuggestions ) { - delete editor._.menuItems[ i ]; - delete editor._.commands[ i ]; + delete editor._.menuItems[ m ]; + delete editor._.commands[ m ]; } moreSuggestions = {}; // Reset items. mainSuggestions = {}; @@ -669,49 +683,60 @@ CKEDITOR.plugins.scayt = var contextCommands = editor.config.scayt_contextCommands || 'all'; contextCommands = contextCommands.split( '|' ); - for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) - { - var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' ); - var exec = ( function( el, s ) - { - return { - exec: function() - { - scayt_control.replace( el, s ); - } - }; - })( node, items_suggestion[i] ); - - if ( i < maxSuggestions ) + if ( items_suggestion && items_suggestion.length ) { + for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) { - addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], - commandName, exec, 'scayt_suggest', i + 1 ); - _r[ commandName ] = CKEDITOR.TRISTATE_OFF; - mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; + var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' ); + var exec = ( function( el, s ) + { + return { + exec: function() + { + scayt_control.replace(el, s); + } + }; + })( node, items_suggestion[i] ); + + if ( i < maxSuggestions ) + { + addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], + commandName, exec, 'scayt_suggest', i + 1 ); + mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; + } + else if ( moreSuggestionsUnable == 'on' ) + { + addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], + commandName, exec, 'scayt_moresuggest', i + 1 ); + moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; + moreSuggestionsUnableAdded = true; + } } - else if ( moreSuggestionsUnable == 'on' ) + + if ( moreSuggestionsUnableAdded ) { - addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], - commandName, exec, 'scayt_moresuggest', i + 1 ); - moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; - moreSuggestionsUnableAdded = true; + // Register the More suggestions group; + editor.addMenuItem( 'scayt_moresuggest', + { + label : editor.lang.scayt.moreSuggestions, + group : 'scayt_moresuggest', + order : 10, + getItems : function() + { + return moreSuggestions; + } + }); + mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF; } } - - if ( moreSuggestionsUnableAdded ) - { - // Register the More suggestions group; - editor.addMenuItem( 'scayt_moresuggest', + else { + // "No suggestions" feature + editor.addMenuItem( 'scayt_nosuggest', { - label : lang.moreSuggestions, - group : 'scayt_moresuggest', - order : 10, - getItems : function() - { - return moreSuggestions; - } + label : editor.lang.scayt.noSuggestions ? editor.lang.scayt.noSuggestions : (editor.lang.spellCheck.noSuggestions ? editor.lang.spellCheck.noSuggestions : 'No suggestions'), + group : 'scayt_suggest', + order : 1 }); - mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF; + mainSuggestions[ 'scayt_nosuggest' ] = CKEDITOR.TRISTATE_OFF; } if ( in_array( 'all', contextCommands ) || in_array( 'ignore', contextCommands) ) @@ -804,27 +829,28 @@ CKEDITOR.plugins.scayt = })(); /** - * If enabled (true), turns on SCAYT automatically after loading the editor. + * If enabled (set to true), turns on SCAYT automatically + * after loading the editor. * @name CKEDITOR.config.scayt_autoStartup * @type Boolean - * @default false + * @default false * @example * config.scayt_autoStartup = true; */ /** * Defines the number of SCAYT suggestions to show in the main context menu. - * The possible values are: + * Possible values are: * * @name CKEDITOR.config.scayt_maxSuggestions * @type Number - * @default 5 + * @default 5 * @example * // Display only three suggestions in the main context menu. * config.scayt_maxSuggestions = 3; @@ -834,11 +860,11 @@ CKEDITOR.plugins.scayt = */ /** - * Sets the customer ID for SCAYT. Required for migration from free version - * with banner to paid version. + * Sets the customer ID for SCAYT. Required for migration from free, + * ad-supported version to paid, ad-free version. * @name CKEDITOR.config.scayt_customerid * @type String - * @default '' + * @default '' * @example * // Load SCAYT using my customer ID. * config.scayt_customerid = 'your-encrypted-customer-id'; @@ -846,10 +872,10 @@ CKEDITOR.plugins.scayt = /** * Enables/disables the "More Suggestions" sub-menu in the context menu. - * The possible values are "on" or "off". + * Possible values are on and off. * @name CKEDITOR.config.scayt_moreSuggestions * @type String - * @default 'on' + * @default 'on' * @example * // Disables the "More Suggestions" sub-menu. * config.scayt_moreSuggestions = 'off'; @@ -857,91 +883,99 @@ CKEDITOR.plugins.scayt = /** * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore" - * and "Ignore All"). It must be a string with one or more of the following - * words separated by a pipe ("|"): + * and "Ignore All"). This must be a string with one or more of the following + * words separated by a pipe character ("|"): * * @name CKEDITOR.config.scayt_contextCommands * @type String - * @default 'all' + * @default 'all' * @example * // Show only "Add Word" and "Ignore All" in the context menu. * config.scayt_contextCommands = 'add|ignoreall'; */ /** - * Sets the default spellchecking language for SCAYT. + * Sets the default spell checking language for SCAYT. Possible values are: + * en_US, en_GB, pt_BR, da_DK, + * nl_NL, en_CA, fi_FI, fr_FR, + * fr_CA, de_DE, el_GR, it_IT, + * nb_NO, pt_PT, es_ES, sv_SE. * @name CKEDITOR.config.scayt_sLang * @type String - * @default 'en_US' + * @default 'en_US' * @example * // Sets SCAYT to German. * config.scayt_sLang = 'de_DE'; */ /** - * Sets the visibility of the SCAYT tabs in the settings dialog and toolbar - * button. The value must contain a "1" (enabled) or "0" (disabled) number for - * each of the following entries, in this precise order, separated by a - * comma (","): "Options", "Languages" and "Dictionary". + * Sets the visibility of particular tabs in the SCAYT dialog window and toolbar + * button. This setting must contain a 1 (enabled) or 0 + * (disabled) value for each of the following entries, in this precise order, + * separated by a comma (","): "Options", "Languages", and "Dictionary". * @name CKEDITOR.config.scayt_uiTabs * @type String - * @default '1,1,1' + * @default '1,1,1' * @example - * // Hide the "Languages" tab. + * // Hides the "Languages" tab. * config.scayt_uiTabs = '1,0,1'; */ /** - * Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application. - * Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l . + * Sets the URL to SCAYT core. Required to switch to the licensed version of SCAYT application. + * Further details available at + * + * http://wiki.webspellchecker.net/doku.php?id=migration:hosredfreetolicensedck. * @name CKEDITOR.config.scayt_srcUrl * @type String - * @default '' + * @default '' * @example * config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js"; */ /** - * Links SCAYT to custom dictionaries. It's a string containing dictionary ids - * separared by commas (","). Available only for licensed version. - * Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support . + * Links SCAYT to custom dictionaries. This is a string containing dictionary IDs + * separared by commas (","). Available only for the licensed version. + * Further details at + * + * http://wiki.webspellchecker.net/doku.php?id=installationandconfiguration:customdictionaries:licensed. * @name CKEDITOR.config.scayt_customDictionaryIds * @type String - * @default '' + * @default '' * @example * config.scayt_customDictionaryIds = '3021,3456,3478"'; */ /** - * Makes it possible to activate a custom dictionary on SCAYT. The user - * dictionary name must be used. Available only for licensed version. + * Makes it possible to activate a custom dictionary in SCAYT. The user + * dictionary name must be used. Available only for the licensed version. * @name CKEDITOR.config.scayt_userDictionaryName * @type String - * @default '' + * @default '' * @example * config.scayt_userDictionaryName = 'MyDictionary'; */ /** - * Define order of placing of SCAYT context menu items by groups. - * It must be a string with one or more of the following - * words separated by a pipe ("|"): + * Defines the order SCAYT context menu items by groups. + * This must be a string with one or more of the following + * words separated by a pipe character ("|"): * * * @name CKEDITOR.config.scayt_contextMenuItemsOrder * @type String - * @default 'suggest|moresuggest|control' + * @default 'suggest|moresuggest|control' * @example * config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest'; */