JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / undo / plugin.js
index e013a9d..4909cad 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -130,11 +130,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        this.contents = this.contents.replace( /\s+_cke_expando=".*?"/g, '' );\r
        }\r
 \r
+       // Attributes that browser may changing them when setting via innerHTML.\r
+       var protectedAttrs = /\b(?:href|src|name)="[^"]*?"/gi;\r
+\r
        Image.prototype =\r
        {\r
                equals : function( otherImage, contentOnly )\r
                {\r
-                       if ( this.contents != otherImage.contents )\r
+                       var thisContents = this.contents,\r
+                               otherContents = otherImage.contents;\r
+\r
+                       // For IE6/7 : Comparing only the protected attribute values but not the original ones.(#4522)\r
+                       if( CKEDITOR.env.ie && ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) )\r
+                       {\r
+                               thisContents = thisContents.replace( protectedAttrs, '' );\r
+                               otherContents = otherContents.replace( protectedAttrs, '' );\r
+                       }\r
+\r
+                       if( thisContents != otherContents )\r
                                return false;\r
 \r
                        if ( contentOnly )\r
@@ -179,6 +192,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                this.reset();\r
        }\r
 \r
+\r
+       var editingKeyCodes = { /*Backspace*/ 8:1, /*Delete*/ 46:1 },\r
+               modifierKeyCodes = { /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1 },\r
+               navigationKeyCodes = { 37:1, 38:1, 39:1, 40:1 };  // Arrows: L, T, R, B\r
+\r
        UndoManager.prototype =\r
        {\r
                /**\r
@@ -187,32 +205,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                 */\r
                type : function( event )\r
                {\r
-                       var keystroke = event && event.data.getKeystroke(),\r
-\r
-                               // Backspace, Delete\r
-                               modifierCodes = { 8:1, 46:1 },\r
-                               // Keystrokes which will modify the contents.\r
-                               isModifier = keystroke in modifierCodes,\r
-                               wasModifier = this.lastKeystroke in modifierCodes,\r
-                               lastWasSameModifier = isModifier && keystroke == this.lastKeystroke,\r
-\r
-                               // Arrows: L, T, R, B\r
-                               resetTypingCodes = { 37:1, 38:1, 39:1, 40:1 },\r
+                       var keystroke = event && event.data.getKey(),\r
+                               isModifierKey = keystroke in modifierKeyCodes,\r
+                               isEditingKey = keystroke in editingKeyCodes,\r
+                               wasEditingKey = this.lastKeystroke in editingKeyCodes,\r
+                               sameAsLastEditingKey = isEditingKey && keystroke == this.lastKeystroke,\r
                                // Keystrokes which navigation through contents.\r
-                               isReset = keystroke in resetTypingCodes,\r
-                               wasReset = this.lastKeystroke in resetTypingCodes,\r
+                               isReset = keystroke in navigationKeyCodes,\r
+                               wasReset = this.lastKeystroke in navigationKeyCodes,\r
 \r
                                // Keystrokes which just introduce new contents.\r
-                               isContent = ( !isModifier && !isReset ),\r
+                               isContent = ( !isEditingKey && !isReset ),\r
 \r
                                // Create undo snap for every different modifier key.\r
-                               modifierSnapshot = ( isModifier && !lastWasSameModifier ),\r
+                               modifierSnapshot = ( isEditingKey && !sameAsLastEditingKey ),\r
                                // Create undo snap on the following cases:\r
-                               // 1. Just start to type.\r
+                               // 1. Just start to type .\r
                                // 2. Typing some content after a modifier.\r
                                // 3. Typing some content after make a visible selection.\r
-                               startedTyping = !this.typing\r
-                                       || ( isContent && ( wasModifier || wasReset ) );\r
+                               startedTyping = !( isModifierKey || this.typing )\r
+                                       || ( isContent && ( wasEditingKey || wasReset ) );\r
 \r
                        if ( startedTyping || modifierSnapshot )\r
                        {\r
@@ -230,6 +242,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                if ( beforeTypeImage.contents != currentSnapshot )\r
                                                {\r
+                                                       // It's safe to now indicate typing state.\r
+                                                       this.typing = true;\r
+\r
                                                        // This's a special save, with specified snapshot\r
                                                        // and without auto 'fireChange'.\r
                                                        if ( !this.save( false, beforeTypeImage, false ) )\r
@@ -250,15 +265,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
 \r
                        this.lastKeystroke = keystroke;\r
+\r
                        // Create undo snap after typed too much (over 25 times).\r
-                       if ( isModifier )\r
+                       if ( isEditingKey )\r
                        {\r
                                this.typesCount = 0;\r
                                this.modifiersCount++;\r
 \r
                                if ( this.modifiersCount > 25 )\r
                                {\r
-                                       this.save();\r
+                                       this.save( false, null, false );\r
                                        this.modifiersCount = 1;\r
                                }\r
                        }\r
@@ -269,12 +285,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                if ( this.typesCount > 25 )\r
                                {\r
-                                       this.save();\r
+                                       this.save( false, null, false );\r
                                        this.typesCount = 1;\r
                                }\r
                        }\r
 \r
-                       this.typing = true;\r
                },\r
 \r
                reset : function()      // Reset the undo stack.\r