Skip to content

Commit 1ecf10c

Browse files
author
garry.yao
committed
Better inline documentation.
git-svn-id: https://svn.ckeditor.com/CKEditor/trunk@5627 da63caf2-3823-0410-a1e8-d69ccee00dfb
1 parent 81f9709 commit 1ecf10c

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

_source/core/dom/range.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
33
For licensing, see LICENSE.html or http://ckeditor.com/license
44
*/
@@ -612,7 +612,7 @@ CKEDITOR.dom.range = function( document ) {
612612
},
613613

614614
/**
615-
* Move the range out of bookmark nodes if they're been the container.
615+
* Move the range out of bookmark nodes if they'd been the container.
616616
*/
617617
optimizeBookmark: function() {
618618
var startNode = this.startContainer,
@@ -1015,12 +1015,12 @@ CKEDITOR.dom.range = function( document ) {
10151015

10161016
var walker = new CKEDITOR.dom.walker( walkerRange ),
10171017
blockBoundary, // The node on which the enlarging should stop.
1018-
tailBr, //
1019-
defaultGuard = CKEDITOR.dom.walker.blockBoundary(
1018+
tailBr, // In case BR as block boundary.
1019+
notBlockBoundary = CKEDITOR.dom.walker.blockBoundary(
10201020
( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br:1 } : null ),
10211021
// Record the encountered 'blockBoundary' for later use.
10221022
boundaryGuard = function( node ) {
1023-
var retval = defaultGuard( node );
1023+
var retval = notBlockBoundary( node );
10241024
if ( !retval )
10251025
blockBoundary = node;
10261026
return retval;
@@ -1040,8 +1040,9 @@ CKEDITOR.dom.range = function( document ) {
10401040
// It's the body which stop the enlarging if no block boundary found.
10411041
blockBoundary = blockBoundary || body;
10421042

1043-
// Start the range at different position by comparing
1044-
// the document position of it with 'enlargeable' node.
1043+
// Start the range either after the end of found block (<p>...</p>[text)
1044+
// or at the start of block (<p>[text...), by comparing the document position
1045+
// with 'enlargeable' node.
10451046
this.setStartAt( blockBoundary, !blockBoundary.is( 'br' ) && ( !enlargeable && this.checkStartOfBlock() || enlargeable && blockBoundary.contains( enlargeable ) ) ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_AFTER_END );
10461047

10471048
// Enlarging the end boundary.
@@ -1060,8 +1061,8 @@ CKEDITOR.dom.range = function( document ) {
10601061
// It's the body which stop the enlarging if no block boundary found.
10611062
blockBoundary = blockBoundary || body;
10621063

1063-
// Start the range at different position by comparing
1064-
// the document position of it with 'enlargeable' node.
1064+
// Close the range either before the found block start (text]<p>...</p>) or at the block end (...text]</p>)
1065+
// by comparing the document position with 'enlargeable' node.
10651066
this.setEndAt( blockBoundary, ( !enlargeable && this.checkEndOfBlock() || enlargeable && blockBoundary.contains( enlargeable ) ) ? CKEDITOR.POSITION_BEFORE_END : CKEDITOR.POSITION_BEFORE_START );
10661067
// We must include the <br> at the end of range if there's
10671068
// one and we're expanding list item contents
@@ -1074,6 +1075,13 @@ CKEDITOR.dom.range = function( document ) {
10741075
* Descrease the range to make sure that boundaries
10751076
* always anchor beside text nodes or innermost element.
10761077
* @param {Number} mode ( CKEDITOR.SHRINK_ELEMENT | CKEDITOR.SHRINK_TEXT ) The shrinking mode.
1078+
* <dl>
1079+
* <dt>CKEDITOR.SHRINK_ELEMENT</dt>
1080+
* <dd>Shrink the range boundaries to the edge of the innermost element.</dd>
1081+
* <dt>CKEDITOR.SHRINK_TEXT</dt>
1082+
* <dd>Shrink the range boudaries to anchor by the side of enclosed text node, range remains if there's no text nodes on boundaries at all.</dd>
1083+
* </dl>
1084+
* @param {Boolean} selectContents Whether result range anchors at the inner OR outer boundary of the node.
10771085
*/
10781086
shrink: function( mode, selectContents ) {
10791087
// Unable to shrink a collapsed range.
@@ -1430,11 +1438,11 @@ CKEDITOR.dom.range = function( document ) {
14301438
walkerRange[ checkType == CKEDITOR.START ? 'setStartAt' : 'setEndAt' ]
14311439
( element, checkType == CKEDITOR.START ? CKEDITOR.POSITION_AFTER_START : CKEDITOR.POSITION_BEFORE_END );
14321440

1433-
var walker = new CKEDITOR.dom.walker( walkerRange ),
1434-
retval = false;
1441+
var walker = new CKEDITOR.dom.walker( walkerRange );
14351442
walker.evaluator = elementBoundaryEval;
14361443
return walker[ checkType == CKEDITOR.START ? 'checkBackward' : 'checkForward' ]();
14371444
},
1445+
14381446
// Calls to this function may produce changes to the DOM. The range may
14391447
// be updated to reflect such changes.
14401448
checkStartOfBlock: function() {
@@ -1565,7 +1573,7 @@ CKEDITOR.dom.range = function( document ) {
15651573
getEnclosedNode: function() {
15661574
var walkerRange = this.clone();
15671575

1568-
// Optimize and analyze the range to avoid DOM destructive nature of walker. (#
1576+
// Optimize and analyze the range to avoid DOM destructive nature of walker. (#5780)
15691577
walkerRange.optimize();
15701578
if ( walkerRange.startContainer.type != CKEDITOR.NODE_ELEMENT || walkerRange.endContainer.type != CKEDITOR.NODE_ELEMENT )
15711579
return null;
@@ -1613,11 +1621,15 @@ CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS = 3;
16131621

16141622
/**
16151623
* Check boundary types.
1616-
* @see CKEDITOR.dom.range::checkBoundaryOfElement
1624+
* @see CKEDITOR.dom.range.prototype.checkBoundaryOfElement
16171625
*/
16181626
CKEDITOR.START = 1;
16191627
CKEDITOR.END = 2;
16201628
CKEDITOR.STARTEND = 3;
16211629

1630+
/**
1631+
* Shrink range types.
1632+
* @see CKEDITOR.dom.range.prototype.shrink
1633+
*/
16221634
CKEDITOR.SHRINK_ELEMENT = 1;
16231635
CKEDITOR.SHRINK_TEXT = 2;

0 commit comments

Comments
 (0)