X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fscayt%2Fplugin.js;h=2076207b0136532a64e975c22bd62bf2d44421e8;hp=f64d25e8c994f68a68ce4b7600a30910557b7c03;hb=8665a7c6c60586526e32e8941fe2896739b6ebfb;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1 diff --git a/_source/plugins/scayt/plugin.js b/_source/plugins/scayt/plugin.js index f64d25e..2076207 100644 --- a/_source/plugins/scayt/plugin.js +++ b/_source/plugins/scayt/plugin.js @@ -11,9 +11,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { var commandName = 'scaytcheck', - openPage = '', - scayt_paused = null, - scayt_control_id = null; + openPage = ''; // Checks if a value exists in an array function in_array(needle, haystack) @@ -47,9 +45,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license oParams.userDictionaryName = editor.config.scayt_userDictionaryName || ''; oParams.sLang = editor.config.scayt_sLang || 'en_US'; + // Introduce SCAYT onLoad callback. (#5632) + oParams.onLoad = function() + { + // Draw down word marker to avoid being covered by background-color style.(#5466) + if ( !( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) ) + this.addStyle( this.selectorCss(), 'padding-bottom: 2px !important;' ); + + // Call scayt_control.focus when SCAYT loaded + // and only if editor has focus and scayt control creates at first time (#5720) + if ( editor.focusManager.hasFocus && !plugin.isControlRestored( editor ) ) + this.focus(); + + }; + oParams.onBeforeChange = function() { - if ( !editor.checkDirty() ) + if ( plugin.getScayt( editor ) && !editor.checkDirty() ) setTimeout( function(){ editor.resetDirty(); } ); }; @@ -62,11 +74,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } // needs for restoring a specific scayt control settings - if ( scayt_control_id ) - oParams.id = scayt_control_id; + if ( plugin.getControlId(editor) ) + 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(); + } ); + // Copy config. var lastInstance = plugin.instances[ editor.name ]; if ( lastInstance ) @@ -88,7 +105,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license plugin.uiTabs = fTabs; try { - scayt_control.setDisabled( scayt_paused === false ); + scayt_control.setDisabled( plugin.isPaused( editor ) === false ); } catch (e) {} editor.fire( 'showScaytState' ); @@ -120,30 +137,51 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var scayt_instance = plugin.getScayt( editor ); if ( scayt_instance ) { - scayt_paused = scayt_instance.paused = !scayt_instance.disabled; + plugin.setPaused( editor, !scayt_instance.disabled ); // store a control id for restore a specific scayt control settings - scayt_control_id = scayt_instance.id; + 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' ) + plugin.markControlRestore( editor ); + }); + + editor.on( 'afterCommandExec', function( ev ) + { + if ( !plugin.isScaytEnabled( editor ) ) + return; + + 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, scayt_instance = plugin.getScayt( editor ); + + // SCAYT instance might already get destroyed by mode switch (#5744). + if ( !scayt_instance ) + return; + + delete plugin.instances[ editor.name ]; // store a control id for restore a specific scayt control settings - scayt_control_id = scayt_instance.id; + plugin.setControlId( editor, scayt_instance.id ); scayt_instance.destroy( true ); - delete plugin.instances[ editor.name ]; }); // Listen to data manipulation to reflect scayt markup. editor.on( 'afterSetData', function() { if ( plugin.isScaytEnabled( editor ) ) { - window.setTimeout( function(){ plugin.getScayt( editor ).refresh(); }, 10 ); + window.setTimeout( function() + { + var instance = plugin.getScayt( editor ); + instance && instance.refresh(); + }, 10 ); } }); @@ -158,8 +196,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( CKEDITOR.env.ie ) editor.getSelection().unlock( true ); - // Swallow any SCAYT engine errors. - window.setTimeout( function(){ scayt_instance.refresh(); }, 10 ); + // Return focus to the editor and refresh SCAYT markup (#5573). + window.setTimeout( function() + { + scayt_instance.focus(); + scayt_instance.refresh(); + }, 10 ); } }, this, null, 50 ); @@ -173,8 +215,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( CKEDITOR.env.ie ) editor.getSelection().unlock( true ); - // Swallow any SCAYT engine errors. - window.setTimeout( function(){ scayt_instance.refresh(); },10 ); + // Return focus to the editor (#5573) + // Refresh SCAYT markup + window.setTimeout( function() + { + scayt_instance.focus(); + scayt_instance.refresh(); + }, 10 ); } }, this, null, 50 ); @@ -208,14 +255,92 @@ For licensing, see LICENSE.html or http://ckeditor.com/license ); } + // Override Image.equals method avoid CK snapshot module to add SCAYT markup to snapshots. (#5546) + var undoImagePrototype = CKEDITOR.plugins.undo.Image.prototype; + undoImagePrototype.equals = CKEDITOR.tools.override( undoImagePrototype.equals, function( org ) + { + return function( otherImage ) + { + var thisContents = this.contents, + otherContents = otherImage.contents; + var scayt_instance = plugin.getScayt( this.editor ); + // Making the comparison based on content without SCAYT word markers. + if ( scayt_instance && plugin.isScaytReady( this.editor ) ) + { + // scayt::reset might return value undefined. (#5742) + this.contents = scayt_instance.reset( thisContents ) || ''; + otherImage.contents = scayt_instance.reset( otherContents ) || ''; + } + + var retval = org.apply( this, arguments ); + + this.contents = thisContents; + otherImage.contents = otherContents; + return retval; + }; + }); + if ( editor.document ) createInstance(); }; - CKEDITOR.plugins.scayt = +CKEDITOR.plugins.scayt = { engineLoaded : false, instances : {}, + // Data storage for SCAYT control, based on editor instances + controlInfo : {}, + setControlInfo : function( editor, o ) + { + if ( editor && editor.name && typeof ( this.controlInfo[ editor.name ] ) != 'object' ) + this.controlInfo[ editor.name ] = {}; + + for ( var infoOpt in o ) + this.controlInfo[ editor.name ][ infoOpt ] = o[ infoOpt ]; + }, + isControlRestored : function ( editor ) + { + if ( editor && + editor.name && + this.controlInfo[ editor.name ] ) + { + return this.controlInfo[ editor.name ].restored ; + } + return false; + }, + markControlRestore : function ( editor ) + { + this.setControlInfo( editor,{ restored:true } ); + }, + setControlId: function (editor, id) + { + this.setControlInfo( editor,{ id:id } ); + }, + getControlId: function (editor) + { + if ( editor && + editor.name && + this.controlInfo[ editor.name ] && + this.controlInfo[ editor.name ].id ) + { + return this.controlInfo[ editor.name ].id; + } + return null; + }, + setPaused: function ( editor , bool ) + { + this.setControlInfo( editor,{ paused:bool } ); + }, + isPaused: function (editor) + { + if ( editor && + editor.name && + this.controlInfo[editor.name] ) + { + return this.controlInfo[editor.name].paused ; + } + return undefined; + }, getScayt : function( editor ) { return this.instances[ editor.name ]; @@ -234,7 +359,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { // SCAYT doesn't work with Opera. if ( CKEDITOR.env.opera ) - return null; + return editor.fire( 'showScaytState' ); if ( this.engineLoaded === true ) return onEngineLoad.apply( editor ); // Add new instance. @@ -257,34 +382,39 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var protocol = document.location.protocol; // Default to 'http' for unknown. protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; - var baseUrl = 'svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js'; + var baseUrl = 'svc.spellchecker.net/spellcheck31/lf/scayt24/loader__base.js'; var scaytUrl = editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl ); var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + '/'; - CKEDITOR._djScaytConfig = + if( window.scayt == undefined ) { - baseUrl: scaytConfigBaseUrl, - addOnLoad: - [ - function() - { - CKEDITOR.fireOnce( 'scaytReady' ); - } - ], - isDebug: false - }; - // Append javascript code. - CKEDITOR.document.getHead().append( - CKEDITOR.document.createElement( 'script', - { - attributes : - { - type : 'text/javascript', - src : scaytUrl - } - }) - ); + CKEDITOR._djScaytConfig = + { + baseUrl: scaytConfigBaseUrl, + addOnLoad: + [ + function() + { + CKEDITOR.fireOnce( 'scaytReady' ); + } + ], + isDebug: false + }; + // Append javascript code. + CKEDITOR.document.getHead().append( + CKEDITOR.document.createElement( 'script', + { + attributes : + { + type : 'text/javascript', + src : scaytUrl + } + }) + ); + } + else + CKEDITOR.fireOnce( 'scaytReady' ); return null; }, @@ -322,6 +452,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license exec: function( editor ) { + var autoStartup = editor.config.scayt_autoStartup; + autoStartup = ( autoStartup == undefined ) || autoStartup; + if ( plugin.isScaytReady( editor ) ) { var isEnabled = plugin.isScaytEnabled( editor ); @@ -329,19 +462,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON ); var scayt_control = plugin.getScayt( editor ); + // the place where the status of editor focus should be restored + // after there will be ability to store its state before SCAYT button click + // if (storedFocusState is focused ) + // scayt_control.focus(); + // + // now focus is set certainly + scayt_control.focus( ); scayt_control.setDisabled( isEnabled ); } - else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time + else if ( !autoStartup && plugin.engineLoaded >= 0 ) // Load first time { this.setState( CKEDITOR.TRISTATE_DISABLED ); - - editor.on( 'showScaytState', function() - { - this.removeListener(); - this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); - }, - this); - plugin.loadEngine( editor ); } } @@ -354,8 +486,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license beforeInit : function( editor ) { - // Register own rbc menu group. - editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups; + var items_order = editor.config.scayt_contextMenuItemsOrder + || 'suggest|moresuggest|control', + items_order_str = ""; + + items_order = items_order.split( '|' ); + + if ( items_order && items_order.length ) + { + for ( var pos in items_order ) + items_order_str += 'scayt_' + items_order[ pos ] + ( items_order.length != parseInt( pos, 10 ) + 1 ? ',' : '' ); + } + + // Register scayt rbc menu group. + if ( editor.config.scayt_contextMenuOntop ) + // Put it on top of all context menu items + editor.config.menu_groups = items_order_str + ',' + editor.config.menu_groups; + else + // Put it down + editor.config.menu_groups = editor.config.menu_groups + ',' +items_order_str; }, init : function( editor ) @@ -448,7 +597,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON, { label : editor.lang.scayt.title, - title : editor.lang.scayt.title, + title : CKEDITOR.env.opera ? editor.lang.scayt.opera_title : editor.lang.scayt.title, className : 'cke_button_scayt', onRender: function() { @@ -607,15 +756,30 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }); } - // Start plugin - if ( editor.config.scayt_autoStartup ) - { - var showInitialState = function() + var showInitialState = function() { editor.removeListener( 'showScaytState', showInitialState ); - command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); + + if ( !CKEDITOR.env.opera ) + command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); + else + command.setState( CKEDITOR.TRISTATE_DISABLED ); }; - editor.on( 'showScaytState', showInitialState ); + + editor.on( 'showScaytState', showInitialState ); + + if ( CKEDITOR.env.opera ) + { + editor.on( 'instanceReady', function() + { + showInitialState(); + }); + } + + // Start plugin + var autoStartup = editor.config.scayt_autoStartup; + if ( ( autoStartup == undefined ) || autoStartup ) + { editor.on( 'instanceReady', function() { plugin.loadEngine( editor ); @@ -625,16 +789,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license afterInit : function( editor ) { - // Prevent word marker line from displaying in elements path. (#3570) - var elementsPathFilters; + // Prevent word marker line from displaying in elements path and been removed when cleaning format. (#3570) (#4125) + var elementsPathFilters, + scaytFilter = function( element ) + { + if ( element.hasAttribute( 'scaytid' ) ) + return false; + }; + if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) ) - { - elementsPathFilters.push( function( element ) - { - if ( element.hasAttribute( 'scaytid' ) ) - return false; - } ); - } + elementsPathFilters.push( scaytFilter ); + + editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter ); } }); @@ -644,9 +810,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * If enabled (true), turns on SCAYT automatically after loading the editor. * @name CKEDITOR.config.scayt_autoStartup * @type Boolean - * @default false + * @default true * @example - * config.scayt_autoStartup = true; + * config.scayt_autoStartup = false; */ /** @@ -765,3 +931,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @example * config.scayt_userDictionaryName = 'MyDictionary'; */ + +/** + * Makes it possible to place the SCAYT context menu items above others. + * @name CKEDITOR.config.scayt_contextMenuOntop + * @type Boolean + * @default false + * @example + * config.scayt_contextMenuOntop = true; + */ + +/** + * 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 ("|"): + * + * + * @name CKEDITOR.config.scayt_contextMenuItemsOrder + * @type String + * @default 'suggest|moresuggest|control' + * @example + * config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest'; + */