16 | | var onEngineLoad = function() |
17 | | { |
18 | | var editor = this; |
| 34 | var createInstance = function() // Create new instance every time Document is created. |
| 35 | { |
| 36 | // Initialise Scayt instance. |
| 37 | var oParams = {}; |
| 38 | oParams.srcNodeRef = editor.document.getWindow().$.frameElement; // Get the iframe. |
| 39 | // syntax : AppName.AppVersion@AppRevision |
| 40 | oParams.assocApp = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision; |
| 41 | oParams.customerid = editor.config.scayt_customerid || ""; |
| 42 | oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds; |
| 43 | oParams.userDictionaryName = editor.config.scayt_userDictionaryName; |
| 44 | oParams.sLang = editor.config.scayt_sLang || "en_US"; |
| 45 | |
| 46 | if ( CKEDITOR._scaytParams ) |
| 47 | { |
| 48 | for ( var k in CKEDITOR._scaytParams ) |
| 49 | { |
| 50 | oParams[ k ] = CKEDITOR._scaytParams[ k ]; |
| 51 | } |
| 52 | } |
28 | | oParams.customerid = editor.config.scayt_customerid || "1:11111111111111111111111111111111111111"; |
29 | | oParams.customDictionaryName = editor.config.scayt_customDictionaryName; |
30 | | oParams.userDictionaryName = editor.config.scayt_userDictionaryName; |
31 | | oParams.defLang = editor.scayt_defLang; |
| 56 | // Copy config. |
| 57 | var lastInstance = plugin.instances[ editor.name ]; |
| 58 | if ( lastInstance ) |
| 59 | { |
| 60 | scayt_control.sLang = lastInstance.sLang; |
| 61 | scayt_control.option( lastInstance.option() ); |
| 62 | scayt_control.paused = lastInstance.paused; |
| 63 | } |
33 | | if ( CKEDITOR._scaytParams ) |
34 | | { |
35 | | for ( var k in CKEDITOR._scaytParams ) |
36 | | { |
37 | | oParams[ k ] = CKEDITOR._scaytParams[ k ]; |
38 | | } |
39 | | } |
| 65 | plugin.instances[ editor.name ] = scayt_control; |
| 66 | |
| 67 | //window.scayt.uiTags |
| 68 | var menuGroup = 'scaytButton'; |
| 69 | var uiTabs = window.scayt.uiTags; |
| 70 | var fTabs = []; |
| 71 | |
| 72 | for (var i = 0,l=4; i<l; i++) |
| 73 | fTabs.push( uiTabs[i] && plugin.uiTabs[i] ); |
| 74 | |
| 75 | plugin.uiTabs = fTabs; |
| 76 | |
| 77 | try { |
| 78 | scayt_control.setDisabled( scayt_control.paused === false ); |
| 79 | } catch (e) {} |
| 80 | editor.fire( 'showScaytState' ); |
| 81 | }; |
54 | | try { |
55 | | scayt_control.setDisabled( scayt_control.paused === false ); // I really don't know why it causes JS error in IE |
56 | | } catch (e) {} |
57 | | editor.fire( 'showScaytState' ); |
58 | | }; |
| 102 | editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution. |
| 103 | { |
| 104 | if ( (ev.data.name == 'source' || ev.data.name == 'newpage') && editor.mode == 'wysiwyg' ) |
| 105 | { |
| 106 | var scayt_instanse = plugin.getScayt( editor ); |
| 107 | if ( scayt_instanse ) |
| 108 | { |
| 109 | scayt_instanse.paused = !scayt_instanse.disabled; |
| 110 | scayt_instanse.destroy(); |
| 111 | delete plugin.instances[ editor.name ]; |
| 112 | } |
| 113 | } |
| 114 | }); |
| 115 | |
60 | | editor.on( 'contentDom', createInstance ); |
61 | | editor.on( 'contentDomUnload', function() |
62 | | { |
63 | | // Remove scripts. |
64 | | var scripts = CKEDITOR.document.getElementsByTag( 'script' ), |
65 | | scaytIdRegex = /^dojoIoScript(\d+)$/i, |
66 | | scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i; |
| 117 | editor.on( 'destroy', function() |
| 118 | { |
| 119 | plugin.getScayt( editor ).destroy(); |
| 120 | }); |
| 121 | // Listen to data manipulation to reflect scayt markup. |
| 122 | editor.on( 'afterSetData', function() |
| 123 | { |
| 124 | if ( plugin.isScaytEnabled( editor ) ) |
| 125 | plugin.getScayt( editor ).refresh(); |
| 126 | }); |
68 | | for ( var i=0; i < scripts.count(); i++ ) |
69 | | { |
70 | | var script = scripts.getItem( i ), |
71 | | id = script.getId(), |
72 | | src = script.getAttribute( 'src' ); |
| 128 | // Reload spell-checking for current word after insertion completed. |
| 129 | editor.on( 'insertElement', function() |
| 130 | { |
| 131 | var scayt_instance = plugin.getScayt( editor ); |
| 132 | if ( plugin.isScaytEnabled( editor ) ) |
| 133 | { |
| 134 | // Unlock the selection before reload, SCAYT will take |
| 135 | // care selection update. |
| 136 | if ( CKEDITOR.env.ie ) |
| 137 | editor.getSelection().unlock( true ); |
79 | | editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution. |
80 | | { |
81 | | if ( (ev.data.name == 'source' || ev.data.name == 'newpage') && editor.mode == 'wysiwyg' ) |
82 | | { |
83 | | var scayt_instanse = plugin.getScayt( editor ); |
84 | | if ( scayt_instanse ) |
85 | | { |
86 | | scayt_instanse.paused = !scayt_instanse.disabled; |
87 | | scayt_instanse.destroy(); |
88 | | delete plugin.instances[ editor.name ]; |
89 | | } |
90 | | } |
91 | | }); |
| 147 | editor.on( 'insertHtml', function() |
| 148 | { |
| 149 | |
| 150 | var scayt_instance = plugin.getScayt( editor ); |
| 151 | if ( plugin.isScaytEnabled( editor ) ) |
| 152 | { |
| 153 | // Unlock the selection before reload, SCAYT will take |
| 154 | // care selection update. |
| 155 | if ( CKEDITOR.env.ie ) |
| 156 | editor.getSelection().unlock( true ); |
119 | | editor.on( 'scaytDialog', function( ev ) // Communication with dialog. |
120 | | { |
121 | | ev.data.djConfig = window.djConfig; |
122 | | ev.data.scayt_control = plugin.getScayt( editor ); |
123 | | ev.data.tab = openPage; |
124 | | ev.data.scayt = window.scayt; |
125 | | }); |
| 168 | editor.on( 'scaytDialog', function( ev ) // Communication with dialog. |
| 169 | { |
| 170 | ev.data.djConfig = window.djConfig; |
| 171 | ev.data.scayt_control = plugin.getScayt( editor ); |
| 172 | ev.data.tab = openPage; |
| 173 | ev.data.scayt = window.scayt; |
| 174 | }); |
127 | | var dataProcessor = editor.dataProcessor, |
128 | | htmlFilter = dataProcessor && dataProcessor.htmlFilter; |
129 | | if ( htmlFilter ) |
130 | | { |
131 | | htmlFilter.addRules( |
132 | | { |
133 | | elements : |
134 | | { |
135 | | span : function( element ) |
136 | | { |
137 | | if ( element.attributes.scayt_word && element.attributes.scaytid ) |
138 | | { |
139 | | delete element.name; // Write children, but don't write this node. |
140 | | return element; |
141 | | } |
142 | | } |
143 | | } |
144 | | } |
145 | | ); |
146 | | } |
| 176 | var dataProcessor = editor.dataProcessor, |
| 177 | htmlFilter = dataProcessor && dataProcessor.htmlFilter; |
| 178 | if ( htmlFilter ) |
| 179 | { |
| 180 | htmlFilter.addRules( |
| 181 | { |
| 182 | elements : |
| 183 | { |
| 184 | span : function( element ) |
| 185 | { |
| 186 | if ( element.attributes.scayt_word && element.attributes.scaytid ) |
| 187 | { |
| 188 | delete element.name; // Write children, but don't write this node. |
| 189 | return element; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | ); |
| 195 | } |
152 | | CKEDITOR.plugins.scayt = |
153 | | { |
154 | | engineLoaded : false, |
155 | | instances : {}, |
156 | | getScayt : function( editor ) |
157 | | { |
158 | | return this.instances[ editor.name ]; |
159 | | }, |
160 | | isScaytReady : function( editor ) |
161 | | { |
162 | | return this.engineLoaded === true && |
163 | | 'undefined' !== typeof window.scayt && this.getScayt( editor ); |
164 | | }, |
165 | | isScaytEnabled : function( editor ) |
166 | | { |
167 | | var scayt_instanse = this.getScayt( editor ); |
168 | | return ( scayt_instanse ) ? scayt_instanse.disabled === false : false; |
169 | | }, |
170 | | loadEngine : function( editor ) |
171 | | { |
172 | | if ( this.engineLoaded === true ) |
173 | | return onEngineLoad.apply( editor ); // Add new instance. |
174 | | else if ( this.engineLoaded == -1 ) // We are waiting. |
175 | | return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor );} ); // Use function(){} to avoid rejection as duplicate. |
| 201 | CKEDITOR.plugins.scayt = |
| 202 | { |
| 203 | engineLoaded : false, |
| 204 | instances : {}, |
| 205 | getScayt : function( editor ) |
| 206 | { |
| 207 | return this.instances[ editor.name ]; |
| 208 | }, |
| 209 | isScaytReady : function( editor ) |
| 210 | { |
| 211 | return this.engineLoaded === true && |
| 212 | 'undefined' !== typeof window.scayt && this.getScayt( editor ); |
| 213 | }, |
| 214 | isScaytEnabled : function( editor ) |
| 215 | { |
| 216 | var scayt_instanse = this.getScayt( editor ); |
| 217 | return ( scayt_instanse ) ? scayt_instanse.disabled === false : false; |
| 218 | }, |
| 219 | loadEngine : function( editor ) |
| 220 | { |
| 221 | if ( this.engineLoaded === true ) |
| 222 | return onEngineLoad.apply( editor ); // Add new instance. |
| 223 | else if ( this.engineLoaded == -1 ) // We are waiting. |
| 224 | return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor );} ); // Use function(){} to avoid rejection as duplicate. |
177 | | CKEDITOR.on( 'scaytReady', onEngineLoad, editor ); |
178 | | CKEDITOR.on( 'scaytReady', function() |
179 | | { |
180 | | this.engineLoaded = true; |
181 | | }, |
182 | | this, |
183 | | null, |
184 | | 0 ); // First to run. |
| 226 | CKEDITOR.on( 'scaytReady', onEngineLoad, editor ); |
| 227 | CKEDITOR.on( 'scaytReady', function() |
| 228 | { |
| 229 | this.engineLoaded = true; |
| 230 | }, |
| 231 | this, |
| 232 | null, |
| 233 | 0 );// First to run. |
188 | | // compose scayt url |
189 | | var protocol = document.location.protocol; |
190 | | // Default to 'http' for unknown. |
191 | | protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; |
192 | | var baseUrl = "svc.spellchecker.net/spellcheck/lf/scayt/scayt1.js"; |
| 237 | // compose scayt url |
| 238 | var protocol = document.location.protocol; |
| 239 | // Default to 'http' for unknown. |
| 240 | protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; |
| 241 | var baseUrl = "svc.spellchecker.net/spellcheck/lf/scayt/scayt1.js"; |
197 | | CKEDITOR._djScaytConfig = |
198 | | { |
199 | | baseUrl: scaytConfigBaseUrl, |
200 | | addOnLoad: |
201 | | [ |
202 | | function() |
203 | | { |
204 | | CKEDITOR.fireOnce( "scaytReady" ); |
205 | | } |
206 | | ], |
207 | | isDebug: false |
208 | | }; |
209 | | // Append javascript code. |
210 | | CKEDITOR.document.getHead().append( |
211 | | CKEDITOR.document.createElement( 'script', |
212 | | { |
213 | | attributes : |
214 | | { |
215 | | type : 'text/javascript', |
216 | | src : scaytUrl |
217 | | } |
218 | | }) |
219 | | ); |
| 246 | CKEDITOR._djScaytConfig = |
| 247 | { |
| 248 | baseUrl: scaytConfigBaseUrl, |
| 249 | addOnLoad: |
| 250 | [ |
| 251 | function() |
| 252 | { |
| 253 | CKEDITOR.fireOnce( "scaytReady" ); |
| 254 | } |
| 255 | ], |
| 256 | isDebug: false |
| 257 | }; |
| 258 | // Append javascript code. |
| 259 | CKEDITOR.document.getHead().append( |
| 260 | CKEDITOR.document.createElement( 'script', |
| 261 | { |
| 262 | attributes : |
| 263 | { |
| 264 | type : 'text/javascript', |
| 265 | src : scaytUrl |
| 266 | } |
| 267 | }) |
| 268 | ); |
235 | | // Context menu constructing. |
236 | | var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder ) |
237 | | { |
238 | | editor.addCommand( commandName, command ); |
| 284 | // Context menu constructing. |
| 285 | var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder ) |
| 286 | { |
| 287 | editor.addCommand( commandName, command ); |
263 | | var scayt_control = plugin.getScayt( editor ); |
264 | | scayt_control.setDisabled( isEnabled ); |
265 | | } |
266 | | else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time |
267 | | { |
268 | | this.setState( CKEDITOR.TRISTATE_DISABLED ); |
| 312 | var scayt_control = plugin.getScayt( editor ); |
| 313 | scayt_control.setDisabled( isEnabled ); |
| 314 | } |
| 315 | else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time |
| 316 | { |
| 317 | this.setState( CKEDITOR.TRISTATE_DISABLED ); |
287 | | beforeInit : function( editor ) |
288 | | { |
289 | | // Register own rbc menu group. |
290 | | editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups; |
291 | | }, |
| 336 | beforeInit : function( editor ) |
| 337 | { |
| 338 | // Register own rbc menu group. |
| 339 | editor.config.menu_groups = 'scayt_suggest,scayt_moresuggest,scayt_control,' + editor.config.menu_groups; |
| 340 | }, |
301 | | // Add Options dialog. |
302 | | CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) ); |
| 350 | // Add Options dialog. |
| 351 | CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) ); |
| 352 | // read ui tags |
| 353 | var confuiTabs = editor.config.scayt_uiTabs || "1,1,1"; |
| 354 | var uiTabs =[]; |
| 355 | // string tp array convert |
| 356 | confuiTabs = confuiTabs.split(","); |
| 357 | // check array length ! allwaays must be 3 filled with 1 or 0 |
| 358 | for (var i=0,l=3; i<l; i++){ |
| 359 | var flag = parseInt(confuiTabs[i] || "1" ,10); |
| 360 | uiTabs.push( flag ); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | var menuGroup = 'scaytButton'; |
| 365 | editor.addMenuGroup( menuGroup ); |
| 366 | // combine menu items to render |
| 367 | var uiMuneItems = {}; |
| 368 | |
| 369 | // allways added |
| 370 | uiMuneItems.scaytToggle = |
| 371 | { |
| 372 | label : editor.lang.scayt.enable, |
| 373 | command : commandName, |
| 374 | group : menuGroup |
| 375 | }; |
| 376 | |
| 377 | if (uiTabs[0] == 1) |
| 378 | uiMuneItems.scaytOptions = |
| 379 | { |
| 380 | label : editor.lang.scayt.options, |
| 381 | group : menuGroup, |
| 382 | onClick : function() |
| 383 | { |
| 384 | openPage = 'options'; |
| 385 | editor.openDialog( commandName ); |
| 386 | } |
| 387 | }; |
304 | | var menuGroup = 'scaytButton'; |
305 | | editor.addMenuGroup( menuGroup ); |
306 | | editor.addMenuItems( |
307 | | { |
308 | | scaytToggle : |
309 | | { |
310 | | label : editor.lang.scayt.enable, |
311 | | command : commandName, |
312 | | group : menuGroup |
313 | | }, |
| 389 | if (uiTabs[1] == 1) |
| 390 | uiMuneItems.scaytLangs = |
| 391 | { |
| 392 | label : editor.lang.scayt.langs, |
| 393 | group : menuGroup, |
| 394 | onClick : function() |
| 395 | { |
| 396 | openPage = 'langs'; |
| 397 | editor.openDialog( commandName ); |
| 398 | } |
| 399 | }; |
| 400 | if (uiTabs[2] == 1) |
| 401 | uiMuneItems.scaytDict = |
| 402 | { |
| 403 | label : editor.lang.scayt.dictionariesTab, |
| 404 | group : menuGroup, |
| 405 | onClick : function() |
| 406 | { |
| 407 | openPage = 'dictionaries'; |
| 408 | editor.openDialog( commandName ); |
| 409 | } |
| 410 | }; |
| 411 | // allways added |
| 412 | uiMuneItems.scaytAbout = |
| 413 | { |
| 414 | label : editor.lang.scayt.about, |
| 415 | group : menuGroup, |
| 416 | onClick : function() |
| 417 | { |
| 418 | openPage = 'about'; |
| 419 | editor.openDialog( commandName ); |
| 420 | } |
| 421 | } |
| 422 | ; |
| 423 | |
| 424 | uiTabs[3] = 1; // about us tab is allways on |
| 425 | plugin.uiTabs = uiTabs; |
| 426 | |
| 427 | editor.addMenuItems( uiMuneItems ); |
315 | | scaytOptions : |
316 | | { |
317 | | label : editor.lang.scayt.options, |
318 | | group : menuGroup, |
319 | | onClick : function() |
320 | | { |
321 | | openPage = 'options'; |
322 | | editor.openDialog( commandName ); |
323 | | } |
324 | | }, |
| 429 | editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON, |
| 430 | { |
| 431 | label : editor.lang.scayt.title, |
| 432 | title : editor.lang.scayt.title, |
| 433 | className : 'cke_button_scayt', |
| 434 | onRender: function() |
| 435 | { |
| 436 | command.on( 'state', function() |
| 437 | { |
| 438 | this.setState( command.state ); |
| 439 | }, |
| 440 | this); |
| 441 | |
| 442 | }, |
| 443 | onMenu : function() |
| 444 | { |
| 445 | var isEnabled = plugin.isScaytEnabled( editor ); |
| 446 | |
| 447 | editor.getMenuItem( 'scaytToggle' ).label = editor.lang.scayt[ isEnabled ? 'disable' : 'enable' ]; |
| 448 | |
| 449 | return { |
| 450 | scaytToggle : CKEDITOR.TRISTATE_OFF, |
| 451 | scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, |
| 452 | scaytLangs : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, |
| 453 | scaytDict : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, |
| 454 | scaytAbout : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED |
| 455 | }; |
| 456 | } |
| 457 | }); |
349 | | editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON, |
350 | | { |
351 | | label : editor.lang.scayt.title, |
352 | | title : editor.lang.scayt.title, |
353 | | className : 'cke_button_scayt', |
354 | | onRender: function() |
355 | | { |
356 | | command.on( 'state', function() |
357 | | { |
358 | | this.setState( command.state ); |
359 | | }, |
360 | | this); |
361 | | }, |
362 | | onMenu : function() |
363 | | { |
364 | | var isEnabled = plugin.isScaytEnabled( editor ); |
| 471 | if ( !word ) |
| 472 | return null; |
368 | | return { |
369 | | scaytToggle : CKEDITOR.TRISTATE_OFF, |
370 | | scaytOptions : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, |
371 | | scaytLangs : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED, |
372 | | scaytAbout : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED |
373 | | }; |
374 | | } |
375 | | }); |
| 481 | for ( i in moreSuggestions ) |
| 482 | { |
| 483 | delete editor._.menuItems[ i ]; |
| 484 | delete editor._.commands[ i ]; |
| 485 | } |
| 486 | for ( i in mainSuggestions ) |
| 487 | { |
| 488 | delete editor._.menuItems[ i ]; |
| 489 | delete editor._.commands[ i ]; |
| 490 | } |
| 491 | moreSuggestions = {}; // Reset items. |
| 492 | mainSuggestions = {}; |
377 | | // If the "contextmenu" plugin is loaded, register the listeners. |
378 | | if ( editor.contextMenu && editor.addMenuItems ) |
379 | | { |
380 | | editor.contextMenu.addListener( function( element ) |
381 | | { |
382 | | if ( !( plugin.isScaytEnabled( editor ) && element ) ) |
383 | | return null; |
| 494 | var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on"; |
| 495 | var moreSuggestionsUnableAdded = false; |
| 496 | var maxSuggestions = ( editor.config.scayt_maxSuggestions <= 0) |
| 497 | ? items_suggestion.length |
| 498 | : editor.config.scayt_maxSuggestions; |
| 499 | var contextCommands = editor.config.scayt_contextCommands || "all"; |
| 500 | contextCommands = contextCommands.split("|"); |
385 | | var scayt_control = plugin.getScayt( editor ), |
386 | | word = scayt_control.getWord( element.$ ); |
| 502 | for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) |
| 503 | { |
| 504 | var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' ); |
| 505 | var exec = ( function( el, s ) |
| 506 | { |
| 507 | return { |
| 508 | exec: function() |
| 509 | { |
| 510 | scayt_control.replace(el, s); |
| 511 | } |
| 512 | }; |
| 513 | })( element.$, items_suggestion[i] ); |
388 | | if ( !word ) |
389 | | return null; |
| 515 | if ( i < maxSuggestions ) |
| 516 | { |
| 517 | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], |
| 518 | commandName, exec, 'scayt_suggest', i + 1 ); |
| 519 | _r[ commandName ] = CKEDITOR.TRISTATE_OFF; |
| 520 | mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; |
| 521 | } |
| 522 | else if ( moreSuggestionsUnable == "on" ) |
| 523 | { |
391 | | var sLang = scayt_control.getLang(), |
392 | | _r = {}, |
393 | | items_suggestion = window.scayt.getSuggestion( word, sLang ); |
394 | | if (!items_suggestion || !items_suggestion.length ) |
395 | | return null; |
396 | | // Remove unused commands and menuitems |
397 | | for ( i in moreSuggestions ) |
398 | | { |
399 | | delete editor._.menuItems[ i ]; |
400 | | delete editor._.commands[ i ]; |
401 | | } |
402 | | for ( i in mainSuggestions ) |
403 | | { |
404 | | delete editor._.menuItems[ i ]; |
405 | | delete editor._.commands[ i ]; |
406 | | } |
407 | | moreSuggestions = {}; // Reset items. |
408 | | mainSuggestions = {}; |
| 525 | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], |
| 526 | commandName, exec, 'scayt_moresuggest', i + 1 ); |
| 527 | moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; |
| 528 | moreSuggestionsUnableAdded = true; |
425 | | if ( i < editor.config.scayt_maxSuggestions ) |
426 | | { |
427 | | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], |
428 | | commandName, exec, 'scayt_suggest', i + 1 ); |
429 | | _r[ commandName ] = CKEDITOR.TRISTATE_OFF; |
430 | | mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; |
431 | | } |
432 | | else |
433 | | { |
434 | | addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], |
435 | | commandName, exec, 'scayt_moresuggest', i + 1 ); |
436 | | moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; |
437 | | moreSuggestionsUnable = true; |
438 | | } |
439 | | } |
440 | | if ( moreSuggestionsUnable ) |
441 | | // Rgister the More suggestions group; |
442 | | editor.addMenuItem( 'scayt_moresuggest', |
443 | | { |
444 | | label : editor.lang.scayt.moreSuggestions, |
445 | | group : 'scayt_moresuggest', |
446 | | order : 10, |
447 | | getItems : function() |
448 | | { |
449 | | return moreSuggestions; |
450 | | } |
451 | | }); |
454 | | var ignore_command = |
455 | | { |
456 | | exec: function() |
457 | | { |
458 | | scayt_control.ignore( element.$ ); |
459 | | } |
460 | | }; |
461 | | var ignore_all_command = |
462 | | { |
463 | | exec: function() |
464 | | { |
465 | | scayt_control.ignoreAll( element.$ ); |
466 | | } |
467 | | }; |
468 | | var addword_command = |
469 | | { |
470 | | exec: function() |
471 | | { |
472 | | window.scayt.addWordToUserDictionary( element.$ ); |
473 | | } |
474 | | }; |
| 536 | if ( moreSuggestionsUnableAdded ){ |
| 537 | // Rgister the More suggestions group; |
| 538 | editor.addMenuItem( 'scayt_moresuggest', |
| 539 | { |
| 540 | label : editor.lang.scayt.moreSuggestions, |
| 541 | group : 'scayt_moresuggest', |
| 542 | order : 10, |
| 543 | getItems : function() |
| 544 | { |
| 545 | return moreSuggestions; |
| 546 | } |
| 547 | }); |
| 548 | mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF; |
| 549 | |
| 550 | } |
| 551 | |
476 | | addButtonCommand( editor, 'ignore', editor.lang.scayt.ignore, |
477 | | 'scayt_ignore', ignore_command, 'scayt_control', 1); |
478 | | addButtonCommand( editor, 'ignore_all', editor.lang.scayt.ignoreAll, |
479 | | 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2); |
480 | | addButtonCommand( editor, 'add_word', editor.lang.scayt.addWord, |
481 | | 'scayt_add_word', addword_command, 'scayt_control', 3); |
| 553 | |
| 554 | if ( in_array( "all",contextCommands ) || in_array("ignore",contextCommands) ) |
| 555 | { |
| 556 | var ignore_command = { |
| 557 | exec: function(){ |
| 558 | scayt_control.ignore(element.$); |
| 559 | } |
| 560 | }; |
| 561 | addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1); |
| 562 | mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF; |
| 563 | } |
| 564 | |
| 565 | if ( in_array( "all",contextCommands ) || in_array("ignoreall",contextCommands) ) |
| 566 | { |
| 567 | var ignore_all_command = { |
| 568 | exec: function(){ |
| 569 | scayt_control.ignoreAll(element.$); |
| 570 | } |
| 571 | }; |
| 572 | addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2); |
| 573 | mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF; |
| 574 | } |
| 575 | |
| 576 | if ( in_array( "all",contextCommands ) || in_array("add",contextCommands) ) |
| 577 | { |
| 578 | var addword_command = { |
| 579 | exec: function(){ |
| 580 | window.scayt.addWordToUserDictionary(element.$); |
| 581 | } |
| 582 | }; |
| 583 | addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3); |
| 584 | mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF; |
| 585 | } |