X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=7750cfcf5ea10b27486760bb3760ee72c94f8973;hb=614511639979907ceb0da3614122a4d8eb963ad4;hp=d783d6652b9cc19811c35340a3ab75462255db45;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index d783d66..7750cfc 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-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -11,6 +11,16 @@ 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 ) ) + last = block.children[ --lastIndex ]; + return last; + } + function trimFillers( block, fromSource ) { // If the current node is a block, and if we're converting from source or @@ -18,8 +28,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // // Also, any   at the end of blocks are fillers, remove them as well. // (#2886) - var children = block.children; - var lastChild = children[ children.length - 1 ]; + var children = block.children, lastChild = lastNoneSpaceChild( block ); if ( lastChild ) { if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' ) @@ -29,20 +38,31 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } - function blockNeedsExtension( block ) + function blockNeedsExtension( block, fromSource ) { - if ( block.children.length < 1 ) - return true; - - var lastChild = block.children[ block.children.length - 1 ]; - return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'; + // 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; + + var lastChild = lastNoneSpaceChild( block ); + + return !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 extendBlockForDisplay( block ) { trimFillers( block, true ); - if ( blockNeedsExtension( block ) ) + if ( blockNeedsExtension( block, true ) ) { if ( CKEDITOR.env.ie ) block.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); @@ -73,6 +93,7 @@ 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 @@ -103,18 +124,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license [ ( /^_cke_(saved|pa)_/ ), '' ], // All "_cke" attributes are to be ignored. - [ ( /^_cke.*/ ), '' ] + [ ( /^_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.cke_temp ) + return false; + + // Remove duplicated attributes - #3789. var attributeNames = [ 'name', 'href', 'src' ], savedAttributeName; for ( var i = 0 ; i < attributeNames.length ; i++ ) @@ -123,6 +150,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] ); } } + + return element; }, embed : function( element ) @@ -156,6 +185,33 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { return false; } + }, + + 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[ '_cke_title' ] || '' ); } }, @@ -170,8 +226,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license comment : function( contents ) { + // If this is a comment for protected source. if ( contents.substr( 0, protectedSourceMarker.length ) == protectedSourceMarker ) - return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents.substr( protectedSourceMarker.length ) ) ); + { + // Remove the extra marker for real comments from it. + if ( contents.substr( protectedSourceMarker.length, 3 ) == '{C}' ) + contents = contents.substr( protectedSourceMarker.length + 3 ); + else + contents = contents.substr( protectedSourceMarker.length ); + + return new CKEDITOR.htmlParser.cdata( decodeURIComponent( contents ) ); + } return contents; } @@ -192,71 +257,130 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }; } - var protectAttributeRegex = /<(?:a|area|img|input).*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi; + function protectReadOnly( element ) + { + element.attributes.contenteditable = "false"; + } + function unprotectReadyOnly( element ) + { + delete element.attributes.contenteditable; + } + // 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 protectAttributeRegex = /<((?:a|area|img|input)\b[\s\S]*?\s)((href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))([^>]*)>/gi, + findSavedSrcRegex = /\s_cke_saved_src\s*=/; + + 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; + + var protectSelfClosingRegex = /]*?)\/?>(?!\s*<\/cke:\1)/gi; function protectAttributes( html ) { - return html.replace( protectAttributeRegex, '$& _cke_saved_$1' ); + return html.replace( protectAttributeRegex, function( tag, beginning, fullAttr, attrName, end ) + { + // We should not rewrite the _cke_saved_src attribute (#5218) + if ( attrName == 'src' && findSavedSrcRegex.test( tag ) ) + return tag; + else + return '<' + beginning + fullAttr + ' _cke_saved_' + fullAttr + end + '>'; + }); } - var protectStyleTagsRegex = /<(style)(?=[ >])[^>]*>[^<]*<\/\1>/gi; - var encodedTagsRegex = /([^<]*)<\/cke:encoded>/gi; - var protectElementNamesRegex = /(<\/?)((?:object|embed|param).*?>)/gi; - var protectSelfClosingRegex = //gi; - - function protectStyleTagsMatch( match ) + 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, '' ); + return html.replace( protectSelfClosingRegex, '' ); + } + + function protectPreFormatted( html ) + { + return html.replace( /(]*>)(\r\n|\n)/g, '$1$2$2' ); } - function unprotectEncodedTagsMatch( match, encoded ) + function protectRealComments( html ) { - return decodeURIComponent( encoded ); + return html.replace( //g, function( match ) + { + return ''; + }); } - function unprotectEncodedTags( html ) + function unprotectRealComments( html ) { - return html.replace( encodedTagsRegex, unprotectEncodedTagsMatch ); + return html.replace( //g, function( match, data ) + { + return decodeURIComponent( data ); + }); } function protectSource( data, protectRegexes ) { var protectedHtml = [], - tempRegex = /<\!--\{cke_temp\}(\d*?)-->/g; + 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 ), //