X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fundo%2Fplugin.js;h=94744eadcf4c8bf36bf7fe76a4da102dafbaf727;hb=4e90e78dc97789709ee7404359a5517540c27553;hp=e843d2360710aa1d7ac759e3bed73af0fed8b0d7;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/undo/plugin.js b/_source/plugins/undo/plugin.js index e843d23..94744ea 100644 --- a/_source/plugins/undo/plugin.js +++ b/_source/plugins/undo/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -114,21 +114,54 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Create the first image. editor.fire( 'saveSnapshot' ); }; + + /** + * Update the undo stacks with any subsequent DOM changes after this call. + * @name CKEDITOR.editor#updateUndo + * @example + * function() + * { + * editor.fire( 'updateSnapshot' ); + * ... + * // Ask to include subsequent (in this call stack) DOM changes to be + * // considered as part of the first snapshot. + * editor.fire( 'updateSnapshot' ); + * editor.document.body.append(...); + * ... + * } + */ + editor.on( 'updateSnapshot', function() + { + if ( undoManager.currentImage && new Image( editor ).equals( undoManager.currentImage ) ) + setTimeout( function() { undoManager.update(); }, 0 ); + }); } }); - // Gets a snapshot image which represent the current document status. - function Image( editor ) + CKEDITOR.plugins.undo = {}; + + /** + * Undo snapshot which represents the current document status. + * @name CKEDITOR.plugins.undo.Image + * @param editor The editor instance on which the image is created. + */ + var Image = CKEDITOR.plugins.undo.Image = function( editor ) { - var contents = editor.getSnapshot(), + this.editor = editor; + + editor.fire( 'beforeUndoImage' ); + + var contents = editor.getSnapshot(), selection = contents && editor.getSelection(); // In IE, we need to remove the expando attributes. - CKEDITOR.env.ie && contents && ( contents = contents.replace( /\s+_cke_expando=".*?"/g, '' ) ); + CKEDITOR.env.ie && contents && ( contents = contents.replace( /\s+data-cke-expando=".*?"/g, '' ) ); this.contents = contents; this.bookmarks = selection && selection.createBookmarks2( true ); - } + + editor.fire( 'afterUndoImage' ); + }; // Attributes that browser may changing them when setting via innerHTML. var protectedAttrs = /\b(?:href|src|name)="[^"]*?"/gi; @@ -137,6 +170,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { equals : function( otherImage, contentOnly ) { + var thisContents = this.contents, otherContents = otherImage.contents; @@ -238,7 +272,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // In IE, we need to remove the expando attributes. if ( CKEDITOR.env.ie ) - currentSnapshot = currentSnapshot.replace( /\s+_cke_expando=".*?"/g, '' ); + currentSnapshot = currentSnapshot.replace( /\s+data-cke-expando=".*?"/g, '' ); if ( beforeTypeImage.contents != currentSnapshot ) { @@ -310,7 +344,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ this.index = -1; - this.limit = this.editor.config.undoStackSize; + this.limit = this.editor.config.undoStackSize || 20; this.currentImage = null; @@ -397,8 +431,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Update current image with the actual editor // content, since actualy content may differ from // the original snapshot due to dom change. (#4622) - this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) ); - + this.update(); this.fireChange(); }, @@ -497,6 +530,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } return false; + }, + + /** + * Update the last snapshot of the undo stack with the current editor content. + */ + update : function() + { + this.snapshots.splice( this.index, 1, ( this.currentImage = new Image( this.editor ) ) ); } }; })(); @@ -509,7 +550,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * @example * config.undoStackSize = 50; */ -CKEDITOR.config.undoStackSize = 20; /** * Fired when the editor is about to save an undo snapshot. This event can be @@ -517,3 +557,23 @@ CKEDITOR.config.undoStackSize = 20; * @name CKEDITOR.editor#saveSnapshot * @event */ + +/** + * Fired before an undo image is to be taken. An undo image represents the + * editor state at some point. It's saved into an undo store, so the editor is + * able to recover the editor state on undo and redo operations. + * @name CKEDITOR.editor#beforeUndoImage + * @since 3.5.3 + * @see CKEDITOR.editor#afterUndoImage + * @event + */ + +/** + * Fired after an undo image is taken. An undo image represents the + * editor state at some point. It's saved into an undo store, so the editor is + * able to recover the editor state on undo and redo operations. + * @name CKEDITOR.editor#afterUndoImage + * @since 3.5.3 + * @see CKEDITOR.editor#beforeUndoImage + * @event + */