Ticket #5145: 5145_5.patch

File 5145_5.patch, 10.6 KB (added by WebSpellChecker.net, 14 years ago)
  • _source/plugins/scayt/plugin.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
     
    1010
    1111(function()
    1212{
     13 
    1314        var commandName         = 'scaytcheck',
    1415                openPage                = '',
    15                 scayt_paused    = null;
     16                scayt_paused    = null,
     17                scayt_control_id = null;
    1618
    1719        // Checks if a value exists in an array
    1820        function in_array(needle, haystack)
     
    4446                        oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds;
    4547                        oParams.userDictionaryName = editor.config.scayt_userDictionaryName;
    4648                        oParams.sLang = editor.config.scayt_sLang || "en_US";
    47 
    48                         if ( CKEDITOR._scaytParams )
     49                       
     50                        if ( CKEDITOR._.scaytParams )
    4951                        {
    50                                 for ( var k in CKEDITOR._scaytParams )
     52                                for ( var k in CKEDITOR._.scaytParams )
    5153                                {
    52                                         oParams[ k ] = CKEDITOR._scaytParams[ k ];
     54                                        oParams[ k ] = CKEDITOR._.scaytParams[ k ];
    5355                                }
    5456                        }
    55 
     57                       
     58                        if ( scayt_control_id )
     59                                oParams.id = scayt_control_id;
     60                       
    5661                        var scayt_control = new window.scayt( oParams );
    5762
    5863                        // Copy config.
     
    103108
    104109                editor.on( 'beforeCommandExec', function( ev )          // Disable SCAYT before Source command execution.
    105110                        {
     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                                }
    106118                                if ( (ev.data.name == 'source' ||  ev.data.name == 'newpage') && editor.mode == 'wysiwyg' )
    107119                                {
    108120                                        var scayt_instanse = plugin.getScayt( editor );
    109121                                        if ( scayt_instanse )
    110122                                        {
    111123                                                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                                               
    114128                                        }
    115129                                }
    116130                        });
     
    118132
    119133                editor.on( 'destroy', function()
    120134                        {
    121                                 plugin.getScayt( editor ).destroy();
     135                                scayt_control_id = scayt_instanse.id;
     136                                plugin.getScayt( editor ).destroy(true);
    122137                        });
    123138                // Listen to data manipulation to reflect scayt markup.
    124139                editor.on( 'afterSetData', function()
    125140                        {
    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                                }
    128148                        });
    129149
    130150                // Reload spell-checking for current word after insertion completed.
     
    139159                                                editor.getSelection().unlock( true );
    140160
    141161                                        // Swallow any SCAYT engine errors.
    142                                         try{
    143                                                 scayt_instance.refresh();
    144                                         }catch( er )
    145                                         {}
     162                                        window.setTimeout(function(){scayt_instance.refresh()},10);
     163                                       
    146164                                }
    147165                        }, this, null, 50 );
    148166
     
    158176                                                editor.getSelection().unlock( true );
    159177
    160178                                        // 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                                       
    165182                                }
    166183                        }, this, null, 50 );
    167184
     
    218235                },
    219236                loadEngine : function( editor )
    220237                {
     238                        if (CKEDITOR.env.opera)
     239                                return;
    221240                        if ( this.engineLoaded === true )
    222241                                return onEngineLoad.apply( editor );    // Add new instance.
    223242                        else if ( this.engineLoaded == -1 )                     // We are waiting.
     
    238257                        var protocol = document.location.protocol;
    239258                        // Default to 'http' for unknown.
    240259                        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";
    242261
    243262                        var scaytUrl  =  editor.config.scayt_srcUrl || ( protocol + "//" + baseUrl );
    244263                        var scaytConfigBaseUrl =  plugin.parseUrl( scaytUrl ).path +  "/";
     
    457476                        // If the "contextmenu" plugin is loaded, register the listeners.
    458477                        if ( editor.contextMenu && editor.addMenuItems )
    459478                        {
    460                                 editor.contextMenu.addListener( function( element )
     479                                editor.contextMenu.addListener( function( )
    461480                                        {
    462                                                 if ( !( plugin.isScaytEnabled( editor ) && element ) )
     481                                               
     482                                                if (!plugin.isScaytEnabled(editor))
     483                                                {                                                       
    463484                                                        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 );
    464494
    465                                                 var scayt_control = plugin.getScayt( editor ),
    466                                                         word = scayt_control.getWord( element.$ );
    467 
    468                                                 if ( !word )
     495                                                if (!word)
     496                                                {
    469497                                                        return null;
    470 
     498                                                }
    471499                                                var sLang = scayt_control.getLang(),
    472500                                                        _r = {},
    473501                                                        items_suggestion = window.scayt.getSuggestion( word, sLang );
    474                                                 if (!items_suggestion || !items_suggestion.length )
     502                                                if (!items_suggestion || !items_suggestion.length)
     503                                                {                                                       
    475504                                                        return null;
     505                                                }
    476506                                                // Remove unused commands and menuitems
    477507                                                for ( i in moreSuggestions )
    478508                                                {
     
    508538                                                                                        scayt_control.replace(el, s);
    509539                                                                                }
    510540                                                                        };
    511                                                                 })( element.$, items_suggestion[i] );
     541                                                                })( node, items_suggestion[i] );
    512542
    513543                                                        if ( i < maxSuggestions )
    514544                                                        {
     
    546576                                                {
    547577                                                        var ignore_command = {
    548578                                                                exec: function(){
    549                                                                         scayt_control.ignore(element.$);
     579                                                                        scayt_control.ignore(node);
    550580                                                                }
    551581                                                        };
    552582                                                        addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);
     
    557587                                                {
    558588                                                        var ignore_all_command = {
    559589                                                                exec: function(){
    560                                                                         scayt_control.ignoreAll(element.$);
     590                                                                        scayt_control.ignoreAll(node);
    561591                                                                }
    562592                                                        };
    563593                                                        addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
     
    568598                                                {
    569599                                                        var addword_command = {
    570600                                                                exec: function(){
    571                                                                         window.scayt.addWordToUserDictionary(element.$);
     601                                                                        window.scayt.addWordToUserDictionary(node);
    572602                                                                }
    573603                                                        };
    574604                                                        addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
     
    579609                                                        scayt_control.fireOnContextMenu( editor );
    580610
    581611                                                return mainSuggestions;
     612                                               
    582613                                        });
    583614                        }
    584615
     
    598629        });
    599630})();
    600631
    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 */
     641CKEDITOR.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 */
     657CKEDITOR.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 */
     680CKEDITOR.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 */
     699CKEDITOR.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 */
     710CKEDITOR.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 */
     723CKEDITOR.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 */
     734CKEDITOR.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 */
     745CKEDITOR.config.scayt_userDictionaryName = "";
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy