Ticket #2816: 2816_2.patch

File 2816_2.patch, 22.4 KB (added by Garry Yao, 15 years ago)
  • _source/core/editor.js

     
    380380                execCommand : function( commandName, data )
    381381                {
    382382                        var command = this.getCommand( commandName );
     383                        var exeResult;
     384                        var commandEvent =
     385
     386                        /**
     387                         * The event data for this command
     388                         * @type FCKEDITOR.command.Event
     389                         */
     390                        {
     391                                name :commandName,
     392                                command :command
     393                        };
    383394                        if ( command && command.state != CKEDITOR.TRISTATE_DISABLED )
    384                                 return command.exec( this, data );
     395                        {
     396                                this.fire( 'beforeCommandExec' , commandEvent );
     397                                exeResult = command.exec( this , data );
     398                                this.fire( 'afterCommandExec' , commandEvent );
     399                                return exeResult;
     400                        }
    385401
    386402                        // throw 'Unknown command name "' + commandName + '"';
    387403                        return false;
  • _source/plugins/dialog/plugin.js

     
    205205
    206206                this.on( 'ok', function( evt )
    207207                        {
     208                                this._.editor.fire('beforeDialogClose');
    208209                                iterContents( function( item )
    209210                                        {
    210211                                                if ( item.validate )
     
    234235
    235236                this.on( 'cancel', function( evt )
    236237                        {
     238                                this._.editor.fire('beforeDialogClose');
    237239                                iterContents( function( item )
    238240                                        {
    239241                                                if ( item.isChanged() )
     
    461463                                        } );
    462464
    463465                        // Save editor selection and grab the focus.
    464                         if ( !this._.parentDialog )
    465                                 this.saveSelection();
    466466                        this._.dummyText.focus();
    467467                        this._.dummyText.$.select();
    468468
     469                        this._.editor.fire('beforeDialogShow', this);
    469470                        // Execute onLoad for the first show.
    470471                        this.fireOnce( 'load', {} );
    471472                        this.fire( 'show', {} );
     
    575576                                CKEDITOR.document.removeListener( 'keydown', accessKeyDownHandler );
    576577                                CKEDITOR.document.removeListener( 'keyup', accessKeyUpHandler );
    577578
    578                                 // Restore focus and (if not already restored) selection in the editing area.
    579                                 this.restoreSelection();
    580                                 this._.editor.focus();
    581579                        }
    582580                        else
    583581                                CKEDITOR.dialog._.currentZIndex -= 10;
     
    818816                getParentEditor : function()
    819817                {
    820818                        return this._.editor;
    821                 },
    822 
    823                 /**
    824                  * Saves the current selection position in the editor.
    825                  * This function is automatically called when a non-nested dialog is opened,
    826                  * but it may also be called by event handlers in dialog definition.
    827                  * @example
    828                  */
    829                 saveSelection : function()
    830                 {
    831                         if ( this._.editor.mode )
    832                         {
    833                                 var selection = new CKEDITOR.dom.selection( this._.editor.document );
    834                                 this._.selectedRanges = selection.getRanges();
    835                         }
    836                 },
    837 
    838                 /**
    839                  * Clears the saved selection in the dialog object.
    840                  * This function should be called if the dialog's code has already changed the
    841                  * current selection position because the dialog closed. (e.g. at onOk())
    842                  * @example
    843                  */
    844                 clearSavedSelection : function()
    845                 {
    846                         delete this._.selectedRanges;
    847                 },
    848 
    849                 /**
    850                  * Restores the editor's selection from the previously saved position in this
    851                  * dialog.
    852                  * This function is automatically called when a non-nested dialog is closed,
    853                  * but it may also be called by event handlers in dialog definition.
    854                  * @example
    855                  */
    856                 restoreSelection : function()
    857                 {
    858                         if ( this._.editor.mode && this._.selectedRanges )
    859                                 ( new CKEDITOR.dom.selection( this._.editor.document ) ).selectRanges( this._.selectedRanges );
    860819                }
     820
    861821        };
    862822
    863823        CKEDITOR.tools.extend( CKEDITOR.dialog,
     
    879839                        {
    880840                                this._.dialogDefinitions[name] = dialogDefinition;
    881841                        },
    882                        
     842
    883843                        exists : function( name )
    884844                        {
    885845                                return !!this._.dialogDefinitions[ name ];
  • _source/plugins/link/dialogs/link.js

     
    636636                onShow : function()
    637637                {
    638638                        this.fakeObj = false;
    639                         // IE BUG: Selection must be in the editor for getSelection() to work.
    640                         this.restoreSelection();
    641639                        var editor = this.getParentEditor(),
    642640                                selection = editor.getSelection(),
    643641                                ranges = selection.getRanges(),
     
    696694                                {
    697695                                        loadLink.apply( this, [ editor, selection, ranges, element ] );
    698696                                        selection.selectElement( element );
    699                                         this.saveSelection();
    700697                                }
    701698
    702699                                element = rangeRoot.getAscendant( 'img', true );
     
    706703                                        element = editor.fakeobjects.restoreElement( this.fakeObj );
    707704                                        loadLink.apply( this, [ editor, selection, ranges, element ] );
    708705                                        selection.selectElement( this.fakeObj );
    709                                         this.saveSelection();
    710706                                }
    711707                        }
    712708
     
    803799
    804800                        if ( !this._.selectedElement )
    805801                        {
    806                                 // IE BUG: Selection must be in the editor for getSelection() to work.
    807                                 this.restoreSelection();
    808                                 this.clearSavedSelection();
    809 
    810802                                // Create element if current selection is collapsed.
    811803                                var selection = editor.getSelection(),
    812804                                        ranges = selection.getRanges();
  • _source/plugins/link/dialogs/anchor.js

     
    88        // Function called in onShow to load selected element.
    99        var loadElements = function( editor, selection, ranges, element )
    1010        {
    11                 this.saveSelection();
    1211                this.editMode = true;
    1312                this.editObj = element;
    1413
     
    3635                        // Insert a new anchor.
    3736                        if ( !this.editMode )
    3837                        {
    39                                 // It doesn't work with IE.
    40                                 this.restoreSelection();
    41                                 this.clearSavedSelection();
    4238
    4339                                var fakeElement = editor.fakeobjects.protectElement( this.editObj );
    4440                                editor.insertElement( fakeElement );
     
    5349                        this.fakeObj = false;
    5450                        this.editMode = false;
    5551
    56                         // IE BUG: Selection must be in the editor for getSelection() to work.
    57                         this.restoreSelection();
    58 
    5952                        var editor = this.getParentEditor(),
    6053                                selection = editor.getSelection(),
    6154                                ranges = selection.getRanges();
     
    7164                                        element = editor.fakeobjects.restoreElement( this.fakeObj );
    7265                                        loadElements.apply( this, [ editor, selection, ranges, element ] );
    7366                                        selection.selectElement( this.fakeObj );
    74                                         this.saveSelection();
    7567                                }
    7668                        }
    7769                        this.pushDefault();
  • _source/plugins/specialchar/dialogs/specialchar.js

     
    4646                {
    4747                        var columns = this.definition.charColumns,
    4848                                chars = this.definition.chars;
    49                
     49
    5050                        var html = [ '<table style="width: 320px; height: 100%; border-collapse: separate;" align="center" cellspacing="2" cellpadding="2" border="0">' ];
    5151
    5252                        var i = 0 ;
     
    5353                        while ( i < chars.length )
    5454                        {
    5555                                html.push( '<tr>' ) ;
    56                                
     56
    5757                                for( var j = 0 ; j < columns ; j++, i++ )
    5858                                {
    5959                                        if ( chars[ i ] )
     
    5858                                {
    5959                                        if ( chars[ i ] )
    6060                                        {
    61                                                 html.push( 
     61                                                html.push(
    6262                                                        '<td width="1%"' +
    6363                                                        ' title="', chars[i].replace( /&/g, '&amp;' ), '"' +
    6464                                                        ' value="', chars[i].replace( /&/g, "&amp;" ), '"' +
     
    6767                                        }
    6868                                        else
    6969                                                html.push( '<td class="DarkBackground">&nbsp;' );
    70                                        
     70
    7171                                        html.push( '</td>' );
    7272                                }
    7373                                html.push( '</tr>' );
     
    140140                                                                                                target = target.$;
    141141                                                                                                if ( value = target.getAttribute( 'value' ) )
    142142                                                                                                {
    143                                                                                                         this.getDialog().restoreSelection();
    144143                                                                                                        editor.insertHtml( value );
    145144                                                                                                        this.getDialog().hide();
    146145                                                                                                }
  • _source/plugins/image/dialogs/image.js

     
    228228                var oImageOriginal = dialog.editObj[ 'imageOriginal' ];
    229229                if ( oImageOriginal && oImageOriginal.getCustomData( 'isReady' ) == 'true' )
    230230                {
    231                         if ( value != undefined )
     231                        if ( value != undefined )
    232232                                dialog.imageLockRatio = value
    233233                        else
    234234                                dialog.imageLockRatio = !dialog.imageLockRatio;
     
    341341        {
    342342                this.editObj[ 'image' ] = false;
    343343                this.editMode[ 'image' ] = false;               // Default:  Create a new Image
    344                 this.saveSelection();
    345344
    346345                this.setValueOf( "Link", "txtUrl", "" );
    347346                this.setValueOf( "Link", "cmbTarget", "" );
     
    501500                        // Insert a new Image.
    502501                        if ( this.editMode[ 'image' ] == false )
    503502                        {
    504                                 // It doesn't work with IE.
    505                                 this.restoreSelection();
    506                                 this.clearSavedSelection();
    507503
    508504                                if ( useLink )
    509505                                        //Insert a new Link.
     
    559555                        this.dimensionsInStyle[ 'height' ] = false;
    560556                        this.forceResetSize = false;
    561557
    562                         // IE BUG: Selection must be in the editor for getSelection() to work.
    563                         this.restoreSelection();
    564558
    565559                        var editor = this.getParentEditor(),
    566560                                selection = editor.getSelection(),
     
    602596                                {
    603597                                        loadElements.apply( this, [ editor, selection, ranges, element ] );
    604598                                        selection.selectElement( element );
    605                                         this.saveSelection();
    606599                                }
    607600                        }
    608601                        updateOriginal( this, false );
  • _source/plugins/forms/dialogs/textfield.js

     
    1717        // Function called in onShow to load selected element.
    1818        var loadSelection = function( editor, selection, ranges, element )
    1919        {
    20                 this.saveSelection();
    2120                this.editObj = element;
    2221                this.editMode = true;
    2322
     
    4948                        // Default: create a new element.
    5049                        this.editMode = false;
    5150
    52                         // IE BUG: Selection must be in the editor for getSelection() to work.
    53                         this.restoreSelection();
    5451
    5552                        var editor = this.getParentEditor(),
    5653                                selection = editor.getSelection(),
     
    8683
    8784                        if ( this.editMode == false )
    8885                        {
    89                                 this.restoreSelection();
    90                                 this.clearSavedSelection();
    9186                                editor.insertElement( this.editObj );
    9287                        }
    9388                        return true;
  • _source/plugins/forms/dialogs/select.js

     
    4444
    4545                dialog.editObj = element;
    4646                dialog.editMode = true;
    47                 dialog.saveSelection();
    4847
    4948                dialog.getContentElement( 'info', 'txtName' ).setValue( dialog.editObj.getAttribute( "name" ) );
    5049                dialog.getContentElement( 'info', 'txtSize' ).setValue( dialog.editObj.getAttribute( "size" ) );
     
    7473                        this.editMode = false;
    7574                        this.changedAttibutes = new Array();
    7675
    77                         // IE BUG: Selection must be in the editor for getSelection() to work.
    78                         this.restoreSelection();
    7976
    8077                        var editor = this.getParentEditor(),
    8178                                selection = editor.getSelection(),
     
    9188                                {
    9289                                        loadSelection.apply( this, [ editor, selection, ranges, element ] );
    9390                                        selection.selectElement( element );
    94                                         this.saveSelection();
    9591                                }
    9692                        }
    9793
     
    139135
    140136                        if ( this.editMode == false )
    141137                        {
    142                                 this.restoreSelection();
    143138                                parentEditor.insertElement( this.editObj );
    144139                        }
    145140                        return true;
  • _source/plugins/forms/dialogs/textarea.js

     
    1717        // Function called in onShow to load selected element.
    1818        var loadSelection = function( editor, selection, ranges, element )
    1919        {
    20                 this.saveSelection();
    2120                this.editObj = element;
    2221                this.editMode = true;
    2322
     
    4746                        // Default: create a new element.
    4847                        this.editMode = false;
    4948
    50                         // IE BUG: Selection must be in the editor for getSelection() to work.
    51                         this.restoreSelection();
    5249
    5350                        var editor = this.getParentEditor(),
    5451                                selection = editor.getSelection(),
     
    8077
    8178                        if ( this.editMode == false )
    8279                        {
    83                                 this.restoreSelection();
    84                                 this.clearSavedSelection();
    8580                                editor.insertElement( this.editObj );
    8681                        }
    8782                        return true;
  • _source/plugins/forms/dialogs/radio.js

     
    1717        // Function called in onShow to load selected element.
    1818        var loadSelection = function( editor, selection, ranges, element )
    1919        {
    20                 this.saveSelection();
    2120                this.editObj = element;
    2221                this.editMode = true;
    2322
     
    4443                        this.editMode = false;
    4544                        this.changedAttibutes = new Array();
    4645
    47                         // IE BUG: Selection must be in the editor for getSelection() to work.
    48                         this.restoreSelection();
    4946
    5047                        var editor = this.getParentEditor(),
    5148                                selection = editor.getSelection(),
     
    7976                        if ( this.editMode == false )
    8077                        {
    8178                                // It doesn't work with IE.
    82                                 this.restoreSelection();
    83                                 this.clearSavedSelection();
    8479                                editor.insertElement( this.editObj );
    8580                        }
    8681                        return true;
  • _source/plugins/forms/dialogs/button.js

     
    2626                this.setValueOf( 'info', 'txtValue', value );
    2727                this.setValueOf( 'info', 'txtType', type );
    2828
    29                 this.saveSelection();
    3029                this.editMode = true;
    3130                this.editObj = element;
    3231
     
    4342                        // Default: create a new element.
    4443                        this.editMode = false;
    4544
    46                         // IE BUG: Selection must be in the editor for getSelection() to work.
    47                         this.restoreSelection();
    4845
    4946                        var editor = this.getParentEditor(),
    5047                                selection = editor.getSelection(),
     
    8077
    8178                        if ( this.editMode == false )
    8279                        {
    83                                 this.restoreSelection();
    84                                 this.clearSavedSelection();
    8580                                editor.insertElement( this.editObj );
    8681                        }
    8782                        return true;
  • _source/plugins/forms/dialogs/checkbox.js

     
    1010                minHeight : 230,
    1111                onShow : function()
    1212                {
    13                         // IE BUG: Selection must be in the editor for getSelectedElement()
    14                         // to work.
    15                         this.restoreSelection();
    16 
    1713                        var element = this.getParentEditor().getSelection().getSelectedElement();
    1814
    1915                        if ( element && element.getAttribute( 'type' ) == "checkbox" )
     
    3935
    4036                        if ( isInsertMode )
    4137                        {
    42                                 this.restoreSelection();
    43                                 this.clearSavedSelection();
    4438                                editor.insertElement( element );
    4539                        }
    4640                },
  • _source/plugins/forms/dialogs/hiddenfield.js

     
    1717        // Function called in onShow to load selected element.
    1818        var loadSelection = function( editor, selection, ranges, element )
    1919        {
    20                 this.saveSelection();
    2120                this.editObj = element;
    2221                this.editMode = true;
    2322
     
    4140                        this.editMode = false;
    4241                        this.changedAttibutes = new Array();
    4342
    44                         // IE BUG: Selection must be in the editor for getSelection() to work.
    45                         this.restoreSelection();
    4643
    4744                        var editor = this.getParentEditor(),
    4845                                selection = editor.getSelection(),
     
    7471
    7572                        if ( this.editMode == false )
    7673                        {
    77                                 this.restoreSelection();
    78                                 this.clearSavedSelection();
    7974                                editor.insertElement( this.editObj );
    8075                        }
    8176                        return true;
  • _source/plugins/forms/dialogs/form.js

     
    1717        // Function called in onShow to load selected element.
    1818        var loadSelection = function( editor, selection, ranges, element )
    1919        {
    20                 this.saveSelection();
    2120                this.editObj = element;
    2221                this.editMode = true;
    2322
     
    5453
    5554                        if ( this.editMode == false )
    5655                        {
    57                                 this.restoreSelection();
    58                                 this.clearSavedSelection();
    5956                                editor.insertElement( this.editObj );
    6057                        }
    6158                        return true;
     
    6663                        this.editMode = false;
    6764                        this.changedAttibutes = new Array();
    6865
    69                         // IE BUG: Selection must be in the editor for getSelection() to work.
    70                         this.restoreSelection();
    7166
    7267                        var editor = this.getParentEditor(),
    7368                                selection = editor.getSelection(),
  • _source/plugins/flash/dialogs/flash.js

     
    163163        var loadElements = function( editor, selection, ranges, fakeElement, realElement )
    164164        {
    165165                selection.selectElement( fakeElement );
    166                 this.saveSelection();
    167166                this.editMode[ 'fakeobject' ] = realElement.getName();
    168167                this.editObj[ 'fakeobject' ] = fakeElement;
    169168
     
    326325                        this.dimensionsInStyle[ 'width' ] = false;
    327326                        this.dimensionsInStyle[ 'height' ] = false;
    328327
    329                         // IE BUG: Selection must be in the editor for getSelection() to work.
    330                         this.restoreSelection();
    331328
    332329                        var editor = this.getParentEditor(),
    333330                                selection = editor.getSelection(),
     
    415412                                else
    416413                                        this.editObj[ 'fakeobject' ] = CKEDITOR.plugins.fakeobjects.protectElement( this.editObj[ 'object' ] );
    417414
    418                                 // It doesn't work with IE.
    419                                 this.restoreSelection();
    420                                 this.clearSavedSelection();
    421415                                editor.insertElement( this.editObj[ 'fakeobject' ] );
    422416                        }
    423417                        else
  • _source/plugins/table/dialogs/table.js

     
    1616                onShow : function()
    1717                {
    1818                        // Detect if there's a selected table.
    19                         this.restoreSelection();
    2019                        var selection = editor.getSelection(),
    2120                                ranges = selection.getRanges(),
    2221                                me = this,
     
    148147                        // Insert the table element if we're creating one.
    149148                        if ( !this._.selectedElement )
    150149                        {
    151                                 this.restoreSelection();
    152150                                editor.insertElement( table );
    153151                                this.clearSavedSelection();
    154152                        }
  • _source/plugins/styles/plugin.js

     
    595595
    596596CKEDITOR.styleCommand.prototype.exec = function( editor )
    597597{
    598         editor.focus();
    599598
    600599        var doc = editor.document;
    601600
  • _source/plugins/selection/plugin.js

     
    9090                                                // IE is the only to provide the "selectionchange"
    9191                                                // event.
    9292                                                editor.document.on( 'selectionchange', checkSelectionChangeTimeout, editor );
     93
     94                                                //Destory previous saved selection.
     95                                                editor.document.on( 'selectionchange', function ()
     96                                                {
     97                                                        editor.dropSavedRanges();
     98                                                } );
     99
     100                                                // Save selection on editor window blur
     101                                                ( new CKEDITOR.dom.element( editor.document.$.body ) ).on( 'beforedeactivate',
     102                                                function (){
     103                                                        editor.saveSelection();
     104                                                } );
    93105                                        }
    94106                                        else
    95107                                        {
     
    102114                                        }
    103115                                });
    104116
    105                         editor.addCommand( 'selectAll', selectAllCmd );
     117                        //restore selection for commands.
     118                        if ( CKEDITOR.env.ie )
     119                        {
     120                                editor.on( 'beforeCommandExec',  editor.restoreSelection,  editor);
     121                                editor.on( 'beforeDialogShow',  editor.restoreSelection,  editor);
     122                                editor.on( 'beforeDialogClose',  editor.restoreSelection,  editor);
     123                        }
     124                        editor.addCommand( 'selectAll',  selectAllCmd );
    106125                        editor.ui.addButton( 'SelectAll',
    107126                                {
    108127                                        label : editor.lang.selectAll,
     
    142161};
    143162
    144163/**
     164 * Last selection ranges recording
     165 * @name selectedRanges
     166 * @private
     167 * @memberof CKEDITOR.editor
     168 * @type CKEDITOR.dom.range
     169 */
     170
     171//Selection restore  APIs for IE, see #2816
     172if( CKEDITOR.env.ie )
     173{
     174        CKEDITOR.tools.extend( CKEDITOR.editor.prototype,  {
     175
     176                /**
     177                 * Record the current selection status range of this document.
     178                 * Note: This save doesn't resistant to dom changes, resort to undo/redo plugin for such need.
     179                 */
     180                saveSelection : function()
     181                {
     182                        if ( this.mode === 'wysiwyg' && !this._.selectedRanges )
     183                        {
     184                                var selection = new CKEDITOR.dom.selection( this.document );
     185                                this._.selectedRanges = selection.getRanges();
     186                        }
     187                },
     188
     189                /**
     190                 * Clears the saved selection ranges when expired.
     191                 */
     192                dropSavedRanges : function()
     193                {
     194                        if( this._.selectedRanges )
     195                        {
     196                                delete this._.selectedRanges;
     197                        }
     198                },
     199
     200                /**
     201                 * Retrieve the last saved ranges
     202                 * @return {CKEDITOR.dom.range}
     203                 */
     204                getSavedRange: function()
     205                {
     206                        return this._.selectionRanges||null;
     207                },
     208
     209                /**
     210                 * Restores the last ranges record and select the ranges in document.
     211                 */
     212                restoreSelection : function()
     213                {
     214                        if ( this._.selectedRanges && this.mode === 'wysiwyg' )
     215                        {
     216                                ( new CKEDITOR.dom.selection( this.document ) ).selectRanges( this._.selectedRanges );
     217                        }
     218                }
     219});
     220}
     221
     222
     223/**
    145224 * Gets the current selection from the document.
    146225 * @returns {CKEDITOR.dom.selection} A selection object.
    147226 * @example
  • _source/plugins/smiley/dialogs/smiley.js

     
    5454                        else if ( targetName != 'img' )
    5555                                return;
    5656
    57                         this.getDialog().restoreSelection();
    58                        
    5957                        var src = target.getAttribute( 'src' ),
    6058                                title = target.getAttribute( 'title' );
    6159                       
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy