Ticket #5145: 5145_5.patch
File 5145_5.patch, 10.6 KB (added by , 13 years ago) |
---|
-
_source/plugins/scayt/plugin.js
1 /*1 /* 2 2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. 3 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 4 */ … … 10 10 11 11 (function() 12 12 { 13 13 14 var commandName = 'scaytcheck', 14 15 openPage = '', 15 scayt_paused = null; 16 scayt_paused = null, 17 scayt_control_id = null; 16 18 17 19 // Checks if a value exists in an array 18 20 function in_array(needle, haystack) … … 44 46 oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds; 45 47 oParams.userDictionaryName = editor.config.scayt_userDictionaryName; 46 48 oParams.sLang = editor.config.scayt_sLang || "en_US"; 47 48 if ( CKEDITOR._ scaytParams )49 50 if ( CKEDITOR._.scaytParams ) 49 51 { 50 for ( var k in CKEDITOR._ scaytParams )52 for ( var k in CKEDITOR._.scaytParams ) 51 53 { 52 oParams[ k ] = CKEDITOR._ scaytParams[ k ];54 oParams[ k ] = CKEDITOR._.scaytParams[ k ]; 53 55 } 54 56 } 55 57 58 if ( scayt_control_id ) 59 oParams.id = scayt_control_id; 60 56 61 var scayt_control = new window.scayt( oParams ); 57 62 58 63 // Copy config. … … 103 108 104 109 editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution. 105 110 { 111 if ( ev.data.name == 'removeFormat' && editor.mode == 'wysiwyg' ) 112 { 113 114 if (plugin.isScaytEnabled(editor)) 115 window.setTimeout(function(){plugin.getScayt(editor).refresh()},10); 116 117 } 106 118 if ( (ev.data.name == 'source' || ev.data.name == 'newpage') && editor.mode == 'wysiwyg' ) 107 119 { 108 120 var scayt_instanse = plugin.getScayt( editor ); 109 121 if ( scayt_instanse ) 110 122 { 111 123 scayt_paused = scayt_instanse.paused = !scayt_instanse.disabled; 112 scayt_instanse.destroy(); 113 delete plugin.instances[ editor.name ]; 124 scayt_control_id = scayt_instanse.id; 125 scayt_instanse.destroy(true); 126 delete plugin.instances[editor.name]; 127 114 128 } 115 129 } 116 130 }); … … 118 132 119 133 editor.on( 'destroy', function() 120 134 { 121 plugin.getScayt( editor ).destroy(); 135 scayt_control_id = scayt_instanse.id; 136 plugin.getScayt( editor ).destroy(true); 122 137 }); 123 138 // Listen to data manipulation to reflect scayt markup. 124 139 editor.on( 'afterSetData', function() 125 140 { 126 if ( plugin.isScaytEnabled( editor ) ) 127 plugin.getScayt( editor ).refresh(); 141 if (plugin.isScaytEnabled(editor)) { 142 window.setTimeout(function(){plugin.getScayt(editor).refresh()},10); 143 144 if( !editor.checkDirty() ) 145 setTimeout( function(){ editor.resetDirty(); } ); 146 147 } 128 148 }); 129 149 130 150 // Reload spell-checking for current word after insertion completed. … … 139 159 editor.getSelection().unlock( true ); 140 160 141 161 // Swallow any SCAYT engine errors. 142 try{ 143 scayt_instance.refresh(); 144 }catch( er ) 145 {} 162 window.setTimeout(function(){scayt_instance.refresh()},10); 163 146 164 } 147 165 }, this, null, 50 ); 148 166 … … 158 176 editor.getSelection().unlock( true ); 159 177 160 178 // Swallow any SCAYT engine errors. 161 try{ 162 scayt_instance.refresh(); 163 }catch( er ) 164 {} 179 180 window.setTimeout(function(){scayt_instance.refresh()},10); 181 165 182 } 166 183 }, this, null, 50 ); 167 184 … … 218 235 }, 219 236 loadEngine : function( editor ) 220 237 { 238 if (CKEDITOR.env.opera) 239 return; 221 240 if ( this.engineLoaded === true ) 222 241 return onEngineLoad.apply( editor ); // Add new instance. 223 242 else if ( this.engineLoaded == -1 ) // We are waiting. … … 238 257 var protocol = document.location.protocol; 239 258 // Default to 'http' for unknown. 240 259 protocol = protocol.search( /https?:/) != -1? protocol : 'http:'; 241 var baseUrl = "svc.spellchecker.net/spellcheck3 /lf/scayt/scayt21.js";260 var baseUrl = "svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js"; 242 261 243 262 var scaytUrl = editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl ); 244 263 var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + "/"; … … 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( ) 461 480 { 462 if ( !( plugin.isScaytEnabled( editor ) && element ) ) 481 482 if (!plugin.isScaytEnabled(editor)) 483 { 463 484 return null; 485 } 486 var scayt_control = plugin.getScayt( editor ); 487 var node = scayt_control.getScaytNode(); 488 489 if (!node) 490 { 491 return null; 492 } 493 word = scayt_control.getWord( node ); 464 494 465 var scayt_control = plugin.getScayt( editor ), 466 word = scayt_control.getWord( element.$ ); 467 468 if ( !word ) 495 if (!word) 496 { 469 497 return null; 470 498 } 471 499 var sLang = scayt_control.getLang(), 472 500 _r = {}, 473 501 items_suggestion = window.scayt.getSuggestion( word, sLang ); 474 if (!items_suggestion || !items_suggestion.length ) 502 if (!items_suggestion || !items_suggestion.length) 503 { 475 504 return null; 505 } 476 506 // Remove unused commands and menuitems 477 507 for ( i in moreSuggestions ) 478 508 { … … 508 538 scayt_control.replace(el, s); 509 539 } 510 540 }; 511 })( element.$, items_suggestion[i] );541 })( node, items_suggestion[i] ); 512 542 513 543 if ( i < maxSuggestions ) 514 544 { … … 546 576 { 547 577 var ignore_command = { 548 578 exec: function(){ 549 scayt_control.ignore( element.$);579 scayt_control.ignore(node); 550 580 } 551 581 }; 552 582 addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1); … … 557 587 { 558 588 var ignore_all_command = { 559 589 exec: function(){ 560 scayt_control.ignoreAll( element.$);590 scayt_control.ignoreAll(node); 561 591 } 562 592 }; 563 593 addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2); … … 568 598 { 569 599 var addword_command = { 570 600 exec: function(){ 571 window.scayt.addWordToUserDictionary( element.$);601 window.scayt.addWordToUserDictionary(node); 572 602 } 573 603 }; 574 604 addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3); … … 579 609 scayt_control.fireOnContextMenu( editor ); 580 610 581 611 return mainSuggestions; 612 582 613 }); 583 614 } 584 615 … … 598 629 }); 599 630 })(); 600 631 601 // TODO: Documentation 602 // CKEDITOR.config.scayt_maxSuggestions 603 // CKEDITOR.config.scayt_autoStartup 632 /** 633 * turn on/off SCAYT autostartup 634 * possible values: false || true 635 * @type boolean 636 * @default false 637 * @example 638 * // SCAYT turn on after editor is loaded 639 * CKEDITOR.config.scayt_autoStartup = true; 640 */ 641 CKEDITOR.config.scayt_autoStartup = CKEDITOR.config.scayt_autoStartup || false; 642 643 /** 644 * allows to set main context menu suggestions count 645 * possiblevalues 646 * 0 - all suggestions should be shown in context menu 647 * >0 (1, 2, etc.)- number of suggestions should be shown in context menu - others should 648 * be shown in "More Suggestions" sub menu 649 * <0 (-1, -2, etc.)- no suggestions should be shown in context menu - all should be shown 650 * in "More Suggestions" sub menu and it (sub-menu) should have caption "Suggestions" 651 * @type int 652 * @default 5 653 * @example 654 * // will show 3 suggestions in right mouse button menu 655 * CKEDITOR.config.scayt_maxSuggestions = 3; 656 */ 657 CKEDITOR.config.scayt_maxSuggestions = CKEDITOR.config.scayt_maxSuggestions || 5; 658 659 660 /** 661 * allows to set encrypted customer id 662 * required to migrate from trial paid hosted service 663 * @type string 664 * 665 * @example 666 * // will load SCAYT from your custom url 667 * CKEDITOR.config.scayt_customerid = "your-encrypted-customer-id"; 668 */ 669 //CKEDITOR.config.scayt_customerid = ""; 670 671 /** 672 * enable or disable "More Suggestions" sub menu in context menu 673 * possible values: "on" or "off" 674 * @type string 675 * @default "on" 676 * @example 677 * // More Suggestion menu will enable 678 * CKEDITOR.config.scayt_moreSuggestions = "on"; 679 */ 680 CKEDITOR.config.scayt_moreSuggestions = "on"; 681 682 683 /** 684 * allows to customize SCAYT context menu commands (Add word, Ignore , Ignore all) 685 * string with "|" delimiter and combination of words "add", "ignore", "ignoreall", e.g. "add|ignoreall" 686 * posible values: 687 * "off" - disable all buttons 688 * "all" - enable all buttons 689 * "ignore" - "ingnore" button 690 * "ignoreall" - "ignore all" button 691 * "add" - "add word" button 692 * 693 * @type string 694 * @default "all" 695 * @example 696 * // show 2 SCAYT buttons in context menu - Add Word and Ignore All 697 * CKEDITOR.config.scayt_contextCommands = "add|ignoreall"; 698 */ 699 CKEDITOR.config.scayt_contextCommands = "all"; 700 701 /** 702 * set up spellchecking language for SCAYT 703 * possible values "en_US", "en_GB", "en_AU"... - 704 * @type string 705 * @default "on" 706 * @example 707 * // set up German language as prior for spellchecking 708 * CKEDITOR.config.scayt_sLang = "de_DE"; 709 */ 710 CKEDITOR.config.scayt_sLang = "en_US"; 711 712 /** 713 * allows to cutomise SCAYT options tags 714 * possible values: string with "," delimiter and combination of "0" or "1" 715 * all 3 values are required in order of tabs following in UI: 716 * options,languages,dictionary 717 * @type string 718 * @default "1,1,1" 719 * @example 720 * // Languages tab will ont rendered 721 * CKEDITOR.config.scayt_uiTabs = "1,0,1"; 722 */ 723 CKEDITOR.config.scayt_uiTabs = "1,1,1"; 724 725 /** 726 * allows to link up custom dictionaries (only for licensed users) 727 * possible values: string with "," delimiter and combination of dictionaries ids 728 * @type string 729 * @default "" 730 * @example 731 * // set up German language as prior for spellchecking 732 * CKEDITOR.config.scayt_customDictionaryIds ="3021,3456,3478" 733 */ 734 CKEDITOR.config.scayt_customDictionaryIds = ""; 735 736 /** 737 * allows to turn on your own dictionary 738 * possible values: alpha numeric name of dictionary 739 * @type string 740 * @default "" 741 * @example 742 * // set up German language as prior for spellchecking 743 * CKEDITOR.config.scayt_userDictionaryName = "MyDictionary" 744 */ 745 CKEDITOR.config.scayt_userDictionaryName = "";