X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fdom%2Frange.js;h=8f10980e472a859f093ce39bc09249c49e4af736;hb=614511639979907ceb0da3614122a4d8eb963ad4;hp=0146f6a6d691f222153f1d44ccf8ea907c3520d1;hpb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;p=ckeditor.git diff --git a/_source/core/dom/range.js b/_source/core/dom/range.js index 0146f6a..8f10980 100644 --- a/_source/core/dom/range.js +++ b/_source/core/dom/range.js @@ -3,6 +3,9 @@ Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ +/** + * @class + */ CKEDITOR.dom.range = function( document ) { this.startContainer = null; @@ -305,7 +308,7 @@ CKEDITOR.dom.range = function( document ) return node.type != CKEDITOR.NODE_TEXT && node.getName() in CKEDITOR.dtd.$removeEmpty || !CKEDITOR.tools.trim( node.getText() ) - || node.getParent().hasAttribute( '_fck_bookmark' ); + || node.getParent().hasAttribute( '_cke_bookmark' ); } var whitespaceEval = new CKEDITOR.dom.walker.whitespaces(), @@ -348,7 +351,10 @@ CKEDITOR.dom.range = function( document ) this.collapsed = true; }, - // The selection may be lost when cloning (due to the splitText() call). + /** + * The content nodes of the range are cloned and added to a document fragment, which is returned. + * Note: Text selection may lost after invoking this method. (caused by text node splitting). + */ cloneContents : function() { var docFrag = new CKEDITOR.dom.documentFragment( this.document ); @@ -359,6 +365,9 @@ CKEDITOR.dom.range = function( document ) return docFrag; }, + /** + * Deletes the content nodes of the range permanently from the DOM tree. + */ deleteContents : function() { if ( this.collapsed ) @@ -367,6 +376,10 @@ CKEDITOR.dom.range = function( document ) execContentsAction( this, 0 ); }, + /** + * The content nodes of the range are cloned and added to a document fragment, + * meanwhile they're removed permanently from the DOM tree. + */ extractContents : function() { var docFrag = new CKEDITOR.dom.documentFragment( this.document ); @@ -400,7 +413,7 @@ CKEDITOR.dom.range = function( document ) var collapsed = this.collapsed; startNode = this.document.createElement( 'span' ); - startNode.setAttribute( '_fck_bookmark', 1 ); + startNode.setAttribute( '_cke_bookmark', 1 ); startNode.setStyle( 'display', 'none' ); // For IE, it must have something inside, otherwise it may be @@ -710,10 +723,10 @@ CKEDITOR.dom.range = function( document ) endNode = this.endContainer; if ( startNode.is && startNode.is( 'span' ) - && startNode.hasAttribute( '_fck_bookmark' ) ) + && startNode.hasAttribute( '_cke_bookmark' ) ) this.setStartAt( startNode, CKEDITOR.POSITION_BEFORE_START ); if ( endNode && endNode.is && endNode.is( 'span' ) - && endNode.hasAttribute( '_fck_bookmark' ) ) + && endNode.hasAttribute( '_cke_bookmark' ) ) this.setEndAt( endNode, CKEDITOR.POSITION_AFTER_END ); }, @@ -919,7 +932,7 @@ CKEDITOR.dom.range = function( document ) // If this is a visible element. // We need to check for the bookmark attribute because IE insists on // rendering the display:none nodes we use for bookmarks. (#3363) - if ( sibling.$.offsetWidth > 0 && !sibling.getAttribute( '_fck_bookmark' ) ) + if ( sibling.$.offsetWidth > 0 && !sibling.getAttribute( '_cke_bookmark' ) ) { // We'll accept it only if we need // whitespace, and this is an inline @@ -1078,7 +1091,7 @@ CKEDITOR.dom.range = function( document ) // If this is a visible element. // We need to check for the bookmark attribute because IE insists on // rendering the display:none nodes we use for bookmarks. (#3363) - if ( sibling.$.offsetWidth > 0 && !sibling.getAttribute( '_fck_bookmark' ) ) + if ( sibling.$.offsetWidth > 0 && !sibling.getAttribute( '_cke_bookmark' ) ) { // We'll accept it only if we need // whitespace, and this is an inline @@ -1300,7 +1313,8 @@ CKEDITOR.dom.range = function( document ) } } - var walker = new CKEDITOR.dom.walker( walkerRange ); + var walker = new CKEDITOR.dom.walker( walkerRange ), + isBookmark = CKEDITOR.dom.walker.bookmark(); walker.evaluator = function( node ) { @@ -1311,6 +1325,9 @@ CKEDITOR.dom.range = function( document ) var currentElement; walker.guard = function( node, movingOut ) { + if ( isBookmark( node ) ) + return true; + // Stop when we're shrink in element mode while encountering a text node. if ( mode == CKEDITOR.SHRINK_ELEMENT && node.type == CKEDITOR.NODE_TEXT ) return false; @@ -1398,7 +1415,7 @@ CKEDITOR.dom.range = function( document ) // Fixing invalid range start inside dtd empty elements. if( startNode.type == CKEDITOR.NODE_ELEMENT && CKEDITOR.dtd.$empty[ startNode.getName() ] ) - startNode = startNode.getParent(), startOffset = startNode.getIndex(); + startOffset = startNode.getIndex(), startNode = startNode.getParent(); this.startContainer = startNode; this.startOffset = startOffset; @@ -1429,7 +1446,7 @@ CKEDITOR.dom.range = function( document ) // Fixing invalid range end inside dtd empty elements. if( endNode.type == CKEDITOR.NODE_ELEMENT && CKEDITOR.dtd.$empty[ endNode.getName() ] ) - endNode = endNode.getParent(), endOffset = endNode.getIndex() + 1; + endOffset = endNode.getIndex() + 1, endNode = endNode.getParent(); this.endContainer = endNode; this.endOffset = endOffset; @@ -1864,17 +1881,13 @@ CKEDITOR.ENLARGE_ELEMENT = 1; CKEDITOR.ENLARGE_BLOCK_CONTENTS = 2; CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS = 3; -/** - * Check boundary types. - * @see CKEDITOR.dom.range.prototype.checkBoundaryOfElement - */ +// Check boundary types. +// @see CKEDITOR.dom.range.prototype.checkBoundaryOfElement CKEDITOR.START = 1; CKEDITOR.END = 2; CKEDITOR.STARTEND = 3; -/** - * Shrink range types. - * @see CKEDITOR.dom.range.prototype.shrink - */ +// Shrink range types. +// @see CKEDITOR.dom.range.prototype.shrink CKEDITOR.SHRINK_ELEMENT = 1; CKEDITOR.SHRINK_TEXT = 2;