JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5
[ckeditor.git] / _source / plugins / htmldataprocessor / plugin.js
index 7750cfc..f9b5dea 100644 (file)
@@ -38,8 +38,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                }\r
        }\r
 \r
-       function blockNeedsExtension( block, fromSource )\r
+       function blockNeedsExtension( block, fromSource, extendEmptyBlock )\r
        {\r
+               if( !fromSource && ( !extendEmptyBlock ||\r
+                       typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) === false ) ) )\r
+                       return false;\r
+\r
         // 1. For IE version >=8,  empty blocks are displayed correctly themself in wysiwiyg;\r
         // 2. For the rest, at least table cell and list item need no filler space.\r
         // (#6248)\r
@@ -51,32 +55,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                var lastChild = lastNoneSpaceChild( block );\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
+               return !lastChild || 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
+       function getBlockExtension( isOutput, emptyBlockFiller )\r
        {\r
-               trimFillers( block, true );\r
-\r
-               if ( blockNeedsExtension( block, true ) )\r
+               return function( node )\r
                {\r
-                       if ( CKEDITOR.env.ie )\r
-                               block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );\r
-                       else\r
-                               block.add( new CKEDITOR.htmlParser.element( 'br', {} ) );\r
-               }\r
-       }\r
+                       trimFillers( node, !isOutput );\r
 \r
-       function extendBlockForOutput( block )\r
-       {\r
-               trimFillers( block );\r
-\r
-               if ( blockNeedsExtension( block ) )\r
-                       block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );\r
+                       if ( blockNeedsExtension( node, !isOutput, emptyBlockFiller ) )\r
+                       {\r
+                               if ( isOutput || CKEDITOR.env.ie )\r
+                                       node.add( new CKEDITOR.htmlParser.text( '\xa0' ) );\r
+                               else\r
+                                       node.add( new CKEDITOR.htmlParser.element( 'br', {} ) );\r
+                       }\r
+               };\r
        }\r
 \r
        var dtd = CKEDITOR.dtd;\r
@@ -98,14 +97,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                [\r
                        // Event attributes (onXYZ) must not be directly set. They can become\r
                        // active in the editing area (IE|WebKit).\r
-                       [ ( /^on/ ), '_cke_pa_on' ]\r
+                       [ ( /^on/ ), 'data-cke-pa-on' ]\r
                ]\r
        };\r
 \r
        var defaultDataBlockFilterRules = { elements : {} };\r
 \r
        for ( i in blockLikeTags )\r
-               defaultDataBlockFilterRules.elements[ i ] = extendBlockForDisplay;\r
+               defaultDataBlockFilterRules.elements[ i ] = getBlockExtension();\r
 \r
        var defaultHtmlFilterRules =\r
                {\r
@@ -121,10 +120,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        attributeNames :\r
                        [\r
                                // Attributes saved for changes and protected attributes.\r
-                               [ ( /^_cke_(saved|pa)_/ ), '' ],\r
+                               [ ( /^data-cke-(saved|pa)-/ ), '' ],\r
 \r
-                               // All "_cke" attributes are to be ignored.\r
-                               [ ( /^_cke.*/ ), '' ],\r
+                               // All "data-cke" attributes are to be ignored.\r
+                               [ ( /^data-cke.*/ ), '' ],\r
 \r
                                [ 'hidefocus', '' ]\r
                        ],\r
@@ -138,7 +137,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        if ( attribs )\r
                                        {\r
                                                // Elements marked as temporary are to be ignored.\r
-                                               if ( attribs.cke_temp )\r
+                                               if ( attribs[ 'data-cke-temp' ] )\r
                                                        return false;\r
 \r
                                                // Remove duplicated attributes - #3789.\r
@@ -146,7 +145,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        savedAttributeName;\r
                                                for ( var i = 0 ; i < attributeNames.length ; i++ )\r
                                                {\r
-                                                       savedAttributeName = '_cke_saved_' + attributeNames[ i ];\r
+                                                       savedAttributeName = 'data-cke-saved-' + attributeNames[ i ];\r
                                                        savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] );\r
                                                }\r
                                        }\r
@@ -181,12 +180,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                {\r
                                        if ( !( element.children.length ||\r
                                                        element.attributes.name ||\r
-                                                       element.attributes._cke_saved_name ) )\r
+                                                       element.attributes[ 'data-cke-saved-name' ] ) )\r
                                        {\r
                                                return false;\r
                                        }\r
                                },\r
 \r
+                               // Remove dummy span in webkit.\r
+                               span: function( element )\r
+                               {\r
+                                       if ( element.attributes[ 'class' ] == 'Apple-style-span' )\r
+                                               delete element.name;\r
+                               },\r
+\r
                                html : function( element )\r
                                {\r
                                        delete element.attributes.contenteditable;\r
@@ -211,7 +217,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                title : function( element )\r
                                {\r
                                        var titleText = element.children[ 0 ];\r
-                                       titleText && ( titleText.value = element.attributes[ '_cke_title' ] || '' );\r
+                                       titleText && ( titleText.value = element.attributes[ 'data-cke-title' ] || '' );\r
                                }\r
                        },\r
 \r
@@ -242,11 +248,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        }\r
                };\r
 \r
-       var defaultHtmlBlockFilterRules = { elements : {} };\r
-\r
-       for ( i in blockLikeTags )\r
-               defaultHtmlBlockFilterRules.elements[ i ] = extendBlockForOutput;\r
-\r
        if ( CKEDITOR.env.ie )\r
        {\r
                // IE outputs style attribute in capital letters. We should convert\r
@@ -273,7 +274,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        }\r
 \r
        var protectAttributeRegex = /<((?:a|area|img|input)\b[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi,\r
-               findSavedSrcRegex = /\s_cke_saved_src\s*=/;\r
+               findSavedSrcRegex = /\sdata-cke-saved-src\s*=/;\r
 \r
        var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,\r
                encodedElementsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;\r
@@ -291,7 +292,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                if ( attrName == 'src' && findSavedSrcRegex.test( tag ) )\r
                                        return tag;\r
                                else\r
-                                       return '<' + beginning + fullAttr + ' _cke_saved_' + fullAttr + end + '>';\r
+                                       return '<' + beginning + fullAttr + ' data-cke-saved-' + fullAttr + end + '>';\r
                        });\r
        }\r
 \r
@@ -412,7 +413,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        dataProcessor.dataFilter.addRules( defaultDataFilterRules );\r
                        dataProcessor.dataFilter.addRules( defaultDataBlockFilterRules );\r
                        dataProcessor.htmlFilter.addRules( defaultHtmlFilterRules );\r
+\r
+                       var defaultHtmlBlockFilterRules = { elements : {} };\r
+                       for ( i in blockLikeTags )\r
+                               defaultHtmlBlockFilterRules.elements[ i ] = getBlockExtension( true, editor.config.fillEmptyBlocks );\r
+\r
                        dataProcessor.htmlFilter.addRules( defaultHtmlBlockFilterRules );\r
+               },\r
+\r
+               onLoad : function()\r
+               {\r
+                       ! ( 'fillEmptyBlocks' in CKEDITOR.config ) && ( CKEDITOR.config.fillEmptyBlocks = 1 );\r
                }\r
        });\r
 \r
@@ -504,8 +515,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
  * values, it's not recommended to change this setting for compliance with the\r
  * W3C XHTML 1.0 standards (<a href="http://www.w3.org/TR/xhtml1/#C_12">C.12, XHTML 1.0</a>).\r
  * @name CKEDITOR.config.forceSimpleAmpersand\r
+ * @name CKEDITOR.config.forceSimpleAmpersand\r
  * @type Boolean\r
  * @default false\r
  * @example\r
  * config.forceSimpleAmpersand = false;\r
  */\r
+\r
+/**\r
+ * Whether a filler text (non-breaking space entity - &nbsp;) will be inserted into empty block elements in HTML output,\r
+ * this is used to render block elements properly with line-height; When a function is instead specified,\r
+ * it'll be passed a {@link CKEDITOR.htmlParser.element} to decide whether adding the filler text\r
+ * by expecting a boolean return value.\r
+ * @name CKEDITOR.config.fillEmptyBlocks\r
+ * @since 3.5\r
+ * @type Boolean\r
+ * @default true\r
+ * @example\r
+ * config.fillEmptyBlocks = false;     // Prevent filler nodes in all empty blocks.\r
+ *\r
+ * // Prevent filler node only in float cleaners.\r
+ * config.fillEmptyBlocks = function( element )\r
+ * {\r
+ *     if ( element.attributes[ 'class' ].indexOf ( 'clear-both' ) != -1 )\r
+ *             return false;\r
+ * }\r
+ */\r