JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / plugins / htmldataprocessor / plugin.js
index 47bdb7c..f8cf91d 100644 (file)
@@ -16,7 +16,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        {\r
                var lastIndex = block.children.length,\r
                        last = block.children[ lastIndex - 1 ];\r
-               while(  last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) )\r
+               while (  last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) )\r
                        last = block.children[ --lastIndex ];\r
                return last;\r
        }\r
@@ -41,7 +41,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        function blockNeedsExtension( block )\r
        {\r
                var lastChild = lastNoneSpaceChild( block );\r
-               return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';\r
+\r
+               return !lastChild\r
+                       || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'\r
+                       // Some of the controls in form needs extension too,\r
+                       // to move cursor at the end of the form. (#4791)\r
+                       || block.name == 'form' && lastChild.name == 'input';\r
        }\r
 \r
        function extendBlockForDisplay( block )\r
@@ -79,6 +84,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        delete blockLikeTags.pre;\r
        var defaultDataFilterRules =\r
        {\r
+               elements : {},\r
                attributeNames :\r
                [\r
                        // Event attributes (onXYZ) must not be directly set. They can become\r
@@ -172,6 +178,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        }\r
                                },\r
 \r
+                               html : function( element )\r
+                               {\r
+                                       delete element.attributes.contenteditable;\r
+                                       delete element.attributes[ 'class' ];\r
+                               },\r
+\r
                                body : function( element )\r
                                {\r
                                        delete element.attributes.spellcheck;\r
@@ -185,6 +197,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                        if ( !element.attributes.type )\r
                                                element.attributes.type = 'text/css';\r
+                               },\r
+\r
+                               title : function( element )\r
+                               {\r
+                                       var titleText = element.children[ 0 ];\r
+                                       titleText && ( titleText.value = element.attributes[ '_cke_title' ] || '' );\r
                                }\r
                        },\r
 \r
@@ -230,7 +248,23 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                };\r
        }\r
 \r
-       var protectAttributeRegex = /<(?:a|area|img|input)[\s\S]*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi;\r
+       function protectReadOnly( element )\r
+       {\r
+               element.attributes.contenteditable = "false";\r
+       }\r
+       function unprotectReadyOnly( element )\r
+       {\r
+               delete element.attributes.contenteditable;\r
+       }\r
+       // Disable form elements editing mode provided by some browers. (#5746)\r
+       for ( i in { input : 1, textarea : 1 } )\r
+       {\r
+               defaultDataFilterRules.elements[ i ] = protectReadOnly;\r
+               defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;\r
+       }\r
+\r
+       var protectAttributeRegex = /<((?:a|area|img|input)[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi,\r
+               findSavedSrcRegex = /\s_cke_saved_src\s*=/;\r
 \r
        var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,\r
                encodedElementsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;\r
@@ -242,7 +276,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        function protectAttributes( html )\r
        {\r
-               return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );\r
+               return html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end )\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 + ' _cke_saved_' + fullAttr + end + '>';\r
+                       });\r
        }\r
 \r
        function protectElements( html )\r
@@ -276,6 +317,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                return html.replace( protectSelfClosingRegex, '<cke:$1$2></cke:$1>' );\r
        }\r
 \r
+       function protectPreFormatted( html )\r
+       {\r
+               return html.replace( /(<pre\b[^>]*>)(\r\n|\n)/g, '$1$2$2' );\r
+       }\r
+\r
        function protectRealComments( html )\r
        {\r
                return html.replace( /<!--(?!{cke_protected})[\s\S]+?-->/g, function( match )\r
@@ -396,6 +442,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // protecting them into open-close. (#3591)\r
                        data = protectSelfClosingElements( data );\r
 \r
+                       // Compensate one leading line break after <pre> open as browsers\r
+                       // eat it up. (#5789)\r
+                       data = protectPreFormatted( data );\r
+\r
                        // Call the browser to help us fixing a possibly invalid HTML\r
                        // structure.\r
                        var div = new CKEDITOR.dom.element( 'div' );\r
@@ -450,4 +500,3 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * @example\r
  * config.forceSimpleAmpersand = false;\r
  */\r
-CKEDITOR.config.forceSimpleAmpersand = false;\r