JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / core / htmlparser / element.js
index 84a452e..b1d5547 100644 (file)
@@ -60,6 +60,61 @@ CKEDITOR.htmlParser.element = function( name, attributes )
        };\r
 };\r
 \r
+/**\r
+ *  Object presentation of  CSS style declaration text.\r
+ *  @param {CKEDITOR.htmlParser.element|String} elementOrStyleText A html parser element or the inline style text.\r
+ */\r
+CKEDITOR.htmlParser.cssStyle = function()\r
+{\r
+        var styleText,\r
+               arg = arguments[ 0 ],\r
+               rules = {};\r
+\r
+       styleText = arg instanceof CKEDITOR.htmlParser.element ? arg.attributes.style : arg;\r
+\r
+       // html-encoded quote might be introduced by 'font-family'\r
+       // from MS-Word which confused the following regexp. e.g.\r
+       //'font-family: "Lucida, Console"'\r
+       ( styleText || '' )\r
+               .replace( /"/g, '"' )\r
+               .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,\r
+                       function( match, name, value )\r
+                       {\r
+                               name == 'font-family' && ( value = value.replace( /["']/g, '' ) );\r
+                               rules[ name.toLowerCase() ] = value;\r
+                       });\r
+\r
+       return {\r
+\r
+               rules : rules,\r
+\r
+               /**\r
+                *  Apply the styles onto the specified element or object.\r
+                * @param {CKEDITOR.htmlParser.element|CKEDITOR.dom.element|Object} obj\r
+                */\r
+               populate : function( obj )\r
+               {\r
+                       var style = this.toString();\r
+                       if ( style )\r
+                       {\r
+                               obj instanceof CKEDITOR.dom.element ?\r
+                                       obj.setAttribute( 'style', style ) :\r
+                                       obj instanceof CKEDITOR.htmlParser.element ?\r
+                                               obj.attributes.style = style :\r
+                                               obj.style = style;\r
+                       }\r
+               },\r
+\r
+               toString : function()\r
+               {\r
+                       var output = [];\r
+                       for ( var i in rules )\r
+                               rules[ i ] && output.push( i, ':', rules[ i ], ';' );\r
+                       return output.join( '' );\r
+               }\r
+       };\r
+};\r
+\r
 (function()\r
 {\r
        // Used to sort attribute entries in an array, where the first element of\r
@@ -163,6 +218,10 @@ CKEDITOR.htmlParser.element = function( name, attributes )
                                        // filter but not the children.\r
                                        if ( !writeName )\r
                                        {\r
+                                               // Fix broken parent refs.\r
+                                               for ( var c = 0, length = this.children.length ; c < length ; c++ )\r
+                                                       this.children[ c ].parent = element.parent;\r
+\r
                                                this.writeChildrenHtml.call( element, writer, isChildrenFiltered ? null : filter );\r
                                                return;\r
                                        }\r