JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.1
[ckeditor.git] / _source / plugins / htmldataprocessor / plugin.js
index f9b5dea..a460bba 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -92,7 +92,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        delete blockLikeTags.pre;\r
        var defaultDataFilterRules =\r
        {\r
-               elements : {},\r
+               elements : {\r
+                       a : function( element )\r
+                       {\r
+                               var attrs = element.attributes;\r
+                               if ( attrs && attrs[ 'data-cke-saved-name' ] )\r
+                                       attrs[ 'class' ] = ( attrs[ 'class' ] ? attrs[ 'class' ] + ' ' : '' ) + 'cke_anchor';\r
+                       }\r
+               },\r
                attributeNames :\r
                [\r
                        // Event attributes (onXYZ) must not be directly set. They can become\r
@@ -122,8 +129,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // Attributes saved for changes and protected attributes.\r
                                [ ( /^data-cke-(saved|pa)-/ ), '' ],\r
 \r
-                               // All "data-cke" attributes are to be ignored.\r
-                               [ ( /^data-cke.*/ ), '' ],\r
+                               // All "data-cke-" attributes are to be ignored.\r
+                               [ ( /^data-cke-.*/ ), '' ],\r
 \r
                                [ 'hidefocus', '' ]\r
                        ],\r
@@ -193,6 +200,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                delete element.name;\r
                                },\r
 \r
+                               // Empty <pre> in IE is reported with filler node (&nbsp;).\r
+                               pre : function( element ) { CKEDITOR.env.ie && trimFillers( element ); },\r
+\r
                                html : function( element )\r
                                {\r
                                        delete element.attributes.contenteditable;\r
@@ -251,20 +261,35 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        if ( CKEDITOR.env.ie )\r
        {\r
                // IE outputs style attribute in capital letters. We should convert\r
-               // them back to lower case.\r
+               // them back to lower case, while not hurting the values (#5930)\r
                defaultHtmlFilterRules.attributes.style = function( value, element )\r
                {\r
-                       return value.toLowerCase();\r
+                       return value.replace( /(^|;)([^\:]+)/g, function( match )\r
+                               {\r
+                                       return match.toLowerCase();\r
+                               });\r
                };\r
        }\r
 \r
        function protectReadOnly( element )\r
        {\r
-               element.attributes.contenteditable = "false";\r
+               var attrs = element.attributes;\r
+\r
+               // We should flag that the element was locked by our code so\r
+               // it'll be editable by the editor functions (#6046).\r
+               if ( attrs.contenteditable != "false" )\r
+                       attrs[ 'data-cke-editable' ] = attrs.contenteditable ? 'true' : 1;\r
+\r
+               attrs.contenteditable = "false";\r
        }\r
        function unprotectReadyOnly( element )\r
        {\r
-               delete element.attributes.contenteditable;\r
+               var attrs = element.attributes;\r
+               switch( attrs[ 'data-cke-editable' ] )\r
+               {\r
+                       case 'true':    attrs.contenteditable = 'true'; break;\r
+                       case '1':               delete attrs.contenteditable;   break;\r
+               }\r
        }\r
        // Disable form elements editing mode provided by some browers. (#5746)\r
        for ( i in { input : 1, textarea : 1 } )\r
@@ -273,8 +298,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;\r
        }\r
 \r
-       var protectAttributeRegex = /<((?:a|area|img|input)\b[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi,\r
-               findSavedSrcRegex = /\sdata-cke-saved-src\s*=/;\r
+       var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi,\r
+               protectAttributeRegex = /\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;\r
 \r
        var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,\r
                encodedElementsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;\r
@@ -286,14 +311,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        function protectAttributes( html )\r
        {\r
-               return html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end )\r
+               return html.replace( protectElementRegex, function( element, tag, attributes )\r
+               {\r
+                       return '<' +  tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName )\r
                        {\r
-                               // We should not rewrite the _cke_saved_src attribute (#5218)\r
-                               if ( attrName == 'src' && findSavedSrcRegex.test( tag ) )\r
-                                       return tag;\r
-                               else\r
-                                       return '<' + beginning + fullAttr + ' data-cke-saved-' + fullAttr + end + '>';\r
-                       });\r
+                               // We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)\r
+                               if ( attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )\r
+                                       return ' data-cke-saved-' + fullAttr + ' ' + fullAttr;\r
+\r
+                               return fullAttr;\r
+                       }) + '>';\r
+               });\r
        }\r
 \r
        function protectElements( html )\r