Ticket #5479: 5479_11.patch

File 5479_11.patch, 7.3 KB (added by Garry Yao, 13 years ago)
  • _source/core/dom/element.js

     
    234234                                this.append( new CKEDITOR.dom.text( text ) );
    235235                },
    236236
    237                 appendBogus : function()
    238                 {
    239                         var lastChild = this.getLast() ;
    240 
    241                         // Ignore empty/spaces text.
    242                         while ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.rtrim( lastChild.getText() ) )
    243                                 lastChild = lastChild.getPrevious();
    244                         if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )
    245                         {
    246                                 var bogus = CKEDITOR.env.opera ?
    247                                                 this.getDocument().createText('') :
    248                                                 this.getDocument().createElement( 'br' );
    249 
    250                                 CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );
    251 
    252                                 this.append( bogus );
    253                         }
    254                 },
    255 
    256237                /**
    257238                * Retrieve block element's filler node if existed.
    258239                */
  • _source/core/dom/walker.js

     
    449449                return false;
    450450        };
    451451
     452        // Append a filler node at the end of an element if not exists.
     453        CKEDITOR.dom.element.prototype.appendBogus = function()
     454        {
     455                var lastChild = this.getLast( fillerEvaluator ) ;
     456                if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )
     457                {
     458                        var bogus = CKEDITOR.env.opera ?
     459                                        this.getDocument().createText('') :
     460                                        this.getDocument().createElement( 'br' );
     461
     462                        CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );
     463
     464                        this.append( bogus );
     465                }
     466        };
     467
     468
    452469})();
  • _source/plugins/wysiwygarea/plugin.js

     
    3838
    3939                                insertFunc.call( this, evt.data );
    4040
     41                                paddingBody( this );
     42
    4143                                // Save snaps after the whole execution completed.
    4244                                // This's a workaround for make DOM modification's happened after
    4345                                // 'insertElement' to be included either, e.g. Form-based dialogs' 'commitContents'
     
    304306                return block.getOuterHtml().match( emptyParagraphRegexp );
    305307        }
    306308
    307         isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
    308 
    309309        // Gecko need a key event to 'wake up' the editing
    310310        // ability when document is empty.(#3864, #5781)
    311311        function activateEditing( editor )
     
    343343                }
    344344        }
    345345
     346        function paddingBody( editor )
     347        {
     348                // All browsers are incapable to moving cursor out of certain non-exitable
     349                // blocks (e.g. table, list, pre) at the end of document, make this happen by
     350                // place a bogus node there, which would be later removed by dataprocessor.
     351                var body = editor.document.getBody(),
     352                        enterMode = editor.config.enterMode,
     353                        selection = editor.getSelection(),
     354                        walkerRange = new CKEDITOR.dom.range( editor.document ),
     355                        walker = new CKEDITOR.dom.walker( walkerRange );
     356
     357                walkerRange.selectNodeContents( body );
     358                walker.evaluator = function( node )
     359                {
     360                        return node.type == CKEDITOR.NODE_ELEMENT && nonExitable( node );
     361                };
     362                walker.guard = function( node, isMoveout )
     363                {
     364                        return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
     365                };
     366
     367                if ( walker.previous() )
     368                {
     369                        editor.fire( 'updateSnapshot' );
     370                        restoreDirty( editor );
     371                        CKEDITOR.env.ie && selection && restoreSelection( selection );
     372
     373                        var paddingBlock;
     374                        if ( enterMode != CKEDITOR.ENTER_BR )
     375                                paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
     376                        else
     377                                paddingBlock = body;
     378
     379                        if ( !CKEDITOR.env.ie )
     380                                paddingBlock.appendBogus();
     381                        else if ( paddingBlock.is( 'body' ) )
     382                        {
     383                                // IE need at least a node to show the cursor, use a zero height br
     384                                // to fly under the radar, additionally wrap the br element with an extra span ,
     385                                // so selection change event could be easily captured when cursor move inside of it.
     386                                var paddingNode = CKEDITOR.dom.element.createFromHtml( '<span data-cke-bogus=1>' +
     387                                                                                                                                                           '<br data-cke-temp=1 style="line-height:0"/></span>', editor.document );
     388                                paddingBlock.append( paddingNode );
     389                        }
     390                }
     391        }
     392
    346393        /**
    347394         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent
    348395         *  non-exitable-block by padding extra br.(#3189)
     
    359406
    360407                CKEDITOR.env.gecko && activateEditing( editor );
    361408
     409                // Remove the padding body node used in IE.
     410                if ( CKEDITOR.env.ie )
     411                {
     412                        var start = range.collapsed && range.startContainer;
     413                        if ( start.type == CKEDITOR.NODE_ELEMENT && start.is( 'span') && start.data( 'cke-bogus') )
     414                        {
     415                                range.moveToPosition( start, CKEDITOR.POSITION_BEFORE_START );
     416                                start.remove();
     417                                range.select();
     418                                return;
     419                        }
     420                }
     421
    362422                // When enterMode set to block, we'll establing new paragraph only if we're
    363423                // selecting inline contents right under body. (#3657)
    364424                if ( enterMode != CKEDITOR.ENTER_BR
     
    396456                                {
    397457                                        element = fixedBlock.getPrevious( isNotWhitespace );
    398458                                        if ( element &&
    399                                                  element.type == CKEDITOR.NODE_ELEMENT &&
    400                                                  !nonExitable( element ) )
     459                                                 element.type == CKEDITOR.NODE_ELEMENT )
    401460                                        {
    402                                                 range.moveToElementEditEnd( element );
    403                                                 fixedBlock.remove();
    404                                         }
    405                                 }
    406                         }
     461                                                if ( !nonExitable( element ) )
     462                                                {
     463                                                        range.moveToElementEditEnd( element );
     464                                                        fixedBlock.remove();
     465                                                }
     466                                                else if ( element.getDirection() )
     467                                                        fixedBlock.setAttribute( 'dir', element.getDirection() );
     468                                        }
     469                                }
     470                        }
    407471
    408472                        range.select();
    409473                        // Notify non-IE that selection has changed.
     
    415479                        }
    416480                }
    417481
    418                 // All browsers are incapable to moving cursor out of certain non-exitable
    419                 // blocks (e.g. table, list, pre) at the end of document, make this happen by
    420                 // place a bogus node there, which would be later removed by dataprocessor.
    421                 var walkerRange = new CKEDITOR.dom.range( editor.document ),
    422                         walker = new CKEDITOR.dom.walker( walkerRange );
    423                 walkerRange.selectNodeContents( body );
    424                 walker.evaluator = function( node )
    425                 {
    426                         return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
    427                 };
    428                 walker.guard = function( node, isMoveout )
    429                 {
    430                         return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
    431                 };
    432 
    433                 if ( walker.previous() )
    434                 {
    435                         editor.fire( 'updateSnapshot' );
    436                         restoreDirty( editor );
    437                         CKEDITOR.env.ie && restoreSelection( selection );
    438 
    439                         var paddingBlock;
    440                         if ( enterMode != CKEDITOR.ENTER_BR )
    441                                 paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
    442                         else
    443                                 paddingBlock = body;
    444 
    445                         if ( !CKEDITOR.env.ie )
    446                                 paddingBlock.appendBogus();
    447                 }
    448         }
     482                paddingBody( editor );
     483        }
    449484
    450485        CKEDITOR.plugins.add( 'wysiwygarea',
    451486        {
     
    10821117                                        var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
    10831118                                        title.data( 'cke-title', editor.document.$.title );
    10841119                                        editor.document.$.title = frameLabel;
     1120                                        paddingBody( editor );
    10851121                                });
    10861122
    10871123                        // IE8 stricts mode doesn't have 'contentEditable' in effect
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy