Ticket #3608: 3608_3.patch

File 3608_3.patch, 10.0 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/list/plugin.js

     
    377377                                                        ( editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'br' ) );
    378378                                        paragraph.appendTo( body );
    379379                                        ranges = [ new CKEDITOR.dom.range( doc ) ];
    380                                         ranges[0].selectNodeContents( paragraph );
     380                                        // IE exception on inserting anything when anchor inside <br>.
     381                                        if ( paragraph.is( 'br' ) )
     382                                        {
     383                                                ranges[ 0 ].setStartBefore( paragraph );
     384                                                ranges[ 0 ].setEndAfter( paragraph );
     385                                        }
     386                                        else
     387                                                ranges[ 0 ].selectNodeContents( paragraph );
    381388                                        selection.selectRanges( ranges );
    382389                                }
    383390                        }
  • _source/core/dom/range.js

     
    265265        // check(Start|End)OfBlock.
    266266        function getCheckStartEndBlockEvalFunction( isStart )
    267267        {
    268                 var hadBr = false;
     268                var hadBr = false, bookmarkEvaluator = CKEDITOR.dom.walker.bookmark( true );
    269269                return function( node )
    270270                {
     271                        // First ignore bookmark nodes.
     272                        if ( bookmarkEvaluator( node ) )
     273                                return true;
     274
    271275                        if ( node.type == CKEDITOR.NODE_TEXT )
    272276                        {
    273277                                // If there's any visible text, then we're not at the start.
    274278                                if ( CKEDITOR.tools.trim( node.getText() ).length )
    275279                                        return false;
    276                         }
     280                                }
    277281                        else
    278282                        {
    279283                                // If there are non-empty inline elements (e.g. <img />), then we're not
     
    11191123                                case CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS:
    11201124
    11211125                                        // Enlarging the start boundary.
    1122                                         var walkerRange = new CKEDITOR.dom.range( this.document );
    1123                                         walkerRange.setStartAt(
    1124                                                 this.document.getBody(), CKEDITOR.POSITION_AFTER_START );
     1126                                        var walkerRange = new CKEDITOR.dom.range( this.document ),
     1127                                                        body = this.document.getBody();
     1128                                        walkerRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
    11251129                                        walkerRange.setEnd( this.startContainer, this.startOffset );
    11261130
    11271131                                        var walker = new CKEDITOR.dom.walker( walkerRange ),
    1128 
    1129                                                 guard = CKEDITOR.dom.walker.blockBoundary(
     1132                                            blockBoundary,  // The node on which the enlarging should stop.
     1133                                                tailBr, //
     1134                                            defaultGuard = CKEDITOR.dom.walker.blockBoundary(
    11301135                                                                ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null ),
    1131                                                 tailBr,
    1132                                                 listGuard = function( node )
     1136                                                // Record the encountered 'blockBoundary' for later use.
     1137                                                boundaryGuard = function( node )
    11331138                                                {
    1134                                                         var result = guard( node );
    1135                                                         if ( !result && node.is && node.is( 'br' ) )
     1139                                                        var retval = defaultGuard( node );
     1140                                                        if ( !retval )
     1141                                                                blockBoundary = node;
     1142                                                        return retval;
     1143                                                },
     1144                                                // Record the encounted 'tailBr' for later use.
     1145                                                tailBrGuard = function( node )
     1146                                                {
     1147                                                        var retval = boundaryGuard( node );
     1148                                                        if ( !retval && node.is && node.is( 'br' ) )
    11361149                                                                tailBr = node;
    1137                                                         return result;
    1138                                                 };
     1150                                                        return retval;
     1151                                                },
     1152                                                guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ?
     1153                                                tailBrGuard : boundaryGuard;
     1154                                               
    11391155                                        walker.guard = guard;
    11401156
     1157
    11411158                                        if ( ( enlargeable = walker.lastBackward() ) )
     1159                                        {
     1160                                                // It's the body which stop the enlaring if no block boundary found.
     1161                                                blockBoundary = blockBoundary || body;
     1162
     1163                                                // Start the range at different position by comparing
     1164                                                // the document position of it with 'enlargeable' node.
     1165                                                var position = blockBoundary.getPosition( enlargeable );
    11421166                                                this.setStartAt(
    1143                                                         enlargeable, CKEDITOR.POSITION_BEFORE_START );
     1167                                                                blockBoundary,
     1168                                                                ( position | CKEDITOR.POSITION_CONTAINS | CKEDITOR.POSITION_PRECEDING )
     1169                                                                                == CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING ?
     1170                                                                CKEDITOR.POSITION_AFTER_START :
     1171                                                                CKEDITOR.POSITION_AFTER_END );
     1172                                        }
    11441173
    11451174                                        // Enlarging the end boundary.
    11461175                                        walkerRange = this.clone();
    11471176                                        walkerRange.collapse();
    1148                                         walkerRange.setEndAt(
    1149                                                 this.document.getBody(), CKEDITOR.POSITION_BEFORE_END );
     1177                                        walkerRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END );
    11501178                                        walker = new CKEDITOR.dom.walker( walkerRange );
    1151                                         walker.guard = ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ?
    1152                                                  listGuard : guard;
     1179                                        walker.guard = guard;
     1180                                        blockBoundary = null;
     1181                                        // End the range right before the block boundary node.
     1182                                        ;
    11531183                                        if ( ( enlargeable = walker.lastForward() ) )
    1154                                                         this.setEndAfter( enlargeable );
     1184                                        {
     1185                                                // It's the body which stop the enlaring if no block boundary found.
     1186                                                blockBoundary = blockBoundary || body;
     1187
     1188                                                // Start the range at different position by comparing
     1189                                                // the document position of it with 'enlargeable' node.
     1190                                                var position = blockBoundary.getPosition( enlargeable );
     1191                                                debugger;
     1192                                                this.setEndAt(
     1193                                                                blockBoundary,
     1194                                                                ( position | CKEDITOR.POSITION_CONTAINS | CKEDITOR.POSITION_PRECEDING )
     1195                                                                                == CKEDITOR.POSITION_CONTAINS + CKEDITOR.POSITION_PRECEDING ?
     1196                                                                CKEDITOR.POSITION_BEFORE_END :
     1197                                                                CKEDITOR.POSITION_BEFORE_START );
     1198                                        }
    11551199                                        // We must include the <br> at the end of range if there's
    11561200                                        // one and we're expanding list item contents
    11571201                                        if ( tailBr )
  • _source/plugins/domiterator/plugin.js

     
    1212(function()
    1313{
    1414
    15         function isBookmarkNode( node )
    16         {
    17                 return ( node && node.getName
    18                                         && node.getName() == 'span'
    19                                         && node.hasAttribute( '_fck_bookmark' ) )
    20                                 ||
    21                                 ( node && !node.getName && isBookmarkNode( node.getParent()) );
    22         }
    23 
    24         function ignoreBookmarkEvaluator( node )
    25         {
    26                 return !isBookmarkNode( node );
    27         }
    28 
    29 
    30         /**
    31          * Find next source order node, ignore bookmark nodes and stop at the specified end node.
    32          * @param {Object} currentNode
    33          * @param {Object} endNode
    34          */
    35         function getNextSourceNode( currentNode, endNode, startFromSibling )
    36         {
    37                 var next = currentNode;
    38                 do
    39                 {
    40                         next = next.getNextSourceNode(
    41                                 startFromSibling, null, endNode );
    42                 }
    43                 while( isBookmarkNode( next ) )
    44                 return next;
    45         }
    46 
    4715        var iterator = function( range )
    4816        {
    4917                if ( arguments.length < 1 )
     
    7947                                range = this.range.clone();
    8048                                range.enlarge( this.forceBrBreak ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS );
    8149
    82                                 var walker = new CKEDITOR.dom.walker( range );
    83                                 walker.evaluator = ignoreBookmarkEvaluator;
     50                                var walker = new CKEDITOR.dom.walker( range ),
     51                                        ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true );
     52                                // Avoid anchor inside bookmark inner text.
     53                                walker.evaluator = ignoreBookmarkTextEvaluator;
    8454                                this._.nextNode = walker.next();
    85 
    8655                                // TODO: It's better to have walker.reset() used here.
    8756                                walker = new CKEDITOR.dom.walker( range );
    88                                 walker.evaluator = ignoreBookmarkEvaluator;
     57                                walker.evaluator = ignoreBookmarkTextEvaluator;
    8958                                var lastNode = walker.previous();
    90                                 this._.lastNode = getNextSourceNode( lastNode, null, true );
     59                                this._.lastNode = lastNode.getNextSourceNode( true );
    9160                                // Probably the document end is reached, we need a marker node.
    9261                                if ( !this._.lastNode )
    9362                                {
     
    10271                                lastNode = this._.lastNode;
    10372
    10473                        this._.nextNode = null;
    105 
    10674                        while ( currentNode )
    10775                        {
    10876                                // closeRange indicates that a paragraph boundary has been found,
     
    230198                                if ( isLast )
    231199                                        break;
    232200
    233                                 currentNode = getNextSourceNode( currentNode, lastNode, continueFromSibling );
     201                                currentNode = currentNode.getNextSourceNode( continueFromSibling, null, lastNode );
    234202                        }
    235203
    236204                        // Now, based on the processed range, look for (or create) the block to be returned.
     
    301269                                        // lists) or the next sibling <li>.
    302270
    303271                                        this._.nextNode = ( block.equals( lastNode ) ? null :
    304                                                 getNextSourceNode( range.getBoundaryNodes().endNode, lastNode, true ) );
     272                                                range.getBoundaryNodes().endNode.getNextSourceNode( true, null, lastNode ) );
    305273                                }
    306274                        }
    307275
     
    334302                        if ( !this._.nextNode )
    335303                        {
    336304                                this._.nextNode = ( isLast || block.equals( lastNode ) ) ? null :
    337                                         getNextSourceNode( block, lastNode, true );
     305                                        block.getNextSourceNode( true, null, lastNode );
    338306                        }
    339307
    340308                        return block;
  • _source/core/dom/walker.js

     
    354354                        return this.blockBoundary( { br : 1 } );
    355355        };
    356356
     357        /**
     358         * Whether the node is a bookmark node's inner text node.
     359         */
     360        CKEDITOR.dom.walker.bookmarkContents = function( node )
     361        {
     362        },
     363
     364        /**
     365         * Whether the to-be-evaluated node is a bookmark node OR bookmark node
     366         * inner contents.
     367         * @param {Boolean} contentOnly Whether only test againt the text content of
     368         * bookmark node instead of the element itself(default).
     369         * @param {Boolean} isReject Whether should return 'false' for the bookmark
     370         * node instead of 'true'(default).
     371         */
     372        CKEDITOR.dom.walker.bookmark = function( contentOnly, isReject )
     373        {
     374                function isBookmarkNode( node )
     375                {
     376                        return ( node && node.getName
     377                                        && node.getName() == 'span'
     378                                        && node.hasAttribute('_fck_bookmark') );
     379                }
     380
     381                return function( node )
     382                {
     383                        var retval, parent;
     384                        // Is bookmark inner text node?
     385                        retval = ( node && !node.getName && ( parent = node.getParent() )
     386                                                && isBookmarkNode( parent ) );
     387                        // Is bookmark node?
     388                        retval = contentOnly ? retval : retval || isBookmarkNode( node );
     389                        return isReject ? !retval : !!retval;
     390                };
     391        }
     392
    357393})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy