Ticket #2907: 2907.patch

File 2907.patch, 3.4 KB (added by Frederico Caldeira Knabben, 15 years ago)
  • _source/core/dom/range.js

     
    360360                        return docFrag;
    361361                },
    362362
    363                 // This is an "intrusive" way to create a bookmark. It includes <span> tags
    364                 // in the range boundaries. The advantage of it is that it is possible to
    365                 // handle DOM mutations when moving back to the bookmark.
    366                 // Attention: the inclusion of nodes in the DOM is a design choice and
    367                 // should not be changed as there are other points in the code that may be
    368                 // using those nodes to perform operations. See GetBookmarkNode.
    369                 createBookmark : function()
     363                /**
     364                 * Creates a bookmark object, which can be later used to restore the
     365                 * range by using the moveToBookmark function.
     366                 * This is an "intrusive" way to create a bookmark. It includes <span> tags
     367                 * in the range boundaries. The advantage of it is that it is possible to
     368                 * handle DOM mutations when moving back to the bookmark.
     369                 * Attention: the inclusion of nodes in the DOM is a design choice and
     370                 * should not be changed as there are other points in the code that may be
     371                 * using those nodes to perform operations. See GetBookmarkNode.
     372                 * @param {Boolean} [serializable] Indicates that the bookmark nodes
     373                 *              must contain ids, which can be used to restore the range even
     374                 *              when these nodes suffer mutations (like a clonation or innerHTML
     375                 *              change).
     376                 * @returns {Object} And object representing a bookmark.
     377                 */
     378                createBookmark : function( serializable )
    370379                {
    371380                        var startNode, endNode;
     381                        var baseId;
    372382                        var clone;
    373383
    374384                        startNode = this.document.createElement( 'span' );
     
    379389                        // removed during DOM operations.
    380390                        startNode.setHtml( '&nbsp;' );
    381391
     392                        if ( serializable )
     393                        {
     394                                baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber();
     395                                startNode.setAttribute( 'id', baseId + 'S' );
     396                        }
     397
    382398                        // If collapsed, the endNode will not be created.
    383399                        if ( !this.collapsed )
    384400                        {
    385401                                endNode = startNode.clone();
    386402                                endNode.setHtml( '&nbsp;' );
    387403
     404                                if ( serializable )
     405                                        endNode.setAttribute( 'id', baseId + 'E' );
     406
    388407                                clone = this.clone();
    389408                                clone.collapse();
    390409                                clone.insertNode( endNode );
     
    404423                                this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END );
    405424
    406425                        return {
    407                                 startNode : startNode,
    408                                 endNode : endNode
     426                                startNode : serializable ? baseId + 'S' : startNode,
     427                                endNode : serializable ? baseId + 'E' : endNode,
     428                                serializable : serializable
    409429                        };
    410430                },
    411431
    412432                moveToBookmark : function( bookmark )
    413433                {
     434                        var serializable = bookmark.serializable,
     435                                startNode       = serializable ? this.document.getById( bookmark.startNode ) : bookmark.startNode,
     436                                endNode         = serializable ? this.document.getById( bookmark.endNode ) : bookmark.endNode;
     437
    414438                        // Set the range start at the bookmark start node position.
    415                         this.setStartBefore( bookmark.startNode );
     439                        this.setStartBefore( startNode );
    416440
    417441                        // Remove it, because it may interfere in the setEndBefore call.
    418                         bookmark.startNode.remove();
     442                        startNode.remove();
    419443
    420444                        // Set the range end at the bookmark end node position, or simply
    421445                        // collapse it if it is not available.
    422                         var endNode = bookmark.endNode;
    423446                        if ( endNode )
    424447                        {
    425448                                this.setEndBefore( endNode );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy