Ticket #117: isdirty.patch

File isdirty.patch, 2.7 KB (added by Frederico Caldeira Knabben, 17 years ago)
  • editor/_source/internals/fck.js

     
    4747
    4848        IsDirty : function()
    4949        {
    50                 return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
     50                if ( this.EditMode == FCK_EDITMODE_SOURCE )
     51                        return ( this.StartupValue != this.EditingArea.Textarea.value ) ;
     52                else
     53                        return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
    5154        },
    5255
    5356        ResetIsDirty : function()
    5457        {
    55                 if ( this.EditorDocument.body )
     58                if ( this.EditMode == FCK_EDITMODE_SOURCE )
     59                        this.StartupValue = this.EditingArea.Textarea.value ;
     60                else if ( this.EditorDocument.body )
    5661                        this.StartupValue = this.EditorDocument.body.innerHTML ;
    5762        },
    5863
     
    8590                this.EditingArea.FFSpellChecker = false ;
    8691
    8792                // Set the editor's startup contents
    88                 this.SetHTML( this.GetLinkedFieldValue() ) ;
     93                this.SetHTML( this.GetLinkedFieldValue(), true ) ;
    8994        },
    9095
    9196        Focus : function()
     
    299304                return html ;
    300305        },
    301306
    302         SetHTML : function( html )
     307        SetHTML : function( html, resetIsDirty )
    303308        {
    304309                this.EditingArea.Mode = FCK.EditMode ;
    305310
     
    319324                                html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
    320325                                html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
    321326                        }
     327                       
     328                        this._ForceResetIsDirty = ( resetIsDirty === true ) ;
    322329
    323330                        var sHtml = '' ;
    324331
     
    415422
    416423                        // Removes the enter key handler.
    417424                        FCK.EnterKeyHandler = null ;
     425                       
     426                        if ( resetIsDirty )
     427                                this.ResetIsDirty() ;
    418428
    419429                        // Listen for keystroke events.
    420430                        FCK.KeystrokeHandler.AttachToElement( this.EditingArea.Textarea ) ;
     
    529539        SwitchEditMode : function( noUndo )
    530540        {
    531541                var bIsWysiwyg = ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) ;
     542
     543                // Save the current IsDirty state, so we may restore it after the switch.
     544                var bIsDirty = FCK.IsDirty() ;
     545
    532546                var sHtml ;
    533547
    534548                // Update the HTML in the view output to show.
     
    547561
    548562                FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ;
    549563
    550                 FCK.SetHTML( sHtml ) ;
    551 
     564                FCK.SetHTML( sHtml, !bIsDirty ) ;
     565               
    552566                // Set the Focus.
    553567                FCK.Focus() ;
    554568
     
    622636
    623637        // Listen for keystroke events.
    624638        FCK.KeystrokeHandler.AttachToElement( FCK.EditorDocument ) ;
     639       
     640        if ( FCK._ForceResetIsDirty )
     641                FCK.ResetIsDirty() ;
    625642
    626643        FCK.OnAfterSetHTML() ;
    627644
     
    629646        if ( FCK.Status != FCK_STATUS_NOTLOADED )
    630647                return ;
    631648
    632         // Save the startup value for the "IsDirty()" check.
    633         FCK.ResetIsDirty() ;
    634 
    635649        FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
    636650}
    637651
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy