Ticket #5145: 5145_4.patch
File 5145_4.patch, 21.5 KB (added by , 13 years ago) |
---|
-
_source/plugins/scayt/plugin.js
10 10 11 11 (function() 12 12 { 13 var commandName = 'scaytcheck',13 var commandName = 'scaytcheck', 14 14 openPage = '', 15 15 scayt_paused = null; 16 16 … … 37 37 { 38 38 // Initialise Scayt instance. 39 39 var oParams = {}; 40 oParams.srcNodeRef = editor.document.getWindow().$.frameElement; // Get the iframe. 40 // Get the iframe. 41 oParams.srcNodeRef = editor.document.getWindow().$.frameElement; 41 42 // syntax : AppName.AppVersion@AppRevision 42 43 oParams.assocApp = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision; 43 44 oParams.customerid = editor.config.scayt_customerid || "1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2"; 44 oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds ;45 oParams.userDictionaryName = editor.config.scayt_userDictionaryName ;45 oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds || ''; 46 oParams.userDictionaryName = editor.config.scayt_userDictionaryName || ''; 46 47 oParams.sLang = editor.config.scayt_sLang || "en_US"; 47 48 48 if ( CKEDITOR._ scaytParams )49 if ( CKEDITOR._.scaytParams ) 49 50 { 50 for ( var k in CKEDITOR._ scaytParams )51 for ( var k in CKEDITOR._.scaytParams ) 51 52 { 52 oParams[ k ] = CKEDITOR._ scaytParams[ k ];53 oParams[ k ] = CKEDITOR._.scaytParams[ k ]; 53 54 } 54 55 } 55 56 … … 72 73 var fTabs = []; 73 74 74 75 for (var i = 0,l=4; i<l; i++) 76 { 75 77 fTabs.push( uiTabs[i] && plugin.uiTabs[i] ); 76 78 } 77 79 plugin.uiTabs = fTabs; 80 78 81 try { 79 82 scayt_control.setDisabled( scayt_paused === false ); 80 83 } catch (e) {} 81 84 82 85 editor.fire( 'showScaytState' ); 83 86 }; 84 87 85 88 editor.on( 'contentDom', createInstance ); 86 89 editor.on( 'contentDomUnload', function() 90 { 91 // Remove scripts. 92 var scripts = CKEDITOR.document.getElementsByTag( 'script' ), 93 scaytIdRegex = /^dojoIoScript(\d+)$/i, 94 scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i; 95 96 for ( var i=0; i < scripts.count(); i++ ) 87 97 { 88 // Remove scripts. 89 var scripts = CKEDITOR.document.getElementsByTag( 'script' ), 90 scaytIdRegex = /^dojoIoScript(\d+)$/i, 91 scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i; 98 var script = scripts.getItem( i ), 99 id = script.getId(), 100 src = script.getAttribute( 'src' ); 92 101 93 for ( var i=0; i < scripts.count(); i++ ) 94 { 95 var script = scripts.getItem( i ), 96 id = script.getId(), 97 src = script.getAttribute( 'src' ); 102 if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex )) 103 script.remove(); 104 } 105 }); 98 106 99 if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))100 script.remove();101 }102 });103 104 107 editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution. 105 108 { 109 if ( ev.data.name == 'removeFormat' && editor.mode == 'wysiwyg' ) 110 { 111 112 if ( plugin.isScaytEnabled( editor ) ) 113 window.setTimeout(function(){plugin.getScayt(editor).refresh()},10); 114 115 } 106 116 if ( (ev.data.name == 'source' || ev.data.name == 'newpage') && editor.mode == 'wysiwyg' ) 107 117 { 108 118 var scayt_instanse = plugin.getScayt( editor ); 109 119 if ( scayt_instanse ) 110 120 { 111 121 scayt_paused = scayt_instanse.paused = !scayt_instanse.disabled; 112 scayt_instanse.destroy( );113 delete plugin.instances[ editor.name];122 scayt_instanse.destroy( true ); 123 delete plugin.instances[editor.name]; 114 124 } 115 125 } 116 126 }); 117 127 118 128 119 129 editor.on( 'destroy', function() 120 121 plugin.getScayt( editor ).destroy();122 130 { 131 plugin.getScayt( editor ).destroy( true ); 132 }); 123 133 // Listen to data manipulation to reflect scayt markup. 124 134 editor.on( 'afterSetData', function() 135 { 136 if ( plugin.isScaytEnabled( editor ) ) 125 137 { 126 if ( plugin.isScaytEnabled( editor ) ) 127 plugin.getScayt( editor ).refresh(); 128 }); 138 plugin.getScayt( editor ).refresh(); 129 139 140 if( !editor.checkDirty() ) 141 setTimeout( function(){ editor.resetDirty(); } ); 142 } 143 }); 144 130 145 // Reload spell-checking for current word after insertion completed. 131 146 editor.on( 'insertElement', function() 147 { 148 var scayt_instance = plugin.getScayt( editor ); 149 if ( plugin.isScaytEnabled( editor ) ) 132 150 { 133 var scayt_instance = plugin.getScayt( editor ); 134 if ( plugin.isScaytEnabled( editor ) ) 135 { 136 // Unlock the selection before reload, SCAYT will take 137 // care selection update. 138 if ( CKEDITOR.env.ie ) 139 editor.getSelection().unlock( true ); 151 // Unlock the selection before reload, SCAYT will take 152 // care selection update. 153 if ( CKEDITOR.env.ie ) 154 editor.getSelection().unlock( true ); 140 155 141 142 143 144 145 146 147 156 // Swallow any SCAYT engine errors. 157 try{ 158 scayt_instance.refresh(); 159 }catch( er ) 160 {} 161 } 162 }, this, null, 50 ); 148 163 149 164 editor.on( 'insertHtml', function() 165 { 166 167 var scayt_instance = plugin.getScayt( editor ); 168 if ( plugin.isScaytEnabled( editor ) ) 150 169 { 170 // Unlock the selection before reload, SCAYT will take 171 // care selection update. 172 if ( CKEDITOR.env.ie ) 173 editor.getSelection().unlock( true ); 151 174 152 var scayt_instance = plugin.getScayt( editor );153 if ( plugin.isScaytEnabled( editor ) )154 {155 // Unlock the selection before reload, SCAYT will take156 // care selection update.157 if ( CKEDITOR.env.ie )158 editor.getSelection().unlock( true);175 // Swallow any SCAYT engine errors. 176 try{ 177 scayt_instance.refresh(); 178 }catch( er ) 179 {} 180 } 181 }, this, null, 50 ); 159 182 160 // Swallow any SCAYT engine errors.161 try{162 scayt_instance.refresh();163 }catch( er )164 {}165 }166 }, this, null, 50 );167 168 183 editor.on( 'scaytDialog', function( ev ) // Communication with dialog. 169 170 171 172 173 174 184 { 185 ev.data.djConfig = window.djConfig; 186 ev.data.scayt_control = plugin.getScayt( editor ); 187 ev.data.tab = openPage; 188 ev.data.scayt = window.scayt; 189 }); 175 190 176 191 var dataProcessor = editor.dataProcessor, 177 192 htmlFilter = dataProcessor && dataProcessor.htmlFilter; … … 218 233 }, 219 234 loadEngine : function( editor ) 220 235 { 236 if ( CKEDITOR.env.opera ) 237 return; 221 238 if ( this.engineLoaded === true ) 222 239 return onEngineLoad.apply( editor ); // Add new instance. 223 240 else if ( this.engineLoaded == -1 ) // We are waiting. … … 230 247 }, 231 248 this, 232 249 null, 233 0 ); // First to run. 250 0 251 ); // First to run. 234 252 235 253 this.engineLoaded = -1; // Loading in progress. 236 254 … … 238 256 var protocol = document.location.protocol; 239 257 // Default to 'http' for unknown. 240 258 protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; 241 var baseUrl = "svc.spellchecker.net/spellcheck3 /lf/scayt/scayt21.js";259 var baseUrl = "svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js"; 242 260 243 261 var scaytUrl = editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl ); 244 262 var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + "/"; … … 355 373 // string tp array convert 356 374 confuiTabs = confuiTabs.split(","); 357 375 // check array length ! allwaays must be 3 filled with 1 or 0 358 for (var i=0,l=3; i<l; i++){ 376 for (var i=0,l=3; i<l; i++) 377 { 359 378 var flag = parseInt(confuiTabs[i] || "1" ,10); 360 379 uiTabs.push( flag ); 361 380 } … … 367 386 368 387 // allways added 369 388 uiMuneItems.scaytToggle = 370 371 372 373 374 389 { 390 label : editor.lang.scayt.enable, 391 command : commandName, 392 group : menuGroup 393 }; 375 394 376 395 if (uiTabs[0] == 1) 377 396 uiMuneItems.scaytOptions = … … 457 476 // If the "contextmenu" plugin is loaded, register the listeners. 458 477 if ( editor.contextMenu && editor.addMenuItems ) 459 478 { 460 editor.contextMenu.addListener( function( element ) 479 editor.contextMenu.addListener( function() 480 { 481 482 if ( !plugin.isScaytEnabled( editor ) ) 483 { 484 return null; 485 } 486 var scayt_control = plugin.getScayt( editor ); 487 var node = scayt_control.getScaytNode(); 488 489 if ( !node ) 490 return null; 491 492 word = scayt_control.getWord( node ); 493 494 if ( !word ) 461 495 { 462 if ( !( plugin.isScaytEnabled( editor ) && element ) ) 463 return null; 496 return null; 497 } 498 var sLang = scayt_control.getLang(), 499 _r = {}, 500 items_suggestion = window.scayt.getSuggestion( word, sLang ); 501 if (!items_suggestion || !items_suggestion.length) 502 { 503 return null; 504 } 505 // Remove unused commands and menuitems 506 for ( i in moreSuggestions ) 507 { 508 delete editor._.menuItems[ i ]; 509 delete editor._.commands[ i ]; 510 } 511 for ( i in mainSuggestions ) 512 { 513 delete editor._.menuItems[ i ]; 514 delete editor._.commands[ i ]; 515 } 516 moreSuggestions = {}; // Reset items. 517 mainSuggestions = {}; 464 518 465 var scayt_control = plugin.getScayt( editor ),466 word = scayt_control.getWord( element.$ );519 var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on"; 520 var moreSuggestionsUnableAdded = false; 467 521 468 if ( !word ) 469 return null; 522 var maxSuggestions = editor.config.scayt_maxSuggestions; 523 ( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 ); 524 !maxSuggestions && ( maxSuggestions = items_suggestion.length ); 470 525 471 var sLang = scayt_control.getLang(), 472 _r = {}, 473 items_suggestion = window.scayt.getSuggestion( word, sLang ); 474 if (!items_suggestion || !items_suggestion.length ) 475 return null; 476 // Remove unused commands and menuitems 477 for ( i in moreSuggestions ) 526 var contextCommands = editor.config.scayt_contextCommands || "all"; 527 contextCommands = contextCommands.split("|"); 528 529 for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) 530 { 531 var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' ); 532 var exec = ( function( el, s ) 533 { 534 return { 535 exec: function() 536 { 537 scayt_control.replace(el, s); 538 } 539 }; 540 })( node, items_suggestion[i] ); 541 542 if ( i < maxSuggestions ) 478 543 { 479 delete editor._.menuItems[ i ]; 480 delete editor._.commands[ i ]; 544 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], 545 commandName, exec, 'scayt_suggest', i + 1 ); 546 _r[ commandName ] = CKEDITOR.TRISTATE_OFF; 547 mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; 481 548 } 482 for ( i in mainSuggestions)549 else if ( moreSuggestionsUnable == "on" ) 483 550 { 484 delete editor._.menuItems[ i ]; 485 delete editor._.commands[ i ]; 551 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], 552 commandName, exec, 'scayt_moresuggest', i + 1 ); 553 moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; 554 moreSuggestionsUnableAdded = true; 486 555 } 487 moreSuggestions = {}; // Reset items. 488 mainSuggestions = {}; 556 } 489 557 490 var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on"; 491 var moreSuggestionsUnableAdded = false; 492 493 var maxSuggestions = editor.config.scayt_maxSuggestions; 494 ( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 ); 495 !maxSuggestions && ( maxSuggestions = items_suggestion.length ); 496 497 var contextCommands = editor.config.scayt_contextCommands || "all"; 498 contextCommands = contextCommands.split("|"); 499 500 for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) 558 if ( moreSuggestionsUnableAdded ){ 559 // Rgister the More suggestions group; 560 editor.addMenuItem( 'scayt_moresuggest', 501 561 { 502 var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' ); 503 var exec = ( function( el, s ) 504 { 505 return { 506 exec: function() 507 { 508 scayt_control.replace(el, s); 509 } 510 }; 511 })( element.$, items_suggestion[i] ); 512 513 if ( i < maxSuggestions ) 562 label : editor.lang.scayt.moreSuggestions, 563 group : 'scayt_moresuggest', 564 order : 10, 565 getItems : function() 514 566 { 515 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], 516 commandName, exec, 'scayt_suggest', i + 1 ); 517 _r[ commandName ] = CKEDITOR.TRISTATE_OFF; 518 mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; 567 return moreSuggestions; 519 568 } 520 else if ( moreSuggestionsUnable == "on" ) 521 { 522 addButtonCommand( editor, 'button_' + commandName, items_suggestion[i], 523 commandName, exec, 'scayt_moresuggest', i + 1 ); 524 moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF; 525 moreSuggestionsUnableAdded = true; 526 } 527 } 569 }); 570 mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF; 528 571 529 if ( moreSuggestionsUnableAdded ){ 530 // Rgister the More suggestions group; 531 editor.addMenuItem( 'scayt_moresuggest', 532 { 533 label : editor.lang.scayt.moreSuggestions, 534 group : 'scayt_moresuggest', 535 order : 10, 536 getItems : function() 537 { 538 return moreSuggestions; 539 } 540 }); 541 mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF; 572 } 542 573 543 } 574 if ( in_array( "all",contextCommands ) || in_array("ignore",contextCommands) ) 575 { 576 var ignore_command = { 577 exec: function(){ 578 scayt_control.ignore( node ); 579 } 580 }; 581 addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1); 582 mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF; 583 } 544 584 545 if ( in_array( "all",contextCommands ) || in_array("ignore",contextCommands) )546 547 var ignore_command = {548 549 scayt_control.ignore(element.$);550 551 552 addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);553 mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF;554 585 if ( in_array( "all",contextCommands ) || in_array("ignoreall",contextCommands) ) 586 { 587 var ignore_all_command = { 588 exec: function(){ 589 scayt_control.ignoreAll( node ); 590 } 591 }; 592 addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2); 593 mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF; 594 } 555 595 556 if ( in_array( "all",contextCommands ) || in_array("ignoreall",contextCommands) )557 558 var ignore_all_command = {559 560 scayt_control.ignoreAll(element.$);561 562 563 addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);564 mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;565 596 if ( in_array( "all",contextCommands ) || in_array("add",contextCommands) ) 597 { 598 var addword_command = { 599 exec: function(){ 600 window.scayt.addWordToUserDictionary( node ); 601 } 602 }; 603 addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3); 604 mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF; 605 } 566 606 567 if ( in_array( "all",contextCommands ) || in_array("add",contextCommands) ) 568 { 569 var addword_command = { 570 exec: function(){ 571 window.scayt.addWordToUserDictionary(element.$); 572 } 573 }; 574 addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3); 575 mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF; 576 } 607 if ( scayt_control.fireOnContextMenu ) 608 scayt_control.fireOnContextMenu( editor ); 577 609 578 if ( scayt_control.fireOnContextMenu ) 579 scayt_control.fireOnContextMenu( editor ); 580 581 return mainSuggestions; 582 }); 610 return mainSuggestions; 611 }); 583 612 } 584 613 585 614 // Start plugin … … 591 620 command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF ); 592 621 }; 593 622 editor.on( 'showScaytState', showInitialState ); 594 595 623 plugin.loadEngine( editor ); 596 624 } 597 625 } 598 626 }); 599 627 })(); 600 628 601 // TODO: Documentation 602 // CKEDITOR.config.scayt_maxSuggestions 603 // CKEDITOR.config.scayt_autoStartup 629 /** 630 * If enabled (true), turns on SCAYT automatically after loading the editor. 631 * @name CKEDITOR.config.scayt_autoStartup 632 * @type Boolean 633 * @default false 634 * @example 635 * config.scayt_autoStartup = true; 636 */ 637 638 /** 639 * Defines the number of SCAYT suggestions to show in the main context menu. 640 * The possible values are: 641 * <ul> 642 * <li>0 (zero): All suggestions are displayed in the main context menu.</li> 643 * <li>Positive number: The maximum number of suggestions to shown in context 644 * menu. Other entries will be shown in "More Suggestions" sub-menu.</li> 645 * <li>Negative number: No suggestions are shown in the main context menu. All 646 * entries will be listed in the "Suggestions" sub-menu.</li> 647 * </ul> 648 * @name CKEDITOR.config.scayt_maxSuggestions 649 * @type Number 650 * @default 5 651 * @example 652 * // Display only three suggestions in the main context menu. 653 * config.scayt_maxSuggestions = 3; 654 * @example 655 * // Do not show the suggestions directly. 656 * config.scayt_maxSuggestions = -1; 657 */ 658 659 /** 660 * Sets the customer ID for SCAYT. Required for migration from free version 661 * with banner to paid version. 662 * @name CKEDITOR.config.scayt_customerid 663 * @type String 664 * @default '' 665 * @example 666 * // Load SCAYT using my customer ID. 667 * config.scayt_customerid = 'your-encrypted-customer-id'; 668 */ 669 670 /** 671 * Enables/disables the "More Suggestions" sub-menu in the context menu. 672 * The possible values are "on" or "off". 673 * @name CKEDITOR.config.scayt_moreSuggestions 674 * @type String 675 * @default 'on' 676 * @example 677 * // Disables the "More Suggestions" sub-menu. 678 * config.scayt_moreSuggestions = 'off'; 679 */ 680 681 /** 682 * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore" 683 * and "Ignore All"). It must be a string with one or more of the following 684 * words separated by a pipe ("|"): 685 * <ul> 686 * <li>"off": disables all options.</li> 687 * <li>"all": enables all options.</li> 688 * <li>"ignore": enables the "Ignore" option.</li> 689 * <li>"ignoreall": enables the "Ignore All" option.</li> 690 * <li>"add": enables the "Add Word" option.</li> 691 * </ul> 692 * @name CKEDITOR.config.scayt_contextCommands 693 * @type String 694 * @default 'all' 695 * @example 696 * // Show only "Add Word" and "Ignore All" in the context menu. 697 * config.scayt_contextCommands = 'add|ignoreall'; 698 */ 699 700 /** 701 * Sets the default spellchecking language for SCAYT. 702 * @name CKEDITOR.config.scayt_sLang 703 * @type String 704 * @default 'en_US' 705 * @example 706 * // Sets SCAYT to German. 707 * config.scayt_sLang = 'de_DE'; 708 */ 709 710 /** 711 * Sets the visibility of the SCAYT tabs in the settings dialog and toolbar 712 * button. The value must contain a "1" (enabled) or "0" (disabled) number for 713 * each of the following entries, in this precise order, separated by a 714 * comma (","): "Options", "Languages" and "Dictionary". 715 * @name CKEDITOR.config.scayt_uiTabs 716 * @type String 717 * @default '1,1,1' 718 * @example 719 * // Hide the "Languages" tab. 720 * config.scayt_uiTabs = '1,0,1'; 721 */ 722 723 724 /** 725 * Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application. 726 * Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l . 727 * @name CKEDITOR.config.scayt_srcUrl 728 * @type String 729 * @default '' 730 * @example 731 * CKEDITOR.config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js"; 732 */ 733 734 /** 735 * Links SCAYT to custom dictionaries. It's a string containing dictionary ids 736 * separared by commas (","). Available only for licensed version. 737 * Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support . 738 * @name CKEDITOR.config.scayt_customDictionaryIds 739 * @type String 740 * @default '' 741 * @example 742 * config.scayt_customDictionaryIds = '3021,3456,3478"'; 743 */ 744 745 /** 746 * Makes it possible to activate a custom dictionary on SCAYT. The user 747 * dictionary name must be used. Available only for licensed version. 748 * @name CKEDITOR.config.scayt_userDictionaryName 749 * @type String 750 * @default '' 751 * @example 752 * config.scayt_userDictionaryName = 'MyDictionary'; 753 */