Ticket #5404: 5404_5.patch

File 5404_5.patch, 4.3 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/htmldataprocessor/plugin.js

     
    3838                }
    3939        }
    4040
    41         function blockNeedsExtension( block, fromSource )
     41        function blockNeedsExtension( block, fromSource, extendEmptyBlock )
    4242        {
     43                if( !extendEmptyBlock ||
     44                        typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) == false ) )
     45                        return false;
     46
    4347        // 1. For IE version >=8,  empty blocks are displayed correctly themself in wysiwiyg;
    4448        // 2. For the rest, at least table cell and list item need no filler space.
    4549        // (#6248)
     
    5155
    5256                var lastChild = lastNoneSpaceChild( block );
    5357
    54                 return !lastChild
    55                         || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'
    56                         // Some of the controls in form needs extension too,
    57                         // to move cursor at the end of the form. (#4791)
    58                         || block.name == 'form' && lastChild.name == 'input';
     58                return !lastChild || lastChild &&
     59                                ( lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'
     60                                // Some of the controls in form needs extension too,
     61                                // to move cursor at the end of the form. (#4791)
     62                                || block.name == 'form' && lastChild.name == 'input' );
    5963        }
    6064
    61         function extendBlockForDisplay( block )
     65        function getBlockExtension( isOutput, emptyBlockFiller )
    6266        {
    63                 trimFillers( block, true );
     67                return function( node )
     68                {
     69                        trimFillers( node, !isOutput );
    6470
    65                 if ( blockNeedsExtension( block, true ) )
    66                 {
    67                         if ( CKEDITOR.env.ie )
    68                                 block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
    69                         else
    70                                 block.add( new CKEDITOR.htmlParser.element( 'br', {} ) );
    71                 }
    72         }
    73 
    74         function extendBlockForOutput( block )
    75         {
    76                 trimFillers( block );
    77 
    78                 if ( blockNeedsExtension( block ) )
    79                         block.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
     71                        if ( blockNeedsExtension( node, !isOutput, emptyBlockFiller ) )
     72                        {
     73                                if ( isOutput || CKEDITOR.env.ie )
     74                                        node.add( new CKEDITOR.htmlParser.text( '\xa0' ) );
     75                                else
     76                                        node.add( new CKEDITOR.htmlParser.element( 'br', {} ) );
     77                        }
     78                }
    8079        }
    8180
    8281        var dtd = CKEDITOR.dtd;
     
    105104        var defaultDataBlockFilterRules = { elements : {} };
    106105
    107106        for ( i in blockLikeTags )
    108                 defaultDataBlockFilterRules.elements[ i ] = extendBlockForDisplay;
     107                defaultDataBlockFilterRules.elements[ i ] = getBlockExtension( false, true );
    109108
    110109        var defaultHtmlFilterRules =
    111110                {
     
    242241                        }
    243242                };
    244243
    245         var defaultHtmlBlockFilterRules = { elements : {} };
    246 
    247         for ( i in blockLikeTags )
    248                 defaultHtmlBlockFilterRules.elements[ i ] = extendBlockForOutput;
    249 
    250244        if ( CKEDITOR.env.ie )
    251245        {
    252246                // IE outputs style attribute in capital letters. We should convert
     
    412406                        dataProcessor.dataFilter.addRules( defaultDataFilterRules );
    413407                        dataProcessor.dataFilter.addRules( defaultDataBlockFilterRules );
    414408                        dataProcessor.htmlFilter.addRules( defaultHtmlFilterRules );
     409
     410                        var defaultHtmlBlockFilterRules = { elements : {} };
     411                        for ( i in blockLikeTags )
     412                                defaultHtmlBlockFilterRules.elements[ i ] = getBlockExtension( true, editor.config.fillEmptyBlocks );
     413
    415414                        dataProcessor.htmlFilter.addRules( defaultHtmlBlockFilterRules );
     415                },
     416               
     417                onLoad : function()
     418                {
     419                        ! ( 'fillEmptyBlocks' in CKEDITOR.config ) && ( CKEDITOR.config.fillEmptyBlocks = 1 );
    416420                }
    417421        });
    418422
     
    510514 * @example
    511515 * config.forceSimpleAmpersand = false;
    512516 */
     517
     518/**
     519 * Whether a filler text (non-breaking space entity -  ) will be inserted into empty block elements in HTML output,
     520 * this is used to render block elements properly with line-height; When a function is instead specified,
     521 * it'll be passed a {@link CKEDITOR.htmlParser.element} to decide whether adding the filler text
     522 * by expecting a boolean return value.
     523 * @name CKEDITOR.config.fillEmptyBlocks;
     524 * @type Boolean|Function
     525 * @default true
     526 * @example
     527 * config.fillEmptyBlocks = false;      // Prevent filler nodes in all empty blocks.
     528 *
     529 * // Prevent filler node only in float cleaners.
     530 * config.fillEmptyBlocks = function( element )
     531 * {
     532 *      if ( element.attributes[ 'class' ].indexOf ( 'clear-both' ) != -1 )
     533 *              return false;
     534 * }
     535 */
     536
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy