File tree Expand file tree Collapse file tree 4 files changed +15
-48
lines changed Expand file tree Collapse file tree 4 files changed +15
-48
lines changed Original file line number Diff line number Diff line change @@ -515,19 +515,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
515
515
* alert( parents[ 0 ].getName() + ',' + parents[ 2 ].getName() ); // 'html,p'
516
516
*
517
517
* @param {Boolean } [closerFirst=false] Determines the order of returned nodes.
518
- * @param {CKEDITOR.dom.node } [lastParent=null] Guard node. Nodes that are parents of `lastParent` will be ommited.
519
- * If `parent` is `null` or `parent` is not an ancestor of this node all parents will be returned.
520
518
* @returns {Array } Returns an array of {@link CKEDITOR.dom.node}.
521
519
*/
522
-
523
- getParents : function ( closerFirst , lastParent ) {
520
+ getParents : function ( closerFirst ) {
524
521
var node = this ;
525
522
var parents = [ ] ;
526
523
527
524
do {
528
525
parents [ closerFirst ? 'push' : 'unshift' ] ( node ) ;
529
526
}
530
- while ( ! node . equals ( lastParent ) && ( node = node . getParent ( ) ) ) ;
527
+ while ( ( node = node . getParent ( ) ) ) ;
531
528
532
529
return parents ;
533
530
} ,
Original file line number Diff line number Diff line change 1
- /**
1
+ /**
2
2
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3
3
* For licensing, see LICENSE.md or http://ckeditor.com/license
4
4
*/
1253
1253
* @since 4.5
1254
1254
* @private
1255
1255
* @param {String } selector Selector to match.
1256
- * @returns {CKEDITOR.dom.node } Matched node or null if a node has not been found.
1256
+ * @returns {CKEDITOR.dom.element } Matched element or ` null` if a node has not been found.
1257
1257
*/
1258
1258
_findOneNotNested : function ( selector ) {
1259
- var match = null ,
1260
- parents ;
1261
-
1262
- var matchedElements = this . wrapper . find ( selector ) ;
1259
+ var matchedElements = this . wrapper . find ( selector ) ,
1260
+ match ,
1261
+ closestWrapper ;
1263
1262
1264
1263
for ( var i = 0 ; i < matchedElements . count ( ) ; i ++ ) {
1265
1264
match = matchedElements . getItem ( i ) ;
1265
+ closestWrapper = match . getAscendant ( Widget . isDomWidgetWrapper ) ;
1266
1266
1267
- parents = match . getParents ( true , this . wrapper ) ;
1268
- // Don't include wrapper element.
1269
- parents . pop ( ) ;
1270
-
1271
- for ( var j = 0 ; j < parents . length ; j ++ ) {
1272
- // One of parents is a widget wrapper, so this match is already a part of other widget.
1273
- if ( Widget . isDomWidgetWrapper ( parents [ j ] ) ) {
1274
- match = null ;
1275
- break ;
1276
- }
1267
+ // The closest ascendant-wrapper of this match defines to which widget
1268
+ // this match belongs. If the ascendant is this widget's wrapper
1269
+ // it means that the match is not nested in other widget.
1270
+ if ( this . wrapper . equals ( closestWrapper ) ) {
1271
+ return match ;
1277
1272
}
1278
-
1279
- // The first match is a good match.
1280
- // Other matches are probably parts of other widgets instances.
1281
- if ( match != null )
1282
- break ;
1283
1273
}
1284
1274
1285
- return match ;
1275
+ return null ;
1286
1276
} ,
1287
1277
1288
1278
/**
Original file line number Diff line number Diff line change @@ -31,9 +31,4 @@ <h1>Title</h1>
31
31
32
32
text
33
33
34
- </ p >
35
- < div id ="guardParent ">
36
- < div >
37
- < span id ="getParentsWithGuard "> </ span >
38
- </ div >
39
- </ div >
34
+ </ p >
Original file line number Diff line number Diff line change 673
673
674
674
assert . areSame ( 3 , node . getParents ( ) . length ) ;
675
675
assert . areSame ( node . getParents ( ) [ 0 ] , node . getParents ( true ) [ 2 ] ) ;
676
-
677
- } ,
678
-
679
- test_getParents_guard : function ( ) {
680
- var guard = newNode ( document . getElementById ( 'guardParent' ) ) ,
681
- node = newNode ( document . getElementById ( 'getParentsWithGuard' ) ) ,
682
- wrongParent = newNode ( document . getElementById ( 'remove' ) ) ;
683
-
684
- assert . areSame ( 3 , node . getParents ( false , guard ) . length ) ;
685
- // guard element is not a parent of node - all nodes up to root are returned (+ body, html)
686
- assert . areSame ( 5 , node . getParents ( false , wrongParent ) . length ) ;
687
- assert . areSame ( node . getParents ( false , guard ) [ 0 ] , guard ) ;
688
- assert . areSame ( node . getParents ( false , guard ) [ 0 ] , node . getParents ( true , guard ) [ 2 ] ) ;
689
- // guard and base node are the same elements - we should get only that node
690
- assert . isTrue ( node . getParents ( false , node ) [ 0 ] . equals ( node ) ) ;
691
676
} ,
692
677
693
678
test_getCommonAncestor : function ( ) {
You can’t perform that action at this time.
0 commit comments