X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=ecf87ed45212310349d1f2696abad5e95bdd39b4;hb=2f22c0c38f17e75be5541089076885442aaa2377;hp=01be3582ab96f229c1c50b9c6ae87474fe07de2e;hpb=7cd80714081a8ffdf4a1a8d2c72f120ed5ef3d6d;p=ckeditor.git diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index 01be358..ecf87ed 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -11,13 +11,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var protectedSourceMarker = '{cke_protected}'; - // Return the last non-space child node of the block (#4344). function lastNoneSpaceChild( block ) { var lastIndex = block.children.length, last = block.children[ lastIndex - 1 ]; - while( last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) ) + while ( last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) ) last = block.children[ --lastIndex ]; return last; } @@ -39,35 +38,51 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } - function blockNeedsExtension( block ) + function blockNeedsExtension( block, fromSource, extendEmptyBlock ) { - var lastChild = lastNoneSpaceChild( block ); - return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; - } + if( !fromSource && ( !extendEmptyBlock || + typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) === false ) ) ) + return false; + + // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg; + // 2. For the rest, at least table cell and list item need no filler space. + // (#6248) + if ( fromSource && CKEDITOR.env.ie && + ( document.documentMode > 7 + || block.name in CKEDITOR.dtd.tr + || block.name in CKEDITOR.dtd.$listItem ) ) + return false; - function extendBlockForDisplay( block ) - { - trimFillers( block, true ); + var lastChild = lastNoneSpaceChild( block ); - if ( blockNeedsExtension( block ) ) - { - if ( CKEDITOR.env.ie ) - block.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); - else - block.add( new CKEDITOR.htmlParser.element( 'br', {} ) ); - } + return !lastChild || lastChild && + ( lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' + // Some of the controls in form needs extension too, + // to move cursor at the end of the form. (#4791) + || block.name == 'form' && lastChild.name == 'input' ); } - function extendBlockForOutput( block ) + function getBlockExtension( isOutput, emptyBlockFiller ) { - trimFillers( block ); + return function( node ) + { + trimFillers( node, !isOutput ); - if ( blockNeedsExtension( block ) ) - block.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); + if ( blockNeedsExtension( node, !isOutput, emptyBlockFiller ) ) + { + if ( isOutput || CKEDITOR.env.ie ) + node.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); + else + node.add( new CKEDITOR.htmlParser.element( 'br', {} ) ); + } + }; } var dtd = CKEDITOR.dtd; + // Define orders of table elements. + var tableOrder = [ 'caption', 'colgroup', 'col', 'thead', 'tfoot', 'tbody' ]; + // Find out the list of block-like tags that can contain
. var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ); for ( var i in blockLikeTags ) @@ -80,18 +95,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license delete blockLikeTags.pre; var defaultDataFilterRules = { + elements : {}, attributeNames : [ // Event attributes (onXYZ) must not be directly set. They can become // active in the editing area (IE|WebKit). - [ ( /^on/ ), '_cke_pa_on' ] + [ ( /^on/ ), 'data-cke-pa-on' ] ] }; var defaultDataBlockFilterRules = { elements : {} }; for ( i in blockLikeTags ) - defaultDataBlockFilterRules.elements[ i ] = extendBlockForDisplay; + defaultDataBlockFilterRules.elements[ i ] = getBlockExtension(); var defaultHtmlFilterRules = { @@ -107,29 +123,48 @@ For licensing, see LICENSE.html or http://ckeditor.com/license attributeNames : [ // Attributes saved for changes and protected attributes. - [ ( /^_cke_(saved|pa)_/ ), '' ], + [ ( /^data-cke-(saved|pa)-/ ), '' ], + + // All "data-cke-" attributes are to be ignored. + [ ( /^data-cke-.*/ ), '' ], - // All "_cke" attributes are to be ignored. - [ ( /^_cke.*/ ), '' ] + [ 'hidefocus', '' ] ], elements : { $ : function( element ) { - // Remove duplicated attributes - #3789. var attribs = element.attributes; if ( attribs ) { + // Elements marked as temporary are to be ignored. + if ( attribs[ 'data-cke-temp' ] ) + return false; + + // Remove duplicated attributes - #3789. var attributeNames = [ 'name', 'href', 'src' ], savedAttributeName; for ( var i = 0 ; i < attributeNames.length ; i++ ) { - savedAttributeName = '_cke_saved_' + attributeNames[ i ]; + savedAttributeName = 'data-cke-saved-' + attributeNames[ i ]; savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] ); } } + + return element; + }, + + // The contents of table should be in correct order (#4809). + table : function( element ) + { + var children = element.children; + children.sort( function ( node1, node2 ) + { + return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ? + CKEDITOR.tools.indexOf( tableOrder, node1.name ) > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0; + } ); }, embed : function( element ) @@ -159,10 +194,47 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { if ( !( element.children.length || element.attributes.name || - element.attributes._cke_saved_name ) ) + element.attributes[ 'data-cke-saved-name' ] ) ) { return false; } + }, + + // Remove dummy span in webkit. + span: function( element ) + { + if ( element.attributes[ 'class' ] == 'Apple-style-span' ) + delete element.name; + }, + + // Empty
 in IE is reported with filler node ( ).
+				pre : function( element ) { CKEDITOR.env.ie && trimFillers( element ); },
+
+				html : function( element )
+				{
+					delete element.attributes.contenteditable;
+					delete element.attributes[ 'class' ];
+				},
+
+				body : function( element )
+				{
+					delete element.attributes.spellcheck;
+					delete element.attributes.contenteditable;
+				},
+
+				style : function( element )
+				{
+					var child = element.children[ 0 ];
+					child && child.value && ( child.value = CKEDITOR.tools.trim( child.value ));
+
+					if ( !element.attributes.type )
+						element.attributes.type = 'text/css';
+				},
+
+				title : function( element )
+				{
+					var titleText = element.children[ 0 ];
+					titleText && ( titleText.value = element.attributes[ 'data-cke-title' ] || '' );
 				}
 			},
 
@@ -173,112 +245,206 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 					// Remove all class names starting with "cke_".
 					return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;
 				}
-			},
-
-			comment : function( contents )
-			{
-				if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker )
-					return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents.substr( protectedSourceMarker.length ) ) );
-
-				return contents;
 			}
 		};
 
-	var defaultHtmlBlockFilterRules = { elements : {} };
-
-	for ( i in blockLikeTags )
-		defaultHtmlBlockFilterRules.elements[ i ] = extendBlockForOutput;
-
 	if ( CKEDITOR.env.ie )
 	{
 		// IE outputs style attribute in capital letters. We should convert
-		// them back to lower case.
+		// them back to lower case, while not hurting the values (#5930)
 		defaultHtmlFilterRules.attributes.style = function( value, element )
 		{
-			return value.toLowerCase();
+			return value.replace( /(^|;)([^\:]+)/g, function( match )
+				{
+					return match.toLowerCase();
+				});
 		};
 	}
 
-	var protectAttributeRegex = /<(?:a|area|img|input)[\s\S]*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi;
+	function protectReadOnly( element )
+	{
+		var attrs = element.attributes;
 
-	function protectAttributes( html )
+		// We should flag that the element was locked by our code so
+		// it'll be editable by the editor functions (#6046).
+		if ( attrs.contenteditable != "false" )
+			attrs[ 'data-cke-editable' ] = attrs.contenteditable ? 'true' : 1;
+
+		attrs.contenteditable = "false";
+	}
+	function unprotectReadyOnly( element )
 	{
-		return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );
+		var attrs = element.attributes;
+		switch( attrs[ 'data-cke-editable' ] )
+		{
+			case 'true':	attrs.contenteditable = 'true';	break;
+			case '1':		delete attrs.contenteditable;	break;
+		}
+	}
+	// Disable form elements editing mode provided by some browers. (#5746)
+	for ( i in { input : 1, textarea : 1 } )
+	{
+		defaultDataFilterRules.elements[ i ] = protectReadOnly;
+		defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;
 	}
 
-	var protectStyleTagsRegex = /<(style)(?=[ >])[^>]*>[^<]*<\/\1>/gi;
-	var encodedTagsRegex = /([^<]*)<\/cke:encoded>/gi;
-	var protectElementNamesRegex = /(<\/?)((?:object|embed|param)[\s\S]*?>)/gi;
-	var protectSelfClosingRegex = //gi;
+	var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi,
+		protectAttributeRegex = /\b(on\w+|href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;
+
+	var protectElementsRegex = /(?:])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,
+		encodedElementsRegex = /([^<]*)<\/cke:encoded>/gi;
+
+	var protectElementNamesRegex = /(<\/?)((?:object|embed|param|html|body|head|title)[^>]*>)/gi,
+		unprotectElementNamesRegex = /(<\/?)cke:((?:html|body|head|title)[^>]*>)/gi;
 
-	function protectStyleTagsMatch( match )
+	var protectSelfClosingRegex = /]*?)\/?>(?!\s*<\/cke:\1)/gi;
+
+	function protectAttributes( html )
+	{
+		return html.replace( protectElementRegex, function( element, tag, attributes )
+		{
+			return '<' +  tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName )
+			{
+				// Avoid corrupting the inline event attributes (#7243).
+				// We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)
+				if ( !( /^on/ ).test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )
+					return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr;
+
+				return fullAttr;
+			}) + '>';
+		});
+	}
+
+	function protectElements( html )
 	{
-		return '' + encodeURIComponent( match ) + '';
+		return html.replace( protectElementsRegex, function( match )
+			{
+				return '' + encodeURIComponent( match ) + '';
+			});
 	}
 
-	function protectStyleTags( html )
+	function unprotectElements( html )
 	{
-		return html.replace( protectStyleTagsRegex, protectStyleTagsMatch );
+		return html.replace( encodedElementsRegex, function( match, encoded )
+			{
+				return decodeURIComponent( encoded );
+			});
 	}
+
 	function protectElementsNames( html )
 	{
 		return html.replace( protectElementNamesRegex, '$1cke:$2');
 	}
+
+	function unprotectElementNames( html )
+	{
+		return html.replace( unprotectElementNamesRegex, '$1$2' );
+	}
+
 	function protectSelfClosingElements( html )
 	{
 		return html.replace( protectSelfClosingRegex, '' );
 	}
 
-	function unprotectEncodedTagsMatch( match, encoded )
+	function protectPreFormatted( html )
 	{
-		return decodeURIComponent( encoded );
+		return html.replace( /(]*>)(\r\n|\n)/g, '$1$2$2' );
 	}
 
-	function unprotectEncodedTags( html )
+	function protectRealComments( html )
 	{
-		return html.replace( encodedTagsRegex, unprotectEncodedTagsMatch );
+		return html.replace( //g, function( match )
+			{
+				return '';
+			});
+	}
+
+	function unprotectRealComments( html )
+	{
+		return html.replace( //g, function( match, data )
+			{
+				return decodeURIComponent( data );
+			});
+	}
+
+	function unprotectSource( html, editor )
+	{
+		var store = editor._.dataStore;
+
+		return html.replace( //g, function( match, data )
+			{
+				return decodeURIComponent( data );
+			}).replace( /\{cke_protected_(\d+)\}/g, function( match, id )
+			{
+				return store && store[ id ] || '';
+			});
 	}
 
-	function protectSource( data, protectRegexes )
+	function protectSource( data, editor )
 	{
 		var protectedHtml = [],
-			tempRegex = /<\!--\{cke_temp\}(\d*?)-->/g;
+			protectRegexes = editor.config.protectedSource,
+			store = editor._.dataStore || ( editor._.dataStore = { id : 1 } ),
+			tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g;
+
 		var regexes =
 			[
-				// First of any other protection, we must protect all comments
-				// to avoid loosing them (of course, IE related).
-				(//g),
-
 				// Script tags will also be forced to be protected, otherwise
 				// IE will execute them.
-				//gi,
+				( //gi ),
 
 				//