Ticket #5479: 5479_12.patch

File 5479_12.patch, 7.8 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                // IE below version 8 doesn't require this fix.
     349                if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat )
     350                        return;
     351
     352                // All browsers are incapable to moving cursor out of certain non-exitable
     353                // blocks (e.g. table, list, pre) at the end of document, make this happen by
     354                // place a bogus node there, which would be later removed by dataprocessor.
     355                var body = editor.document.getBody(),
     356                        enterMode = editor.config.enterMode,
     357                        selection = editor.getSelection(),
     358                        walkerRange = new CKEDITOR.dom.range( editor.document ),
     359                        walker = new CKEDITOR.dom.walker( walkerRange );
     360
     361                walkerRange.selectNodeContents( body );
     362                walker.evaluator = function( node )
     363                {
     364                        return node.type == CKEDITOR.NODE_ELEMENT && nonExitable( node );
     365                };
     366                walker.guard = function( node, isMoveout )
     367                {
     368                        return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
     369                };
     370
     371                if ( walker.previous() )
     372                {
     373                        editor.fire( 'updateSnapshot' );
     374                        restoreDirty( editor );
     375                        CKEDITOR.env.ie && selection && restoreSelection( selection );
     376
     377                        var paddingBlock;
     378                        if ( enterMode != CKEDITOR.ENTER_BR )
     379                                paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
     380                        else
     381                                paddingBlock = body;
     382
     383                        if ( !CKEDITOR.env.ie )
     384                                paddingBlock.appendBogus();
     385                        else if ( paddingBlock.is( 'body' ) )
     386                        {
     387                                // IE need at least a node to show the cursor, use a zero height br
     388                                // to fly under the radar, additionally wrap the br element with an extra span ,
     389                                // so selection change event could be easily captured when cursor move inside of it.
     390                                var paddingNode = CKEDITOR.dom.element.createFromHtml( '<span data-cke-bogus=1>' +
     391                                                                                                                                                           '<br data-cke-temp=1 style="line-height:0"/></span>', editor.document );
     392                                paddingBlock.append( paddingNode );
     393                        }
     394                }
     395        }
     396
    346397        /**
    347398         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent
    348399         *  non-exitable-block by padding extra br.(#3189)
     
    359410
    360411                CKEDITOR.env.gecko && activateEditing( editor );
    361412
     413                // Remove the padding body node used in IE.
     414                if ( CKEDITOR.env.ie )
     415                {
     416                        var start = range.collapsed && range.startContainer;
     417                        if ( start.type == CKEDITOR.NODE_ELEMENT && start.is( 'span') && start.data( 'cke-bogus') )
     418                        {
     419                                range.moveToPosition( start, CKEDITOR.POSITION_BEFORE_START );
     420                                start.remove();
     421                                range.select();
     422                                return;
     423                        }
     424                }
     425
    362426                // When enterMode set to block, we'll establing new paragraph only if we're
    363427                // selecting inline contents right under body. (#3657)
    364428                if ( enterMode != CKEDITOR.ENTER_BR
     
    396460                                {
    397461                                        element = fixedBlock.getPrevious( isNotWhitespace );
    398462                                        if ( element &&
    399                                                  element.type == CKEDITOR.NODE_ELEMENT &&
    400                                                  !nonExitable( element ) )
     463                                                 element.type == CKEDITOR.NODE_ELEMENT )
    401464                                        {
    402                                                 range.moveToElementEditEnd( element );
    403                                                 fixedBlock.remove();
    404                                         }
    405                                 }
    406                         }
     465                                                if ( !nonExitable( element ) )
     466                                                {
     467                                                        range.moveToElementEditEnd( element );
     468                                                        fixedBlock.remove();
     469                                                }
     470                                                else if ( element.getDirection() )
     471                                                        fixedBlock.setAttribute( 'dir', element.getDirection() );
     472                                        }
     473                                }
     474                        }
    407475
    408476                        range.select();
    409477                        // Notify non-IE that selection has changed.
     
    415483                        }
    416484                }
    417485
    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         }
     486                paddingBody( editor );
     487        }
    449488
    450489        CKEDITOR.plugins.add( 'wysiwygarea',
    451490        {
     
    10821121                                        var title = editor.document.getElementsByTag( 'title' ).getItem( 0 );
    10831122                                        title.data( 'cke-title', editor.document.$.title );
    10841123                                        editor.document.$.title = frameLabel;
     1124                                        paddingBody( editor );
    10851125                                });
    10861126
    10871127                        // IE8 stricts mode doesn't have 'contentEditable' in effect
     
    11651205                                                element.data( 'cke-editable', element.hasAttribute( 'contenteditable' ) ? 'true' : '1' );
    11661206                                        element.setAttribute( 'contentEditable', false );
    11671207                                }
     1208
     1209                                paddingBody( editor );
    11681210                        });
    11691211
    1170                 }
    1171         });
     1212                                        }
     1213                        });
    11721214
    11731215        // Fixing Firefox 'Back-Forward Cache' break design mode. (#4514)
    11741216        if ( CKEDITOR.env.gecko )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy