/*\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
}\r
}\r
\r
- function blockNeedsExtension( block )\r
+ function blockNeedsExtension( block, fromSource, extendEmptyBlock )\r
{\r
- var lastChild = lastNoneSpaceChild( block );\r
- return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';\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
+ if ( fromSource && CKEDITOR.env.ie &&\r
+ ( document.documentMode > 7\r
+ || block.name in CKEDITOR.dtd.tr\r
+ || block.name in CKEDITOR.dtd.$listItem ) )\r
+ return false;\r
\r
- function extendBlockForDisplay( block )\r
- {\r
- trimFillers( block, true );\r
+ var lastChild = lastNoneSpaceChild( block );\r
\r
- if ( blockNeedsExtension( block ) )\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
+ 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 extendBlockForOutput( block )\r
+ function getBlockExtension( isOutput, emptyBlockFiller )\r
{\r
- trimFillers( block );\r
+ return function( node )\r
+ {\r
+ trimFillers( node, !isOutput );\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
delete blockLikeTags.pre;\r
var defaultDataFilterRules =\r
{\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
// 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
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
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
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
{\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
+ // Empty <pre> in IE is reported with filler node ( ).\r
+ pre : function( element ) { CKEDITOR.env.ie && trimFillers( element ); },\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
\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[ 'data-cke-title' ] || '' );\r
}\r
},\r
\r
}\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
- // 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
- var protectAttributeRegex = /<(?:a|area|img|input)[\s\S]*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi;\r
+ function protectReadOnly( element )\r
+ {\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
+ 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
+ {\r
+ defaultDataFilterRules.elements[ i ] = protectReadOnly;\r
+ defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;\r
+ }\r
+\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
\r
function protectAttributes( html )\r
{\r
- return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );\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 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
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
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
// 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
\r
/**\r
* Whether to force using "&" instead of "&amp;" in elements attributes\r
- * values. It's not recommended to change this setting for compliance with the\r
- * W3C XHTML 1.0 standards\r
- * (<a href="http://www.w3.org/TR/xhtml1/#C_12">C.12, XHTML 1.0</a>).\r
+ * 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
-CKEDITOR.config.forceSimpleAmpersand = false;\r
+\r
+/**\r
+ * Whether a filler text (non-breaking space entity - ) 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