[2862] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * @fileOverview Spell Check As You Type (SCAYT).
|
---|
| 8 | * Button name : Scayt.
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | (function()
|
---|
| 12 | {
|
---|
| 13 | var commandName = 'scaytcheck',
|
---|
| 14 | openPage = '',
|
---|
| 15 | scayt_paused = null,
|
---|
| 16 | scayt_control_id = null;
|
---|
| 17 |
|
---|
| 18 | // Checks if a value exists in an array
|
---|
| 19 | function in_array(needle, haystack)
|
---|
| 20 | {
|
---|
| 21 | var found = false, key;
|
---|
| 22 | for (key in haystack)
|
---|
| 23 | {
|
---|
| 24 | if ((haystack[key] === needle) || ( haystack[key] == needle))
|
---|
| 25 | {
|
---|
| 26 | found = true;
|
---|
| 27 | break;
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | return found;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | var onEngineLoad = function()
|
---|
| 34 | {
|
---|
| 35 | var editor = this;
|
---|
| 36 |
|
---|
| 37 | var createInstance = function() // Create new instance every time Document is created.
|
---|
| 38 | {
|
---|
| 39 | // Initialise Scayt instance.
|
---|
| 40 | var oParams = {};
|
---|
| 41 | // Get the iframe.
|
---|
| 42 | oParams.srcNodeRef = editor.document.getWindow().$.frameElement;
|
---|
| 43 | // syntax : AppName.AppVersion@AppRevision
|
---|
| 44 | oParams.assocApp = 'CKEDITOR.' + CKEDITOR.version + '@' + CKEDITOR.revision;
|
---|
| 45 | oParams.customerid = editor.config.scayt_customerid || '1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';
|
---|
| 46 | oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds || '';
|
---|
| 47 | oParams.userDictionaryName = editor.config.scayt_userDictionaryName || '';
|
---|
| 48 | oParams.sLang = editor.config.scayt_sLang || 'en_US';
|
---|
| 49 |
|
---|
| 50 | oParams.onBeforeChange = function()
|
---|
| 51 | {
|
---|
| 52 | if ( !editor.checkDirty() )
|
---|
| 53 | setTimeout( function(){ editor.resetDirty(); } );
|
---|
| 54 | };
|
---|
| 55 |
|
---|
| 56 | var scayt_custom_params = window.scayt_custom_params;
|
---|
| 57 | if ( typeof scayt_custom_params == 'object')
|
---|
| 58 | {
|
---|
| 59 | for ( var k in scayt_custom_params )
|
---|
| 60 | if ( ! ( k in Object.prototype ) )
|
---|
| 61 | {
|
---|
| 62 | oParams[ k ] = scayt_custom_params[ k ];
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | // needs for restoring a specific scayt control settings
|
---|
| 66 | if ( scayt_control_id )
|
---|
| 67 | oParams.id = scayt_control_id;
|
---|
| 68 |
|
---|
| 69 | var scayt_control = new window.scayt( oParams );
|
---|
| 70 |
|
---|
| 71 | // Copy config.
|
---|
| 72 | var lastInstance = plugin.instances[ editor.name ];
|
---|
| 73 | if ( lastInstance )
|
---|
| 74 | {
|
---|
| 75 | scayt_control.sLang = lastInstance.sLang;
|
---|
| 76 | scayt_control.option( lastInstance.option() );
|
---|
| 77 | scayt_control.paused = lastInstance.paused;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | plugin.instances[ editor.name ] = scayt_control;
|
---|
| 81 |
|
---|
| 82 | //window.scayt.uiTags
|
---|
| 83 | var menuGroup = 'scaytButton';
|
---|
| 84 | var uiTabs = window.scayt.uiTags;
|
---|
| 85 | var fTabs = [];
|
---|
| 86 |
|
---|
| 87 | for (var i = 0,l=4; i<l; i++)
|
---|
| 88 | fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
|
---|
| 89 |
|
---|
| 90 | plugin.uiTabs = fTabs;
|
---|
| 91 | try {
|
---|
| 92 | scayt_control.setDisabled( scayt_paused === false );
|
---|
| 93 | } catch (e) {}
|
---|
| 94 |
|
---|
| 95 | editor.fire( 'showScaytState' );
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 | editor.on( 'contentDom', createInstance );
|
---|
| 99 | editor.on( 'contentDomUnload', function()
|
---|
| 100 | {
|
---|
| 101 | // Remove scripts.
|
---|
| 102 | var scripts = CKEDITOR.document.getElementsByTag( 'script' ),
|
---|
| 103 | scaytIdRegex = /^dojoIoScript(\d+)$/i,
|
---|
| 104 | scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;
|
---|
| 105 |
|
---|
| 106 | for ( var i=0; i < scripts.count(); i++ )
|
---|
| 107 | {
|
---|
| 108 | var script = scripts.getItem( i ),
|
---|
| 109 | id = script.getId(),
|
---|
| 110 | src = script.getAttribute( 'src' );
|
---|
| 111 |
|
---|
| 112 | if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))
|
---|
| 113 | script.remove();
|
---|
| 114 | }
|
---|
| 115 | });
|
---|
| 116 |
|
---|
| 117 | editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution.
|
---|
| 118 | {
|
---|
| 119 | if ( (ev.data.name == 'source' || ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )
|
---|
| 120 | {
|
---|
| 121 | var scayt_instance = plugin.getScayt( editor );
|
---|
| 122 | if ( scayt_instance )
|
---|
| 123 | {
|
---|
| 124 | scayt_paused = scayt_instance.paused = !scayt_instance.disabled;
|
---|
| 125 | // store a control id for restore a specific scayt control settings
|
---|
| 126 | scayt_control_id = scayt_instance.id;
|
---|
| 127 | scayt_instance.destroy( true );
|
---|
| 128 | delete plugin.instances[ editor.name ];
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | });
|
---|
| 132 |
|
---|
| 133 | editor.on( 'destroy', function( ev )
|
---|
| 134 | {
|
---|
| 135 | var editor = ev.editor,
|
---|
| 136 | scayt_instance = plugin.getScayt( editor );
|
---|
| 137 | // store a control id for restore a specific scayt control settings
|
---|
| 138 | scayt_control_id = scayt_instance.id;
|
---|
| 139 | scayt_instance.destroy( true );
|
---|
| 140 | delete plugin.instances[ editor.name ];
|
---|
| 141 | });
|
---|
| 142 |
|
---|
| 143 | // Listen to data manipulation to reflect scayt markup.
|
---|
| 144 | editor.on( 'afterSetData', function()
|
---|
| 145 | {
|
---|
| 146 | if ( plugin.isScaytEnabled( editor ) ) {
|
---|
| 147 | window.setTimeout( function(){ plugin.getScayt( editor ).refresh(); }, 10 );
|
---|
| 148 | }
|
---|
| 149 | });
|
---|
| 150 |
|
---|
| 151 | // Reload spell-checking for current word after insertion completed.
|
---|
| 152 | editor.on( 'insertElement', function()
|
---|
| 153 | {
|
---|
| 154 | var scayt_instance = plugin.getScayt( editor );
|
---|
| 155 | if ( plugin.isScaytEnabled( editor ) )
|
---|
| 156 | {
|
---|
| 157 | // Unlock the selection before reload, SCAYT will take
|
---|
| 158 | // care selection update.
|
---|
| 159 | if ( CKEDITOR.env.ie )
|
---|
| 160 | editor.getSelection().unlock( true );
|
---|
| 161 |
|
---|
| 162 | // Swallow any SCAYT engine errors.
|
---|
| 163 | window.setTimeout( function(){ scayt_instance.refresh(); }, 10 );
|
---|
| 164 | }
|
---|
| 165 | }, this, null, 50 );
|
---|
| 166 |
|
---|
| 167 | editor.on( 'insertHtml', function()
|
---|
| 168 | {
|
---|
| 169 | var scayt_instance = plugin.getScayt( editor );
|
---|
| 170 | if ( plugin.isScaytEnabled( editor ) )
|
---|
| 171 | {
|
---|
| 172 | // Unlock the selection before reload, SCAYT will take
|
---|
| 173 | // care selection update.
|
---|
| 174 | if ( CKEDITOR.env.ie )
|
---|
| 175 | editor.getSelection().unlock( true );
|
---|
| 176 |
|
---|
| 177 | // Swallow any SCAYT engine errors.
|
---|
| 178 | window.setTimeout( function(){ scayt_instance.refresh(); },10 );
|
---|
| 179 | }
|
---|
| 180 | }, this, null, 50 );
|
---|
| 181 |
|
---|
| 182 | editor.on( 'scaytDialog', function( ev ) // Communication with dialog.
|
---|
| 183 | {
|
---|
| 184 | ev.data.djConfig = window.djConfig;
|
---|
| 185 | ev.data.scayt_control = plugin.getScayt( editor );
|
---|
| 186 | ev.data.tab = openPage;
|
---|
| 187 | ev.data.scayt = window.scayt;
|
---|
| 188 | });
|
---|
| 189 |
|
---|
| 190 | var dataProcessor = editor.dataProcessor,
|
---|
| 191 | htmlFilter = dataProcessor && dataProcessor.htmlFilter;
|
---|
| 192 |
|
---|
| 193 | if ( htmlFilter )
|
---|
| 194 | {
|
---|
| 195 | htmlFilter.addRules(
|
---|
| 196 | {
|
---|
| 197 | elements :
|
---|
| 198 | {
|
---|
| 199 | span : function( element )
|
---|
| 200 | {
|
---|
| 201 | if ( element.attributes.scayt_word && element.attributes.scaytid )
|
---|
| 202 | {
|
---|
| 203 | delete element.name; // Write children, but don't write this node.
|
---|
| 204 | return element;
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | );
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | if ( editor.document )
|
---|
| 213 | createInstance();
|
---|
| 214 | };
|
---|
| 215 |
|
---|
| 216 | CKEDITOR.plugins.scayt =
|
---|
| 217 | {
|
---|
| 218 | engineLoaded : false,
|
---|
| 219 | instances : {},
|
---|
| 220 | getScayt : function( editor )
|
---|
| 221 | {
|
---|
| 222 | return this.instances[ editor.name ];
|
---|
| 223 | },
|
---|
| 224 | isScaytReady : function( editor )
|
---|
| 225 | {
|
---|
| 226 | return this.engineLoaded === true &&
|
---|
| 227 | 'undefined' !== typeof window.scayt && this.getScayt( editor );
|
---|
| 228 | },
|
---|
| 229 | isScaytEnabled : function( editor )
|
---|
| 230 | {
|
---|
| 231 | var scayt_instance = this.getScayt( editor );
|
---|
| 232 | return ( scayt_instance ) ? scayt_instance.disabled === false : false;
|
---|
| 233 | },
|
---|
| 234 | loadEngine : function( editor )
|
---|
| 235 | {
|
---|
| 236 | // SCAYT doesn't work with Opera.
|
---|
| 237 | if ( CKEDITOR.env.opera )
|
---|
| 238 | return null;
|
---|
| 239 |
|
---|
| 240 | if ( this.engineLoaded === true )
|
---|
| 241 | return onEngineLoad.apply( editor ); // Add new instance.
|
---|
| 242 | else if ( this.engineLoaded == -1 ) // We are waiting.
|
---|
| 243 | return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor ); } ); // Use function(){} to avoid rejection as duplicate.
|
---|
| 244 |
|
---|
| 245 | CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
|
---|
| 246 | CKEDITOR.on( 'scaytReady', function()
|
---|
| 247 | {
|
---|
| 248 | this.engineLoaded = true;
|
---|
| 249 | },
|
---|
| 250 | this,
|
---|
| 251 | null,
|
---|
| 252 | 0
|
---|
| 253 | ); // First to run.
|
---|
| 254 |
|
---|
| 255 | this.engineLoaded = -1; // Loading in progress.
|
---|
| 256 |
|
---|
| 257 | // compose scayt url
|
---|
| 258 | var protocol = document.location.protocol;
|
---|
| 259 | // Default to 'http' for unknown.
|
---|
| 260 | protocol = protocol.search( /https?:/) != -1? protocol : 'http:';
|
---|
| 261 | var baseUrl = 'svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js';
|
---|
| 262 |
|
---|
| 263 | var scaytUrl = editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl );
|
---|
| 264 | var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + '/';
|
---|
| 265 |
|
---|
| 266 | CKEDITOR._djScaytConfig =
|
---|
| 267 | {
|
---|
| 268 | baseUrl: scaytConfigBaseUrl,
|
---|
| 269 | addOnLoad:
|
---|
| 270 | [
|
---|
| 271 | function()
|
---|
| 272 | {
|
---|
| 273 | CKEDITOR.fireOnce( 'scaytReady' );
|
---|
| 274 | }
|
---|
| 275 | ],
|
---|
| 276 | isDebug: false
|
---|
| 277 | };
|
---|
| 278 | // Append javascript code.
|
---|
| 279 | CKEDITOR.document.getHead().append(
|
---|
| 280 | CKEDITOR.document.createElement( 'script',
|
---|
| 281 | {
|
---|
| 282 | attributes :
|
---|
| 283 | {
|
---|
| 284 | type : 'text/javascript',
|
---|
| 285 | src : scaytUrl
|
---|
| 286 | }
|
---|
| 287 | })
|
---|
| 288 | );
|
---|
| 289 |
|
---|
| 290 | return null;
|
---|
| 291 | },
|
---|
| 292 | parseUrl : function ( data )
|
---|
| 293 | {
|
---|
| 294 | var match;
|
---|
| 295 | if ( data.match && ( match = data.match(/(.*)[\/\\](.*?\.\w+)$/) ) )
|
---|
| 296 | return { path: match[1], file: match[2] };
|
---|
| 297 | else
|
---|
| 298 | return data;
|
---|
| 299 | }
|
---|
| 300 | };
|
---|
| 301 |
|
---|
| 302 | var plugin = CKEDITOR.plugins.scayt;
|
---|
| 303 |
|
---|
| 304 | // Context menu constructing.
|
---|
| 305 | var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder )
|
---|
| 306 | {
|
---|
| 307 | editor.addCommand( commandName, command );
|
---|
| 308 |
|
---|
| 309 | // If the "menu" plugin is loaded, register the menu item.
|
---|
| 310 | editor.addMenuItem( commandName,
|
---|
| 311 | {
|
---|
| 312 | label : buttonLabel,
|
---|
| 313 | command : commandName,
|
---|
| 314 | group : menugroup,
|
---|
| 315 | order : menuOrder
|
---|
| 316 | });
|
---|
| 317 | };
|
---|
| 318 |
|
---|
| 319 | var commandDefinition =
|
---|
| 320 | {
|
---|
| 321 | preserveState : true,
|
---|
| 322 | editorFocus : false,
|
---|
| 323 |
|
---|
| 324 | exec: function( editor )
|
---|
| 325 | {
|
---|
| 326 | if ( plugin.isScaytReady( editor ) )
|
---|
| 327 | {
|
---|
| 328 | var isEnabled = plugin.isScaytEnabled( editor );
|
---|
| 329 |
|
---|
| 330 | this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );
|
---|
| 331 |
|
---|
| 332 | var scayt_control = plugin.getScayt( editor );
|
---|
| 333 | scayt_control.setDisabled( isEnabled );
|
---|
| 334 | }
|
---|
| 335 | else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time
|
---|
| 336 | {
|
---|
| 337 | this.setState( CKEDITOR.TRISTATE_DISABLED );
|
---|
| 338 |
|
---|
| 339 | editor.on( 'showScaytState', function()
|
---|
| 340 | {
|
---|
| 341 | this.removeListener();
|
---|
| 342 | this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
|
---|
| 343 | },
|
---|
| 344 | this);
|
---|
| 345 |
|
---|
| 346 | plugin.loadEngine( editor );
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 | };
|
---|
| 350 |
|
---|
| 351 | // Add scayt plugin.
|
---|
| 352 | CKEDITOR.plugins.add( 'scayt',
|
---|
| 353 | {
|
---|
| 354 | requires : [ 'menubutton' ],
|
---|
| 355 |
|
---|
| 356 | beforeInit : function( editor )
|
---|
| 357 | {
|
---|
| 358 | // Register own rbc menu group.
|
---|
| 359 | editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups;
|
---|
| 360 | },
|
---|
| 361 |
|
---|
| 362 | init : function( editor )
|
---|
| 363 | {
|
---|
| 364 | var moreSuggestions = {};
|
---|
| 365 | var mainSuggestions = {};
|
---|
| 366 |
|
---|
| 367 | // Scayt command.
|
---|
| 368 | var command = editor.addCommand( commandName, commandDefinition );
|
---|
| 369 |
|
---|
| 370 | // Add Options dialog.
|
---|
| 371 | CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
|
---|
| 372 | // read ui tags
|
---|
| 373 | var confuiTabs = editor.config.scayt_uiTabs || '1,1,1';
|
---|
| 374 | var uiTabs =[];
|
---|
| 375 | // string to array convert
|
---|
| 376 | confuiTabs = confuiTabs.split( ',' );
|
---|
| 377 | // check array length ! always must be 3 filled with 1 or 0
|
---|
| 378 | for (var i=0,l=3; i<l; i++)
|
---|
| 379 | {
|
---|
| 380 | var flag = parseInt(confuiTabs[i] || '1' ,10);
|
---|
| 381 | uiTabs.push( flag );
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | var menuGroup = 'scaytButton';
|
---|
| 385 | editor.addMenuGroup( menuGroup );
|
---|
| 386 | // combine menu items to render
|
---|
| 387 | var uiMuneItems = {};
|
---|
| 388 |
|
---|
| 389 | // always added
|
---|
| 390 | uiMuneItems.scaytToggle =
|
---|
| 391 | {
|
---|
| 392 | label : editor.lang.scayt.enable,
|
---|
| 393 | command : commandName,
|
---|
| 394 | group : menuGroup
|
---|
| 395 | };
|
---|
| 396 |
|
---|
| 397 | if (uiTabs[0] == 1)
|
---|
| 398 | uiMuneItems.scaytOptions =
|
---|
| 399 | {
|
---|
| 400 | label : editor.lang.scayt.options,
|
---|
| 401 | group : menuGroup,
|
---|
| 402 | onClick : function()
|
---|
| 403 | {
|
---|
| 404 | openPage = 'options';
|
---|
| 405 | editor.openDialog( commandName );
|
---|
| 406 | }
|
---|
| 407 | };
|
---|
| 408 |
|
---|
| 409 | if (uiTabs[1] == 1)
|
---|
| 410 | uiMuneItems.scaytLangs =
|
---|
| 411 | {
|
---|
| 412 | label : editor.lang.scayt.langs,
|
---|
| 413 | group : menuGroup,
|
---|
| 414 | onClick : function()
|
---|
| 415 | {
|
---|
| 416 | openPage = 'langs';
|
---|
| 417 | editor.openDialog( commandName );
|
---|
| 418 | }
|
---|
| 419 | };
|
---|
| 420 | if (uiTabs[2] == 1)
|
---|
| 421 | uiMuneItems.scaytDict =
|
---|
| 422 | {
|
---|
| 423 | label : editor.lang.scayt.dictionariesTab,
|
---|
| 424 | group : menuGroup,
|
---|
| 425 | onClick : function()
|
---|
| 426 | {
|
---|
| 427 | openPage = 'dictionaries';
|
---|
| 428 | editor.openDialog( commandName );
|
---|
| 429 | }
|
---|
| 430 | };
|
---|
| 431 | // always added
|
---|
| 432 | uiMuneItems.scaytAbout =
|
---|
| 433 | {
|
---|
| 434 | label : editor.lang.scayt.about,
|
---|
| 435 | group : menuGroup,
|
---|
| 436 | onClick : function()
|
---|
| 437 | {
|
---|
| 438 | openPage = 'about';
|
---|
| 439 | editor.openDialog( commandName );
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 | ;
|
---|
| 443 |
|
---|
| 444 | uiTabs[3] = 1; // about us tab is always on
|
---|
| 445 | plugin.uiTabs = uiTabs;
|
---|
| 446 |
|
---|
| 447 | editor.addMenuItems( uiMuneItems );
|
---|
| 448 |
|
---|
| 449 | editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
|
---|
| 450 | {
|
---|
| 451 | label : editor.lang.scayt.title,
|
---|
| 452 | title : editor.lang.scayt.title,
|
---|
| 453 | className : 'cke_button_scayt',
|
---|
| 454 | onRender: function()
|
---|
| 455 | {
|
---|
| 456 | command.on( 'state', function()
|
---|
| 457 | {
|
---|
| 458 | this.setState( command.state );
|
---|
| 459 | },
|
---|
| 460 | this);
|
---|
| 461 | },
|
---|
| 462 | onMenu : function()
|
---|
| 463 | {
|
---|
| 464 | var isEnabled = plugin.isScaytEnabled( editor );
|
---|
| 465 |
|
---|
| 466 | editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ];
|
---|
| 467 |
|
---|
| 468 | return {
|
---|
| 469 | scaytToggle : CKEDITOR.TRISTATE_OFF,
|
---|
| 470 | scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
|
---|
| 471 | scaytLangs : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
|
---|
| 472 | scaytDict : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
|
---|
| 473 | scaytAbout : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
|
---|
| 474 | };
|
---|
| 475 | }
|
---|
| 476 | });
|
---|
| 477 |
|
---|
| 478 | // If the "contextmenu" plugin is loaded, register the listeners.
|
---|
| 479 | if ( editor.contextMenu && editor.addMenuItems )
|
---|
| 480 | {
|
---|
| 481 | editor.contextMenu.addListener( function( )
|
---|
| 482 | {
|
---|
| 483 | if ( !plugin.isScaytEnabled( editor ) )
|
---|
| 484 | return null;
|
---|
| 485 |
|
---|
| 486 | var scayt_control = plugin.getScayt( editor ),
|
---|
| 487 | node = scayt_control.getScaytNode();
|
---|
| 488 |
|
---|
| 489 | if ( !node )
|
---|
| 490 | return null;
|
---|
| 491 |
|
---|
| 492 | var word = scayt_control.getWord( node );
|
---|
| 493 |
|
---|
| 494 | if ( !word )
|
---|
| 495 | return null;
|
---|
| 496 |
|
---|
| 497 | var sLang = scayt_control.getLang(),
|
---|
| 498 | _r = {},
|
---|
| 499 | items_suggestion = window.scayt.getSuggestion( word, sLang );
|
---|
| 500 | if ( !items_suggestion || !items_suggestion.length )
|
---|
| 501 | return null;
|
---|
| 502 | // Remove unused commands and menuitems
|
---|
| 503 | for ( i in moreSuggestions )
|
---|
| 504 | {
|
---|
| 505 | delete editor._.menuItems[ i ];
|
---|
| 506 | delete editor._.commands[ i ];
|
---|
| 507 | }
|
---|
| 508 | for ( i in mainSuggestions )
|
---|
| 509 | {
|
---|
| 510 | delete editor._.menuItems[ i ];
|
---|
| 511 | delete editor._.commands[ i ];
|
---|
| 512 | }
|
---|
| 513 | moreSuggestions = {}; // Reset items.
|
---|
| 514 | mainSuggestions = {};
|
---|
| 515 |
|
---|
| 516 | var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || 'on';
|
---|
| 517 | var moreSuggestionsUnableAdded = false;
|
---|
| 518 |
|
---|
| 519 | var maxSuggestions = editor.config.scayt_maxSuggestions;
|
---|
| 520 | ( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 );
|
---|
| 521 | !maxSuggestions && ( maxSuggestions = items_suggestion.length );
|
---|
| 522 |
|
---|
| 523 | var contextCommands = editor.config.scayt_contextCommands || 'all';
|
---|
| 524 | contextCommands = contextCommands.split( '|' );
|
---|
| 525 |
|
---|
| 526 | for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
|
---|
| 527 | {
|
---|
| 528 | var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );
|
---|
| 529 | var exec = ( function( el, s )
|
---|
| 530 | {
|
---|
| 531 | return {
|
---|
| 532 | exec: function()
|
---|
| 533 | {
|
---|
| 534 | scayt_control.replace(el, s);
|
---|
| 535 | }
|
---|
| 536 | };
|
---|
| 537 | })( node, items_suggestion[i] );
|
---|
| 538 |
|
---|
| 539 | if ( i < maxSuggestions )
|
---|
| 540 | {
|
---|
| 541 | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
|
---|
| 542 | commandName, exec, 'scayt_suggest', i + 1 );
|
---|
| 543 | _r[ commandName ] = CKEDITOR.TRISTATE_OFF;
|
---|
| 544 | mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
|
---|
| 545 | }
|
---|
| 546 | else if ( moreSuggestionsUnable == 'on' )
|
---|
| 547 | {
|
---|
| 548 | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
|
---|
| 549 | commandName, exec, 'scayt_moresuggest', i + 1 );
|
---|
| 550 | moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
|
---|
| 551 | moreSuggestionsUnableAdded = true;
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | if ( moreSuggestionsUnableAdded )
|
---|
| 556 | {
|
---|
| 557 | // Register the More suggestions group;
|
---|
| 558 | editor.addMenuItem( 'scayt_moresuggest',
|
---|
| 559 | {
|
---|
| 560 | label : editor.lang.scayt.moreSuggestions,
|
---|
| 561 | group : 'scayt_moresuggest',
|
---|
| 562 | order : 10,
|
---|
| 563 | getItems : function()
|
---|
| 564 | {
|
---|
| 565 | return moreSuggestions;
|
---|
| 566 | }
|
---|
| 567 | });
|
---|
| 568 | mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | if ( in_array( 'all', contextCommands ) || in_array( 'ignore', contextCommands) )
|
---|
| 572 | {
|
---|
| 573 | var ignore_command = {
|
---|
| 574 | exec: function(){
|
---|
| 575 | scayt_control.ignore( node );
|
---|
| 576 | }
|
---|
| 577 | };
|
---|
| 578 | addButtonCommand( editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1 );
|
---|
| 579 | mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | if ( in_array( 'all', contextCommands ) || in_array( 'ignoreall', contextCommands ) )
|
---|
| 583 | {
|
---|
| 584 | var ignore_all_command = {
|
---|
| 585 | exec: function(){
|
---|
| 586 | scayt_control.ignoreAll( node );
|
---|
| 587 | }
|
---|
| 588 | };
|
---|
| 589 | addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
|
---|
| 590 | mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | if ( in_array( 'all', contextCommands ) || in_array( 'add', contextCommands ) )
|
---|
| 594 | {
|
---|
| 595 | var addword_command = {
|
---|
| 596 | exec: function(){
|
---|
| 597 | window.scayt.addWordToUserDictionary( node );
|
---|
| 598 | }
|
---|
| 599 | };
|
---|
| 600 | addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
|
---|
| 601 | mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF;
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | if ( scayt_control.fireOnContextMenu )
|
---|
| 605 | scayt_control.fireOnContextMenu( editor );
|
---|
| 606 |
|
---|
| 607 | return mainSuggestions;
|
---|
| 608 | });
|
---|
| 609 | }
|
---|
| 610 |
|
---|
| 611 | // Start plugin
|
---|
| 612 | if ( editor.config.scayt_autoStartup )
|
---|
| 613 | {
|
---|
| 614 | var showInitialState = function()
|
---|
| 615 | {
|
---|
| 616 | editor.removeListener( 'showScaytState', showInitialState );
|
---|
| 617 | command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
|
---|
| 618 | };
|
---|
| 619 | editor.on( 'showScaytState', showInitialState );
|
---|
| 620 | editor.on( 'instanceReady', function()
|
---|
| 621 | {
|
---|
| 622 | plugin.loadEngine( editor );
|
---|
| 623 | });
|
---|
| 624 | }
|
---|
| 625 | },
|
---|
| 626 |
|
---|
| 627 | afterInit : function( editor )
|
---|
| 628 | {
|
---|
| 629 | // Prevent word marker line from displaying in elements path. (#3570)
|
---|
| 630 | var elementsPathFilters;
|
---|
| 631 | if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )
|
---|
| 632 | {
|
---|
| 633 | elementsPathFilters.push( function( element )
|
---|
| 634 | {
|
---|
| 635 | if ( element.hasAttribute( 'scaytid' ) )
|
---|
| 636 | return false;
|
---|
| 637 | } );
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | }
|
---|
| 641 | });
|
---|
| 642 | })();
|
---|
| 643 |
|
---|
| 644 | /**
|
---|
| 645 | * If enabled (true), turns on SCAYT automatically after loading the editor.
|
---|
| 646 | * @name CKEDITOR.config.scayt_autoStartup
|
---|
| 647 | * @type Boolean
|
---|
| 648 | * @default false
|
---|
| 649 | * @example
|
---|
| 650 | * config.scayt_autoStartup = true;
|
---|
| 651 | */
|
---|
| 652 |
|
---|
| 653 | /**
|
---|
| 654 | * Defines the number of SCAYT suggestions to show in the main context menu.
|
---|
| 655 | * The possible values are:
|
---|
| 656 | * <ul>
|
---|
| 657 | * <li>0 (zero): All suggestions are displayed in the main context menu.</li>
|
---|
| 658 | * <li>Positive number: The maximum number of suggestions to shown in context
|
---|
| 659 | * menu. Other entries will be shown in "More Suggestions" sub-menu.</li>
|
---|
| 660 | * <li>Negative number: No suggestions are shown in the main context menu. All
|
---|
| 661 | * entries will be listed in the "Suggestions" sub-menu.</li>
|
---|
| 662 | * </ul>
|
---|
| 663 | * @name CKEDITOR.config.scayt_maxSuggestions
|
---|
| 664 | * @type Number
|
---|
| 665 | * @default 5
|
---|
| 666 | * @example
|
---|
| 667 | * // Display only three suggestions in the main context menu.
|
---|
| 668 | * config.scayt_maxSuggestions = 3;
|
---|
| 669 | * @example
|
---|
| 670 | * // Do not show the suggestions directly.
|
---|
| 671 | * config.scayt_maxSuggestions = -1;
|
---|
| 672 | */
|
---|
| 673 |
|
---|
| 674 | /**
|
---|
| 675 | * Sets the customer ID for SCAYT. Required for migration from free version
|
---|
| 676 | * with banner to paid version.
|
---|
| 677 | * @name CKEDITOR.config.scayt_customerid
|
---|
| 678 | * @type String
|
---|
| 679 | * @default ''
|
---|
| 680 | * @example
|
---|
| 681 | * // Load SCAYT using my customer ID.
|
---|
| 682 | * config.scayt_customerid = 'your-encrypted-customer-id';
|
---|
| 683 | */
|
---|
| 684 |
|
---|
| 685 | /**
|
---|
| 686 | * Enables/disables the "More Suggestions" sub-menu in the context menu.
|
---|
| 687 | * The possible values are "on" or "off".
|
---|
| 688 | * @name CKEDITOR.config.scayt_moreSuggestions
|
---|
| 689 | * @type String
|
---|
| 690 | * @default 'on'
|
---|
| 691 | * @example
|
---|
| 692 | * // Disables the "More Suggestions" sub-menu.
|
---|
| 693 | * config.scayt_moreSuggestions = 'off';
|
---|
| 694 | */
|
---|
| 695 |
|
---|
| 696 | /**
|
---|
| 697 | * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore"
|
---|
| 698 | * and "Ignore All"). It must be a string with one or more of the following
|
---|
| 699 | * words separated by a pipe ("|"):
|
---|
| 700 | * <ul>
|
---|
| 701 | * <li>"off": disables all options.</li>
|
---|
| 702 | * <li>"all": enables all options.</li>
|
---|
| 703 | * <li>"ignore": enables the "Ignore" option.</li>
|
---|
| 704 | * <li>"ignoreall": enables the "Ignore All" option.</li>
|
---|
| 705 | * <li>"add": enables the "Add Word" option.</li>
|
---|
| 706 | * </ul>
|
---|
| 707 | * @name CKEDITOR.config.scayt_contextCommands
|
---|
| 708 | * @type String
|
---|
| 709 | * @default 'all'
|
---|
| 710 | * @example
|
---|
| 711 | * // Show only "Add Word" and "Ignore All" in the context menu.
|
---|
| 712 | * config.scayt_contextCommands = 'add|ignoreall';
|
---|
| 713 | */
|
---|
| 714 |
|
---|
| 715 | /**
|
---|
| 716 | * Sets the default spellchecking language for SCAYT.
|
---|
| 717 | * @name CKEDITOR.config.scayt_sLang
|
---|
| 718 | * @type String
|
---|
| 719 | * @default 'en_US'
|
---|
| 720 | * @example
|
---|
| 721 | * // Sets SCAYT to German.
|
---|
| 722 | * config.scayt_sLang = 'de_DE';
|
---|
| 723 | */
|
---|
| 724 |
|
---|
| 725 | /**
|
---|
| 726 | * Sets the visibility of the SCAYT tabs in the settings dialog and toolbar
|
---|
| 727 | * button. The value must contain a "1" (enabled) or "0" (disabled) number for
|
---|
| 728 | * each of the following entries, in this precise order, separated by a
|
---|
| 729 | * comma (","): "Options", "Languages" and "Dictionary".
|
---|
| 730 | * @name CKEDITOR.config.scayt_uiTabs
|
---|
| 731 | * @type String
|
---|
| 732 | * @default '1,1,1'
|
---|
| 733 | * @example
|
---|
| 734 | * // Hide the "Languages" tab.
|
---|
| 735 | * config.scayt_uiTabs = '1,0,1';
|
---|
| 736 | */
|
---|
| 737 |
|
---|
| 738 |
|
---|
| 739 | /**
|
---|
| 740 | * Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application.
|
---|
| 741 | * Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l .
|
---|
| 742 | * @name CKEDITOR.config.scayt_srcUrl
|
---|
| 743 | * @type String
|
---|
| 744 | * @default ''
|
---|
| 745 | * @example
|
---|
| 746 | * config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js";
|
---|
| 747 | */
|
---|
| 748 |
|
---|
| 749 | /**
|
---|
| 750 | * Links SCAYT to custom dictionaries. It's a string containing dictionary ids
|
---|
| 751 | * separared by commas (","). Available only for licensed version.
|
---|
| 752 | * Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support .
|
---|
| 753 | * @name CKEDITOR.config.scayt_customDictionaryIds
|
---|
| 754 | * @type String
|
---|
| 755 | * @default ''
|
---|
| 756 | * @example
|
---|
| 757 | * config.scayt_customDictionaryIds = '3021,3456,3478"';
|
---|
| 758 | */
|
---|
| 759 |
|
---|
| 760 | /**
|
---|
| 761 | * Makes it possible to activate a custom dictionary on SCAYT. The user
|
---|
| 762 | * dictionary name must be used. Available only for licensed version.
|
---|
| 763 | * @name CKEDITOR.config.scayt_userDictionaryName
|
---|
| 764 | * @type String
|
---|
| 765 | * @default ''
|
---|
| 766 | * @example
|
---|
| 767 | * config.scayt_userDictionaryName = 'MyDictionary';
|
---|
| 768 | */
|
---|