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