JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / scayt / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 /**\r
7  * @fileOverview Spell Check As You Type (SCAYT).\r
8  * Button name : Scayt.\r
9  */\r
10 \r
11 (function()\r
12 {\r
13         var commandName         = 'scaytcheck',\r
14                 openPage                = '',\r
15                 scayt_paused    = null;\r
16 \r
17         // Checks if a value exists in an array\r
18         function in_array(needle, haystack)\r
19         {\r
20                 var found = false, key;\r
21                 for (key in haystack)\r
22                 {\r
23                         if ((haystack[key] === needle) || ( haystack[key] == needle))\r
24                         {\r
25                                 found = true;\r
26                                 break;\r
27                         }\r
28                 }\r
29                 return found;\r
30         }\r
31 \r
32         var onEngineLoad = function()\r
33         {\r
34                 var editor = this;\r
35 \r
36                 var createInstance = function() // Create new instance every time Document is created.\r
37                 {\r
38                         // Initialise Scayt instance.\r
39                         var oParams = {};\r
40                         oParams.srcNodeRef = editor.document.getWindow().$.frameElement;                // Get the iframe.\r
41                         // syntax : AppName.AppVersion@AppRevision\r
42                         oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;\r
43                         oParams.customerid = editor.config.scayt_customerid  || "1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2";\r
44                         oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds;\r
45                         oParams.userDictionaryName = editor.config.scayt_userDictionaryName;\r
46                         oParams.sLang = editor.config.scayt_sLang || "en_US";\r
47 \r
48                         if ( CKEDITOR._scaytParams )\r
49                         {\r
50                                 for ( var k in CKEDITOR._scaytParams )\r
51                                 {\r
52                                         oParams[ k ] = CKEDITOR._scaytParams[ k ];\r
53                                 }\r
54                         }\r
55 \r
56                         var scayt_control = new window.scayt( oParams );\r
57 \r
58                         // Copy config.\r
59                         var     lastInstance = plugin.instances[ editor.name ];\r
60                         if ( lastInstance )\r
61                         {\r
62                                 scayt_control.sLang = lastInstance.sLang;\r
63                                 scayt_control.option( lastInstance.option() );\r
64                                 scayt_control.paused = lastInstance.paused;\r
65                         }\r
66 \r
67                         plugin.instances[ editor.name ] = scayt_control;\r
68 \r
69                         //window.scayt.uiTags\r
70                         var menuGroup = 'scaytButton';\r
71                         var uiTabs = window.scayt.uiTags;\r
72                         var fTabs  = [];\r
73 \r
74                         for (var i = 0,l=4; i<l; i++)\r
75                                 fTabs.push( uiTabs[i] && plugin.uiTabs[i] );\r
76 \r
77                         plugin.uiTabs = fTabs;\r
78                         try {\r
79                                 scayt_control.setDisabled( scayt_paused === false );\r
80                         } catch (e) {}\r
81 \r
82                         editor.fire( 'showScaytState' );\r
83                 };\r
84 \r
85                 editor.on( 'contentDom', createInstance );\r
86                 editor.on( 'contentDomUnload', function()\r
87                         {\r
88                                 // Remove scripts.\r
89                                 var scripts = CKEDITOR.document.getElementsByTag( 'script' ),\r
90                                         scaytIdRegex =  /^dojoIoScript(\d+)$/i,\r
91                                         scaytSrcRegex =  /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;\r
92 \r
93                                 for ( var i=0; i < scripts.count(); i++ )\r
94                                 {\r
95                                         var script = scripts.getItem( i ),\r
96                                                 id = script.getId(),\r
97                                                 src = script.getAttribute( 'src' );\r
98 \r
99                                         if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))\r
100                                                 script.remove();\r
101                                 }\r
102                         });\r
103 \r
104                 editor.on( 'beforeCommandExec', function( ev )          // Disable SCAYT before Source command execution.\r
105                         {\r
106                                 if ( (ev.data.name == 'source' ||  ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )\r
107                                 {\r
108                                         var scayt_instanse = plugin.getScayt( editor );\r
109                                         if ( scayt_instanse )\r
110                                         {\r
111                                                 scayt_paused = scayt_instanse.paused = !scayt_instanse.disabled;\r
112                                                 scayt_instanse.destroy();\r
113                                                 delete plugin.instances[ editor.name ];\r
114                                         }\r
115                                 }\r
116                         });\r
117 \r
118 \r
119                 editor.on( 'destroy', function()\r
120                         {\r
121                                 plugin.getScayt( editor ).destroy();\r
122                         });\r
123                 // Listen to data manipulation to reflect scayt markup.\r
124                 editor.on( 'afterSetData', function()\r
125                         {\r
126                                 if ( plugin.isScaytEnabled( editor ) )\r
127                                         plugin.getScayt( editor ).refresh();\r
128                         });\r
129 \r
130                 // Reload spell-checking for current word after insertion completed.\r
131                 editor.on( 'insertElement', function()\r
132                         {\r
133                                 var scayt_instance = plugin.getScayt( editor );\r
134                                 if ( plugin.isScaytEnabled( editor ) )\r
135                                 {\r
136                                         // Unlock the selection before reload, SCAYT will take\r
137                                         // care selection update.\r
138                                         if ( CKEDITOR.env.ie )\r
139                                                 editor.getSelection().unlock( true );\r
140 \r
141                                         // Swallow any SCAYT engine errors.\r
142                                         try{\r
143                                                 scayt_instance.refresh();\r
144                                         }catch( er )\r
145                                         {}\r
146                                 }\r
147                         }, this, null, 50 );\r
148 \r
149                 editor.on( 'insertHtml', function()\r
150                         {\r
151 \r
152                                 var scayt_instance = plugin.getScayt( editor );\r
153                                 if ( plugin.isScaytEnabled( editor ) )\r
154                                 {\r
155                                         // Unlock the selection before reload, SCAYT will take\r
156                                         // care selection update.\r
157                                         if ( CKEDITOR.env.ie )\r
158                                                 editor.getSelection().unlock( true );\r
159 \r
160                                         // Swallow any SCAYT engine errors.\r
161                                         try{\r
162                                                 scayt_instance.refresh();\r
163                                         }catch( er )\r
164                                         {}\r
165                                 }\r
166                         }, this, null, 50 );\r
167 \r
168                 editor.on( 'scaytDialog', function( ev )        // Communication with dialog.\r
169                         {\r
170                                 ev.data.djConfig = window.djConfig;\r
171                                 ev.data.scayt_control = plugin.getScayt( editor );\r
172                                 ev.data.tab = openPage;\r
173                                 ev.data.scayt = window.scayt;\r
174                         });\r
175 \r
176                 var dataProcessor = editor.dataProcessor,\r
177                         htmlFilter = dataProcessor && dataProcessor.htmlFilter;\r
178                 if ( htmlFilter )\r
179                 {\r
180                         htmlFilter.addRules(\r
181                                 {\r
182                                         elements :\r
183                                         {\r
184                                                 span : function( element )\r
185                                                 {\r
186                                                         if ( element.attributes.scayt_word && element.attributes.scaytid )\r
187                                                         {\r
188                                                                 delete element.name;    // Write children, but don't write this node.\r
189                                                                 return element;\r
190                                                         }\r
191                                                 }\r
192                                         }\r
193                                 }\r
194                         );\r
195                 }\r
196 \r
197                 if ( editor.document )\r
198                         createInstance();\r
199         };\r
200 \r
201         CKEDITOR.plugins.scayt =\r
202         {\r
203                 engineLoaded : false,\r
204                 instances : {},\r
205                 getScayt : function( editor )\r
206                 {\r
207                         return this.instances[ editor.name ];\r
208                 },\r
209                 isScaytReady : function( editor )\r
210                 {\r
211                         return this.engineLoaded === true &&\r
212                                 'undefined' !== typeof window.scayt && this.getScayt( editor );\r
213                 },\r
214                 isScaytEnabled : function( editor )\r
215                 {\r
216                         var scayt_instanse = this.getScayt( editor );\r
217                         return ( scayt_instanse ) ? scayt_instanse.disabled === false : false;\r
218                 },\r
219                 loadEngine : function( editor )\r
220                 {\r
221                         if ( this.engineLoaded === true )\r
222                                 return onEngineLoad.apply( editor );    // Add new instance.\r
223                         else if ( this.engineLoaded == -1 )                     // We are waiting.\r
224                                 return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor );} ); // Use function(){} to avoid rejection as duplicate.\r
225 \r
226                         CKEDITOR.on( 'scaytReady', onEngineLoad, editor );\r
227                         CKEDITOR.on( 'scaytReady', function()\r
228                                 {\r
229                                         this.engineLoaded = true;\r
230                                 },\r
231                                 this,\r
232                                 null,\r
233                                 0 );    // First to run.\r
234 \r
235                         this.engineLoaded = -1; // Loading in progress.\r
236 \r
237                         // compose scayt url\r
238                         var protocol = document.location.protocol;\r
239                         // Default to 'http' for unknown.\r
240                         protocol = protocol.search( /https?:/) != -1? protocol : 'http:';\r
241                         var baseUrl  = "svc.spellchecker.net/spellcheck3/lf/scayt/scayt21.js";\r
242 \r
243                         var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl );\r
244                         var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  "/";\r
245 \r
246                         CKEDITOR._djScaytConfig =\r
247                         {\r
248                                 baseUrl: scaytConfigBaseUrl,\r
249                                 addOnLoad:\r
250                                 [\r
251                                         function()\r
252                                         {\r
253                                                 CKEDITOR.fireOnce( "scaytReady" );\r
254                                         }\r
255                                 ],\r
256                                 isDebug: false\r
257                         };\r
258                         // Append javascript code.\r
259                         CKEDITOR.document.getHead().append(\r
260                                 CKEDITOR.document.createElement( 'script',\r
261                                         {\r
262                                                 attributes :\r
263                                                         {\r
264                                                                 type : 'text/javascript',\r
265                                                                 src : scaytUrl\r
266                                                         }\r
267                                         })\r
268                         );\r
269 \r
270                         return null;\r
271                 },\r
272                 parseUrl : function ( data )\r
273                 {\r
274                         var match;\r
275                         if ( data.match && ( match = data.match(/(.*)[\/\\](.*?\.\w+)$/) ) )\r
276                                 return { path: match[1], file: match[2] };\r
277                         else\r
278                                 return data;\r
279                 }\r
280         };\r
281 \r
282         var plugin = CKEDITOR.plugins.scayt;\r
283 \r
284         // Context menu constructing.\r
285         var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder )\r
286         {\r
287                 editor.addCommand( commandName, command );\r
288 \r
289                 // If the "menu" plugin is loaded, register the menu item.\r
290                 editor.addMenuItem( commandName,\r
291                         {\r
292                                 label : buttonLabel,\r
293                                 command : commandName,\r
294                                 group : menugroup,\r
295                                 order : menuOrder\r
296                         });\r
297         };\r
298 \r
299         var commandDefinition =\r
300         {\r
301                 preserveState : true,\r
302                 editorFocus : false,\r
303 \r
304                 exec: function( editor )\r
305                 {\r
306                         if ( plugin.isScaytReady( editor ) )\r
307                         {\r
308                                 var isEnabled = plugin.isScaytEnabled( editor );\r
309 \r
310                                 this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );\r
311 \r
312                                 var scayt_control = plugin.getScayt( editor );\r
313                                 scayt_control.setDisabled( isEnabled );\r
314                         }\r
315                         else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 )        // Load first time\r
316                         {\r
317                                 this.setState( CKEDITOR.TRISTATE_DISABLED );\r
318 \r
319                                 editor.on( 'showScaytState', function()\r
320                                         {\r
321                                                 this.removeListener();\r
322                                                 this.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
323                                         },\r
324                                         this);\r
325 \r
326                                 plugin.loadEngine( editor );\r
327                         }\r
328                 }\r
329         };\r
330 \r
331         // Add scayt plugin.\r
332         CKEDITOR.plugins.add( 'scayt',\r
333         {\r
334                 requires : [ 'menubutton' ],\r
335 \r
336                 beforeInit : function( editor )\r
337                 {\r
338                         // Register own rbc menu group.\r
339                         editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups;\r
340                 },\r
341 \r
342                 init : function( editor )\r
343                 {\r
344                         var moreSuggestions = {};\r
345                         var mainSuggestions = {};\r
346 \r
347                         // Scayt command.\r
348                         var command = editor.addCommand( commandName, commandDefinition );\r
349 \r
350                         // Add Options dialog.\r
351                         CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );\r
352                         // read ui tags\r
353                         var confuiTabs = editor.config.scayt_uiTabs || "1,1,1";\r
354                         var uiTabs =[];\r
355                         // string tp array convert\r
356                         confuiTabs = confuiTabs.split(",");\r
357                         // check array length ! allwaays must be 3 filled with 1 or 0\r
358                         for (var i=0,l=3; i<l; i++){\r
359                                 var flag = parseInt(confuiTabs[i] || "1" ,10);\r
360                                 uiTabs.push(  flag  );\r
361                         }\r
362 \r
363                         var menuGroup = 'scaytButton';\r
364                         editor.addMenuGroup( menuGroup );\r
365                         // combine menu items to render\r
366                         var uiMuneItems = {};\r
367 \r
368                         // allways added\r
369                         uiMuneItems.scaytToggle =\r
370                                 {\r
371                                         label : editor.lang.scayt.enable,\r
372                                         command : commandName,\r
373                                         group : menuGroup\r
374                                 };\r
375 \r
376                         if (uiTabs[0] == 1)\r
377                                 uiMuneItems.scaytOptions =\r
378                                 {\r
379                                         label : editor.lang.scayt.options,\r
380                                         group : menuGroup,\r
381                                         onClick : function()\r
382                                         {\r
383                                                 openPage = 'options';\r
384                                                 editor.openDialog( commandName );\r
385                                         }\r
386                                 };\r
387 \r
388                         if (uiTabs[1] == 1)\r
389                                 uiMuneItems.scaytLangs =\r
390                                 {\r
391                                         label : editor.lang.scayt.langs,\r
392                                         group : menuGroup,\r
393                                         onClick : function()\r
394                                         {\r
395                                                 openPage = 'langs';\r
396                                                 editor.openDialog( commandName );\r
397                                         }\r
398                                 };\r
399                         if (uiTabs[2] == 1)\r
400                                 uiMuneItems.scaytDict =\r
401                                 {\r
402                                         label : editor.lang.scayt.dictionariesTab,\r
403                                         group : menuGroup,\r
404                                         onClick : function()\r
405                                         {\r
406                                                 openPage = 'dictionaries';\r
407                                                 editor.openDialog( commandName );\r
408                                         }\r
409                                 };\r
410                         // allways added\r
411                         uiMuneItems.scaytAbout =\r
412                                 {\r
413                                         label : editor.lang.scayt.about,\r
414                                         group : menuGroup,\r
415                                         onClick : function()\r
416                                         {\r
417                                                 openPage = 'about';\r
418                                                 editor.openDialog( commandName );\r
419                                         }\r
420                                 }\r
421                         ;\r
422 \r
423                         uiTabs[3] = 1; // about us tab is allways on\r
424                         plugin.uiTabs = uiTabs;\r
425 \r
426                         editor.addMenuItems( uiMuneItems );\r
427 \r
428                                 editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,\r
429                                         {\r
430                                                 label : editor.lang.scayt.title,\r
431                                                 title : editor.lang.scayt.title,\r
432                                                 className : 'cke_button_scayt',\r
433                                                 onRender: function()\r
434                                                 {\r
435                                                         command.on( 'state', function()\r
436                                                         {\r
437                                                                 this.setState( command.state );\r
438                                                         },\r
439                                                         this);\r
440                                                 },\r
441                                                 onMenu : function()\r
442                                                 {\r
443                                                         var isEnabled = plugin.isScaytEnabled( editor );\r
444 \r
445                                                         editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ];\r
446 \r
447                                                         return {\r
448                                                                 scaytToggle  : CKEDITOR.TRISTATE_OFF,\r
449                                                                 scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
450                                                                 scaytLangs   : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
451                                                                 scaytDict    : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,\r
452                                                                 scaytAbout   : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED\r
453                                                         };\r
454                                                 }\r
455                                         });\r
456 \r
457                         // If the "contextmenu" plugin is loaded, register the listeners.\r
458                         if ( editor.contextMenu && editor.addMenuItems )\r
459                         {\r
460                                 editor.contextMenu.addListener( function( element )\r
461                                         {\r
462                                                 if ( !( plugin.isScaytEnabled( editor ) && element ) )\r
463                                                         return null;\r
464 \r
465                                                 var scayt_control = plugin.getScayt( editor ),\r
466                                                         word = scayt_control.getWord( element.$ );\r
467 \r
468                                                 if ( !word )\r
469                                                         return null;\r
470 \r
471                                                 var sLang = scayt_control.getLang(),\r
472                                                         _r = {},\r
473                                                         items_suggestion = window.scayt.getSuggestion( word, sLang );\r
474                                                 if (!items_suggestion || !items_suggestion.length )\r
475                                                         return null;\r
476                                                 // Remove unused commands and menuitems\r
477                                                 for ( i in moreSuggestions )\r
478                                                 {\r
479                                                         delete editor._.menuItems[ i ];\r
480                                                         delete editor._.commands[ i ];\r
481                                                 }\r
482                                                 for ( i in mainSuggestions )\r
483                                                 {\r
484                                                         delete editor._.menuItems[ i ];\r
485                                                         delete editor._.commands[ i ];\r
486                                                 }\r
487                                                 moreSuggestions = {};           // Reset items.\r
488                                                 mainSuggestions = {};\r
489 \r
490                                                 var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on";\r
491                                                 var moreSuggestionsUnableAdded = false;\r
492 \r
493                                                 var maxSuggestions = editor.config.scayt_maxSuggestions;\r
494                                                 ( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 );\r
495                                                 !maxSuggestions && ( maxSuggestions = items_suggestion.length );\r
496 \r
497                                                 var contextCommands = editor.config.scayt_contextCommands || "all";\r
498                                                 contextCommands = contextCommands.split("|");\r
499 \r
500                                                 for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )\r
501                                                 {\r
502                                                         var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );\r
503                                                         var exec = ( function( el, s )\r
504                                                                 {\r
505                                                                         return {\r
506                                                                                 exec: function()\r
507                                                                                 {\r
508                                                                                         scayt_control.replace(el, s);\r
509                                                                                 }\r
510                                                                         };\r
511                                                                 })( element.$, items_suggestion[i] );\r
512 \r
513                                                         if ( i < maxSuggestions )\r
514                                                         {\r
515                                                                 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
516                                                                         commandName, exec, 'scayt_suggest', i + 1 );\r
517                                                                 _r[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
518                                                                 mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
519                                                         }\r
520                                                         else if ( moreSuggestionsUnable == "on" )\r
521                                                         {\r
522                                                                 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],\r
523                                                                         commandName, exec, 'scayt_moresuggest', i + 1 );\r
524                                                                 moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;\r
525                                                                 moreSuggestionsUnableAdded = true;\r
526                                                         }\r
527                                                 }\r
528 \r
529                                                 if ( moreSuggestionsUnableAdded ){\r
530                                                         // Rgister the More suggestions group;\r
531                                                         editor.addMenuItem( 'scayt_moresuggest',\r
532                                                         {\r
533                                                                 label : editor.lang.scayt.moreSuggestions,\r
534                                                                 group : 'scayt_moresuggest',\r
535                                                                 order : 10,\r
536                                                                 getItems : function()\r
537                                                                 {\r
538                                                                         return moreSuggestions;\r
539                                                                 }\r
540                                                         });\r
541                                                         mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;\r
542 \r
543                                                 }\r
544 \r
545                                                 if ( in_array( "all",contextCommands )  || in_array("ignore",contextCommands)  )\r
546                                                 {\r
547                                                         var ignore_command = {\r
548                                                                 exec: function(){\r
549                                                                         scayt_control.ignore(element.$);\r
550                                                                 }\r
551                                                         };\r
552                                                         addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);\r
553                                                         mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF;\r
554                                                 }\r
555 \r
556                                                 if ( in_array( "all",contextCommands )  || in_array("ignoreall",contextCommands)  )\r
557                                                 {\r
558                                                         var ignore_all_command = {\r
559                                                                 exec: function(){\r
560                                                                         scayt_control.ignoreAll(element.$);\r
561                                                                 }\r
562                                                         };\r
563                                                         addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);\r
564                                                         mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;\r
565                                                 }\r
566 \r
567                                                 if ( in_array( "all",contextCommands )  || in_array("add",contextCommands)  )\r
568                                                 {\r
569                                                         var addword_command = {\r
570                                                                 exec: function(){\r
571                                                                         window.scayt.addWordToUserDictionary(element.$);\r
572                                                                 }\r
573                                                         };\r
574                                                         addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);\r
575                                                         mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF;\r
576                                                 }\r
577 \r
578                                                 if ( scayt_control.fireOnContextMenu )\r
579                                                         scayt_control.fireOnContextMenu( editor );\r
580 \r
581                                                 return mainSuggestions;\r
582                                         });\r
583                         }\r
584 \r
585                         // Start plugin\r
586                         if ( editor.config.scayt_autoStartup )\r
587                         {\r
588                                 var showInitialState = function()\r
589                                 {\r
590                                         editor.removeListener( 'showScaytState', showInitialState );\r
591                                         command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );\r
592                                 };\r
593                                 editor.on( 'showScaytState', showInitialState );\r
594 \r
595                                 plugin.loadEngine( editor );\r
596                         }\r
597                 }\r
598         });\r
599 })();\r
600 \r
601 // TODO: Documentation\r
602 // CKEDITOR.config.scayt_maxSuggestions\r
603 // CKEDITOR.config.scayt_autoStartup\r