JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.2
[ckeditor.git] / _source / plugins / undo / plugin.js
index 95bd04a..337c427 100644 (file)
@@ -64,9 +64,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        editor.on( 'afterCommandExec', recordCommand );\r
 \r
                        // Save snapshots before doing custom changes.\r
-                       editor.on( 'saveSnapshot', function()\r
+                       editor.on( 'saveSnapshot', function( evt )\r
                                {\r
-                                       undoManager.save();\r
+                                       undoManager.save( evt.data && evt.data.contentOnly );\r
                                });\r
 \r
                        // Registering keydown on every document recreation.(#3844)\r
@@ -90,7 +90,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Make the undo manager available only in wysiwyg mode.\r
                        editor.on( 'mode', function()\r
                                {\r
-                                       undoManager.enabled = editor.mode == 'wysiwyg';\r
+                                       undoManager.enabled = editor.readOnly ? false : editor.mode == 'wysiwyg';\r
                                        undoManager.onChange();\r
                                });\r
 \r
@@ -116,24 +116,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        };\r
 \r
                        /**\r
-                        * Update the undo stacks with any subsequent DOM changes after this call.\r
+                        * Amend the top of undo stack (last undo image) with the current DOM changes.\r
                         * @name CKEDITOR.editor#updateUndo\r
                         * @example\r
                         * function()\r
                         * {\r
-                        * editor.fire( 'updateSnapshot' );\r
-                        * ...\r
-                        *  // Ask to include subsequent (in this call stack) DOM changes to be\r
-                        * // considered as part of the first snapshot.\r
-                        *      editor.fire( 'updateSnapshot' );\r
+                        *  editor.fire( 'saveSnapshot' );\r
                         *      editor.document.body.append(...);\r
+                        *  // Make new changes following the last undo snapshot part of it.\r
+                        *      editor.fire( 'updateSnapshot' );\r
                         * ...\r
                         * }\r
                         */\r
                        editor.on( 'updateSnapshot', function()\r
                        {\r
-                               if ( undoManager.currentImage && new Image( editor ).equals( undoManager.currentImage ) )\r
-                                       setTimeout( function() { undoManager.update(); }, 0 );\r
+                               if ( undoManager.currentImage )\r
+                                       undoManager.update();\r
                        });\r
                }\r
        });\r
@@ -148,6 +146,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        var Image = CKEDITOR.plugins.undo.Image = function( editor )\r
        {\r
                this.editor = editor;\r
+\r
+               editor.fire( 'beforeUndoImage' );\r
+\r
                var contents = editor.getSnapshot(),\r
                        selection       = contents && editor.getSelection();\r
 \r
@@ -156,6 +157,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                this.contents   = contents;\r
                this.bookmarks  = selection && selection.createBookmarks2( true );\r
+\r
+               editor.fire( 'afterUndoImage' );\r
        };\r
 \r
        // Attributes that browser may changing them when setting via innerHTML.\r
@@ -540,6 +543,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 /**\r
  * The number of undo steps to be saved. The higher this setting value the more\r
  * memory is used for it.\r
+ * @name CKEDITOR.config.undoStackSize\r
  * @type Number\r
  * @default 20\r
  * @example\r
@@ -552,3 +556,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * @name CKEDITOR.editor#saveSnapshot\r
  * @event\r
  */\r
+\r
+/**\r
+ * Fired before an undo image is to be taken. An undo image represents the\r
+ * editor state at some point. It's saved into an undo store, so the editor is\r
+ * able to recover the editor state on undo and redo operations.\r
+ * @name CKEDITOR.editor#beforeUndoImage\r
+ * @since 3.5.3\r
+ * @see CKEDITOR.editor#afterUndoImage\r
+ * @event\r
+ */\r
+\r
+/**\r
+ * Fired after an undo image is taken. An undo image represents the\r
+ * editor state at some point. It's saved into an undo store, so the editor is\r
+ * able to recover the editor state on undo and redo operations.\r
+ * @name CKEDITOR.editor#afterUndoImage\r
+ * @since 3.5.3\r
+ * @see CKEDITOR.editor#beforeUndoImage\r
+ * @event\r
+ */\r