Ticket #5145: 5145_8.patch

File 5145_8.patch, 11.4 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/scayt/plugin.js

     
    1212{
    1313        var commandName         = 'scaytcheck',
    1414                openPage                = '',
    15                 scayt_paused    = null;
     15                scayt_paused    = null,
     16                scayt_control_id = null;
    1617
    1718        // Checks if a value exists in an array
    1819        function in_array(needle, haystack)
     
    3738                {
    3839                        // Initialise Scayt instance.
    3940                        var oParams = {};
    40                         oParams.srcNodeRef = editor.document.getWindow().$.frameElement;                // Get the iframe.
     41                        // Get the iframe.
     42                        oParams.srcNodeRef = editor.document.getWindow().$.frameElement;
    4143                        // syntax : AppName.AppVersion@AppRevision
    4244                        oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;
    4345                        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;
     46                        oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds || '';
     47                        oParams.userDictionaryName = editor.config.scayt_userDictionaryName || '';
    4648                        oParams.sLang = editor.config.scayt_sLang || "en_US";
    4749                       
    4850
     
    5456                                        oParams[ k ] = scayt_custom_params[ k ];
    5557                                }
    5658                        }
    57 
     59                       
     60                        if ( scayt_control_id )
     61                                oParams.id = scayt_control_id;
     62                       
    5863                        var scayt_control = new window.scayt( oParams );
    5964
    6065                        // Copy config.
     
    7479                        var fTabs  = [];
    7580
    7681                        for (var i = 0,l=4; i<l; i++)
    77                                 fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
     82                            fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
    7883
    7984                        plugin.uiTabs = fTabs;
    8085                        try {
     
    111116                                        if ( scayt_instanse )
    112117                                        {
    113118                                                scayt_paused = scayt_instanse.paused = !scayt_instanse.disabled;
    114                                                 scayt_instanse.destroy();
     119                                                scayt_control_id = scayt_instanse.id;
     120                                                scayt_instanse.destroy( true );
    115121                                                delete plugin.instances[ editor.name ];
    116122                                        }
    117123                                }
     
    120126
    121127                editor.on( 'destroy', function()
    122128                        {
    123                                 plugin.getScayt( editor ).destroy();
     129                                scayt_control_id = scayt_instanse.id;
     130                                plugin.getScayt( editor ).destroy( true );
    124131                        });
    125132                // Listen to data manipulation to reflect scayt markup.
    126133                editor.on( 'afterSetData', function()
    127134                        {
    128                                 if ( plugin.isScaytEnabled( editor ) )
    129                                         plugin.getScayt( editor ).refresh();
     135                                if ( plugin.isScaytEnabled( editor ) ) {
     136                                        window.setTimeout( function(){ plugin.getScayt( editor ).refresh() }, 10 );
     137                                }
    130138                        });
    131139
    132140                // Reload spell-checking for current word after insertion completed.
     
    141149                                                editor.getSelection().unlock( true );
    142150
    143151                                        // Swallow any SCAYT engine errors.
    144                                         try{
    145                                                 scayt_instance.refresh();
    146                                         }catch( er )
    147                                         {}
     152                                        window.setTimeout( function(){ scayt_instance.refresh() }, 10 );
    148153                                }
    149154                        }, this, null, 50 );
    150155
     
    160165                                                editor.getSelection().unlock( true );
    161166
    162167                                        // Swallow any SCAYT engine errors.
    163                                         try{
    164                                                 scayt_instance.refresh();
    165                                         }catch( er )
    166                                         {}
     168                                       
     169                                        window.setTimeout( function(){ scayt_instance.refresh() },10 );
     170                                       
    167171                                }
    168172                        }, this, null, 50 );
    169173
     
    220224                },
    221225                loadEngine : function( editor )
    222226                {
     227                        // SCAYT doesn't work with Opera.
     228                        if ( CKEDITOR.env.opera )
     229                                return;
    223230                        if ( this.engineLoaded === true )
    224231                                return onEngineLoad.apply( editor );    // Add new instance.
    225232                        else if ( this.engineLoaded == -1 )                     // We are waiting.
     
    232239                                },
    233240                                this,
    234241                                null,
    235                                 0 );    // First to run.
     242                                0
     243                        );      // First to run.
    236244
    237245                        this.engineLoaded = -1; // Loading in progress.
    238246
     
    240248                        var protocol = document.location.protocol;
    241249                        // Default to 'http' for unknown.
    242250                        protocol = protocol.search( /https?:/) != -1? protocol : 'http:';
    243                         var baseUrl  = "svc.spellchecker.net/spellcheck3/lf/scayt/scayt21.js";
     251                        var baseUrl  = "svc.spellchecker.net/spellcheck31/lf/scayt/scayt22.js";
    244252
    245253                        var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl );
    246254                        var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  "/";
     
    357365                        // string tp array convert
    358366                        confuiTabs = confuiTabs.split(",");
    359367                        // check array length ! allwaays must be 3 filled with 1 or 0
    360                         for (var i=0,l=3; i<l; i++){
     368                        for (var i=0,l=3; i<l; i++)
     369                        {
    361370                                var flag = parseInt(confuiTabs[i] || "1" ,10);
    362371                                uiTabs.push(  flag  );
    363372                        }
     
    459468                        // If the "contextmenu" plugin is loaded, register the listeners.
    460469                        if ( editor.contextMenu && editor.addMenuItems )
    461470                        {
    462                                 editor.contextMenu.addListener( function( element )
     471                                editor.contextMenu.addListener( function( )
    463472                                        {
    464                                                 if ( !( plugin.isScaytEnabled( editor ) && element ) )
     473                                                if ( !plugin.isScaytEnabled( editor ) )
    465474                                                        return null;
    466475
    467476                                                var scayt_control = plugin.getScayt( editor ),
    468                                                         word = scayt_control.getWord( element.$ );
    469 
     477                                                        node = scayt_control.getScaytNode();
     478                                               
     479                                                if ( !node )
     480                                                        return null;
     481
     482                                                        var word = scayt_control.getWord( node );
     483
    470484                                                if ( !word )
    471485                                                        return null;
    472486
    473487                                                var sLang = scayt_control.getLang(),
    474488                                                        _r = {},
    475489                                                        items_suggestion = window.scayt.getSuggestion( word, sLang );
    476                                                 if (!items_suggestion || !items_suggestion.length )
     490                                                if ( !items_suggestion || !items_suggestion.length )
    477491                                                        return null;
    478492                                                // Remove unused commands and menuitems
    479493                                                for ( i in moreSuggestions )
     
    510524                                                                                        scayt_control.replace(el, s);
    511525                                                                                }
    512526                                                                        };
    513                                                                 })( element.$, items_suggestion[i] );
     527                                                                })( node, items_suggestion[i] );
    514528
    515529                                                        if ( i < maxSuggestions )
    516530                                                        {
     
    548562                                                {
    549563                                                        var ignore_command = {
    550564                                                                exec: function(){
    551                                                                         scayt_control.ignore(element.$);
     565                                                                        scayt_control.ignore( node );
    552566                                                                }
    553567                                                        };
    554568                                                        addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);
     
    559573                                                {
    560574                                                        var ignore_all_command = {
    561575                                                                exec: function(){
    562                                                                         scayt_control.ignoreAll(element.$);
     576                                                                        scayt_control.ignoreAll( node );
    563577                                                                }
    564578                                                        };
    565579                                                        addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
     
    570584                                                {
    571585                                                        var addword_command = {
    572586                                                                exec: function(){
    573                                                                         window.scayt.addWordToUserDictionary(element.$);
     587                                                                        window.scayt.addWordToUserDictionary( node );
    574588                                                                }
    575589                                                        };
    576590                                                        addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
     
    593607                                        command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
    594608                                };
    595609                                editor.on( 'showScaytState', showInitialState );
    596 
    597610                                plugin.loadEngine( editor );
    598611                        }
    599612
     
    612625        });
    613626})();
    614627
    615 // TODO: Documentation
    616 // CKEDITOR.config.scayt_maxSuggestions
    617 // CKEDITOR.config.scayt_autoStartup
     628/**
     629 * If enabled (true), turns on SCAYT automatically after loading the editor.
     630 * @name CKEDITOR.config.scayt_autoStartup
     631 * @type Boolean
     632 * @default false
     633 * @example
     634 * config.scayt_autoStartup = true;
     635 */
     636
     637/**
     638 * Defines the number of SCAYT suggestions to show in the main context menu.
     639 * The possible values are:
     640 * <ul>
     641 *      <li>0 (zero): All suggestions are displayed in the main context menu.</li>
     642 *      <li>Positive number: The maximum number of suggestions to shown in context
     643 *              menu. Other entries will be shown in "More Suggestions" sub-menu.</li>
     644 *      <li>Negative number: No suggestions are shown in the main context menu. All
     645 *              entries will be listed in the "Suggestions" sub-menu.</li>
     646 * </ul>
     647 * @name CKEDITOR.config.scayt_maxSuggestions
     648 * @type Number
     649 * @default 5
     650 * @example
     651 * // Display only three suggestions in the main context menu.
     652 * config.scayt_maxSuggestions = 3;
     653 * @example
     654 * // Do not show the suggestions directly.
     655 * config.scayt_maxSuggestions = -1;
     656 */
     657
     658/**
     659 * Sets the customer ID for SCAYT. Required for migration from free version
     660 * with banner to paid version.
     661 * @name CKEDITOR.config.scayt_customerid
     662 * @type String
     663 * @default ''
     664 * @example
     665 * // Load SCAYT using my customer ID.
     666 * config.scayt_customerid  = 'your-encrypted-customer-id';
     667 */
     668
     669/**
     670 * Enables/disables the "More Suggestions" sub-menu in the context menu.
     671 * The possible values are "on" or "off".
     672 * @name CKEDITOR.config.scayt_moreSuggestions
     673 * @type String
     674 * @default 'on'
     675 * @example
     676 * // Disables the "More Suggestions" sub-menu.
     677 * config.scayt_moreSuggestions = 'off';
     678 */
     679
     680/**
     681 * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore"
     682 * and "Ignore All"). It must be a string with one or more of the following
     683 * words separated by a pipe ("|"):
     684 * <ul>
     685 *      <li>"off": disables all options.</li>
     686 *      <li>"all": enables all options.</li>
     687 *      <li>"ignore": enables the "Ignore" option.</li>
     688 *      <li>"ignoreall": enables the "Ignore All" option.</li>
     689 *      <li>"add": enables the "Add Word" option.</li>
     690 * </ul>
     691 * @name CKEDITOR.config.scayt_contextCommands
     692 * @type String
     693 * @default 'all'
     694 * @example
     695 * // Show only "Add Word" and "Ignore All" in the context menu.
     696 * config.scayt_contextCommands = 'add|ignoreall';
     697 */
     698
     699/**
     700 * Sets the default spellchecking language for SCAYT.
     701 * @name CKEDITOR.config.scayt_sLang
     702 * @type String
     703 * @default 'en_US'
     704 * @example
     705 * // Sets SCAYT to German.
     706 * config.scayt_sLang = 'de_DE';
     707 */
     708
     709/**
     710 * Sets the visibility of the SCAYT tabs in the settings dialog and toolbar
     711 * button. The value must contain a "1" (enabled) or "0" (disabled) number for
     712 * each of the following entries, in this precise order, separated by a
     713 * comma (","): "Options", "Languages" and "Dictionary".
     714 * @name CKEDITOR.config.scayt_uiTabs
     715 * @type String
     716 * @default '1,1,1'
     717 * @example
     718 * // Hide the "Languages" tab.
     719 * config.scayt_uiTabs = '1,0,1';
     720 */
     721
     722
     723/**
     724 * Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application.
     725 * Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l .
     726 * @name CKEDITOR.config.scayt_srcUrl
     727 * @type String
     728 * @default ''
     729 * @example
     730 * config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js";
     731 */
     732
     733/**
     734 * Links SCAYT to custom dictionaries. It's a string containing dictionary ids
     735 * separared by commas (","). Available only for licensed version.
     736 * Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support .
     737 * @name CKEDITOR.config.scayt_customDictionaryIds
     738 * @type String
     739 * @default ''
     740 * @example
     741 * config.scayt_customDictionaryIds = '3021,3456,3478"';
     742 */
     743
     744/**
     745 * Makes it possible to activate a custom dictionary on SCAYT. The user
     746 * dictionary name must be used. Available only for licensed version.
     747 * @name CKEDITOR.config.scayt_userDictionaryName
     748 * @type String
     749 * @default ''
     750 * @example
     751 * config.scayt_userDictionaryName = 'MyDictionary';
     752 */
     753
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy