X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fplugins%2Fscayt%2Fplugin.js;h=ec64fed77b1e69180603086996e12696b4d50c14;hb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7;hp=f64d25e8c994f68a68ce4b7600a30910557b7c03;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/scayt/plugin.js b/_source/plugins/scayt/plugin.js index f64d25e..ec64fed 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,10 +45,24 @@ 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() ) - setTimeout( function(){ editor.resetDirty(); } ); + if ( plugin.getScayt( editor ) && !editor.checkDirty() ) + setTimeout( function(){ editor.resetDirty(); }, 0 ); }; var scayt_custom_params = window.scayt_custom_params; @@ -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 ]; @@ -232,9 +357,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, loadEngine : function( editor ) { - // SCAYT doesn't work with Opera. - if ( CKEDITOR.env.opera ) - return null; + // SCAYT doesn't work with Firefox2, Opera. + if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera ) + return editor.fire( 'showScaytState' ); if ( this.engineLoaded === true ) return onEngineLoad.apply( editor ); // Add new instance. @@ -257,34 +382,40 @@ 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/scayt25/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', + async : 'true', + src : scaytUrl + } + }) + ); + } + else + CKEDITOR.fireOnce( 'scaytReady' ); return null; }, @@ -329,19 +460,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 { 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 +484,20 @@ 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 ? ',' : '' ); + } + + // Put it on top of all context menu items (#5717) + editor.config.menu_groups = items_order_str + ',' + editor.config.menu_groups; }, init : function( editor ) @@ -448,7 +590,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() { @@ -477,9 +619,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // If the "contextmenu" plugin is loaded, register the listeners. if ( editor.contextMenu && editor.addMenuItems ) { - editor.contextMenu.addListener( function( ) + editor.contextMenu.addListener( function( element, selection ) { - if ( !plugin.isScaytEnabled( editor ) ) + if ( !plugin.isScaytEnabled( editor ) + || selection.getCommonAncestor().isReadOnly() ) return null; var scayt_control = plugin.getScayt( editor ), @@ -607,15 +750,29 @@ 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 + if ( editor.config.scayt_autoStartup ) + { editor.on( 'instanceReady', function() { plugin.loadEngine( editor ); @@ -625,16 +782,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 ); } }); @@ -765,3 +924,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @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 ("|"): + * + * + * @name CKEDITOR.config.scayt_contextMenuItemsOrder + * @type String + * @default 'suggest|moresuggest|control' + * @example + * config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest'; + */