JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / fakeobjects / plugin.js
index 58c5bcd..14f0357 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
@@ -11,15 +11,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        $ : function( element )\r
                        {\r
-                               var realHtml = element.attributes._cke_realelement,\r
+                               var attributes = element.attributes,\r
+                                       realHtml = attributes && attributes._cke_realelement,\r
                                        realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),\r
                                        realElement = realFragment && realFragment.children[ 0 ];\r
 \r
-                               if ( realElement )\r
+                               // If we have width/height in the element, we must move it into\r
+                               // the real element.\r
+                               if ( realElement && element.attributes._cke_resizable )\r
                                {\r
-                                       // If we have width/height in the element, we must move it into\r
-                                       // the real element.\r
-\r
                                        var style = element.attributes.style;\r
 \r
                                        if ( style )\r
@@ -63,15 +63,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )\r
 {\r
        var lang = this.lang.fakeobjects;\r
+\r
        var attributes =\r
        {\r
                'class' : className,\r
                src : CKEDITOR.getUrl( 'images/spacer.gif' ),\r
                _cke_realelement : encodeURIComponent( realElement.getOuterHtml() ),\r
+               _cke_real_node_type : realElement.type,\r
                alt : lang[ realElementType ] || lang.unknown\r
        };\r
+\r
        if ( realElementType )\r
                attributes._cke_real_element_type = realElementType;\r
+\r
        if ( isResizable )\r
                attributes._cke_resizable = isResizable;\r
 \r
@@ -80,18 +84,19 @@ CKEDITOR.editor.prototype.createFakeElement = function( realElement, className,
 \r
 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )\r
 {\r
-       var writer = new CKEDITOR.htmlParser.basicWriter();\r
+       var lang = this.lang.fakeobjects,\r
+               html;\r
 \r
+       var writer = new CKEDITOR.htmlParser.basicWriter();\r
        realElement.writeHtml( writer );\r
-\r
-       var html = writer.getHtml();\r
-       var lang = this.lang.fakeobjects;\r
+       html = writer.getHtml();\r
 \r
        var attributes =\r
        {\r
                'class' : className,\r
                src : CKEDITOR.getUrl( 'images/spacer.gif' ),\r
                _cke_realelement : encodeURIComponent( html ),\r
+               _cke_real_node_type : realElement.type,\r
                alt : lang[ realElementType ] || lang.unknown\r
        };\r
 \r
@@ -106,6 +111,10 @@ CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, class
 \r
 CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )\r
 {\r
-       var html = decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) );\r
-       return CKEDITOR.dom.element.createFromHtml( html, this.document );\r
+       if ( fakeElement.getAttribute( '_cke_real_node_type' ) != CKEDITOR.NODE_ELEMENT )\r
+               return null;\r
+\r
+       return CKEDITOR.dom.element.createFromHtml(\r
+               decodeURIComponent( fakeElement.getAttribute( '_cke_realelement' ) ),\r
+               this.document );\r
 };\r