Ticket #2907: 2907.patch
File 2907.patch, 3.4 KB (added by , 16 years ago) |
---|
-
_source/core/dom/range.js
360 360 return docFrag; 361 361 }, 362 362 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 ) 370 379 { 371 380 var startNode, endNode; 381 var baseId; 372 382 var clone; 373 383 374 384 startNode = this.document.createElement( 'span' ); … … 379 389 // removed during DOM operations. 380 390 startNode.setHtml( ' ' ); 381 391 392 if ( serializable ) 393 { 394 baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber(); 395 startNode.setAttribute( 'id', baseId + 'S' ); 396 } 397 382 398 // If collapsed, the endNode will not be created. 383 399 if ( !this.collapsed ) 384 400 { 385 401 endNode = startNode.clone(); 386 402 endNode.setHtml( ' ' ); 387 403 404 if ( serializable ) 405 endNode.setAttribute( 'id', baseId + 'E' ); 406 388 407 clone = this.clone(); 389 408 clone.collapse(); 390 409 clone.insertNode( endNode ); … … 404 423 this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END ); 405 424 406 425 return { 407 startNode : startNode, 408 endNode : endNode 426 startNode : serializable ? baseId + 'S' : startNode, 427 endNode : serializable ? baseId + 'E' : endNode, 428 serializable : serializable 409 429 }; 410 430 }, 411 431 412 432 moveToBookmark : function( bookmark ) 413 433 { 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 414 438 // Set the range start at the bookmark start node position. 415 this.setStartBefore( bookmark.startNode );439 this.setStartBefore( startNode ); 416 440 417 441 // Remove it, because it may interfere in the setEndBefore call. 418 bookmark.startNode.remove();442 startNode.remove(); 419 443 420 444 // Set the range end at the bookmark end node position, or simply 421 445 // collapse it if it is not available. 422 var endNode = bookmark.endNode;423 446 if ( endNode ) 424 447 { 425 448 this.setEndBefore( endNode );