X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fplugins%2Fhtmldataprocessor%2Fplugin.js;h=a460bba57ef742079d4cbb243195a1f562f79af8;hb=48b1db88210b4160dce439c6e3e32e14af8c106b;hp=ad3852d7aed0b67b97b697b7e22eda635dce85ce;hpb=66f4ae0bf0280ed56bf7c0f4ab175424dd1d47a0;p=ckeditor.git diff --git a/_source/plugins/htmldataprocessor/plugin.js b/_source/plugins/htmldataprocessor/plugin.js index ad3852d..a460bba 100644 --- a/_source/plugins/htmldataprocessor/plugin.js +++ b/_source/plugins/htmldataprocessor/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -38,36 +38,44 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } } - function blockNeedsExtension( block ) + function blockNeedsExtension( block, fromSource, extendEmptyBlock ) { + 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; + 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'; + 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 extendBlockForDisplay( block ) + function getBlockExtension( isOutput, emptyBlockFiller ) { - trimFillers( block, true ); - - if ( blockNeedsExtension( block ) ) + return function( node ) { - if ( CKEDITOR.env.ie ) - block.add( new CKEDITOR.htmlParser.text( '\xa0' ) ); - else - block.add( new CKEDITOR.htmlParser.element( 'br', {} ) ); - } - } - - function extendBlockForOutput( block ) - { - trimFillers( block ); + 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; @@ -84,19 +92,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license delete blockLikeTags.pre; var defaultDataFilterRules = { - elements : {}, + elements : { + a : function( element ) + { + var attrs = element.attributes; + if ( attrs && attrs[ 'data-cke-saved-name' ] ) + attrs[ 'class' ] = ( attrs[ 'class' ] ? attrs[ 'class' ] + ' ' : '' ) + 'cke_anchor'; + } + }, 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 = { @@ -112,10 +127,10 @@ 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 "_cke" attributes are to be ignored. - [ ( /^_cke.*/ ), '' ], + // All "data-cke-" attributes are to be ignored. + [ ( /^data-cke-.*/ ), '' ], [ 'hidefocus', '' ] ], @@ -129,7 +144,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( attribs ) { // Elements marked as temporary are to be ignored. - if ( attribs.cke_temp ) + if ( attribs[ 'data-cke-temp' ] ) return false; // Remove duplicated attributes - #3789. @@ -137,7 +152,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license 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 ] ] ); } } @@ -172,12 +187,22 @@ 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; @@ -201,7 +226,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license title : function( element ) { - element.children[ 0 ].value = element.attributes[ '_cke_title' ]; + var titleText = element.children[ 0 ]; + titleText && ( titleText.value = element.attributes[ 'data-cke-title' ] || '' ); } }, @@ -232,28 +258,38 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }; - 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(); + }); }; } function protectReadOnly( element ) { - element.attributes.contenteditable = "false"; + var attrs = element.attributes; + + // 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 ) { - delete element.attributes.contenteditable; + 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 } ) @@ -262,7 +298,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly; } - var protectAttributeRegex = /<(?:a|area|img|input)[\s\S]*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi; + var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi, + protectAttributeRegex = /\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi; var protectElementsRegex = /(?: