Skip to content

Commit

Permalink
Merge branch 't/13400' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jun 15, 2015
2 parents 4870adb + 6ec2bbe commit 5c2bd9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
7 changes: 2 additions & 5 deletions core/dom/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,16 @@ CKEDITOR.tools.extend( CKEDITOR.dom.node.prototype, {
* alert( parents[ 0 ].getName() + ',' + parents[ 2 ].getName() ); // 'html,p'
*
* @param {Boolean} [closerFirst=false] Determines the order of returned nodes.
* @param {CKEDITOR.dom.node} [lastParent=null] Guard node. Nodes that are parents of `lastParent` will be ommited.
* If `parent` is `null` or `parent` is not an ancestor of this node all parents will be returned.
* @returns {Array} Returns an array of {@link CKEDITOR.dom.node}.
*/

getParents: function( closerFirst, lastParent ) {
getParents: function( closerFirst ) {
var node = this;
var parents = [];

do {
parents[ closerFirst ? 'push' : 'unshift' ]( node );
}
while ( !node.equals( lastParent ) && ( node = node.getParent() ) );
while ( ( node = node.getParent() ) );

return parents;
},
Expand Down
34 changes: 12 additions & 22 deletions plugins/widget/plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
Expand Down Expand Up @@ -1253,36 +1253,26 @@
* @since 4.5
* @private
* @param {String} selector Selector to match.
* @returns {CKEDITOR.dom.node} Matched node or null if a node has not been found.
* @returns {CKEDITOR.dom.element} Matched element or `null` if a node has not been found.
*/
_findOneNotNested: function( selector ) {
var match = null,
parents;

var matchedElements = this.wrapper.find( selector );
var matchedElements = this.wrapper.find( selector ),
match,
closestWrapper;

for ( var i = 0; i < matchedElements.count(); i++ ) {
match = matchedElements.getItem( i );
closestWrapper = match.getAscendant( Widget.isDomWidgetWrapper );

parents = match.getParents( true, this.wrapper );
// Don't include wrapper element.
parents.pop();

for ( var j = 0; j < parents.length; j++ ) {
// One of parents is a widget wrapper, so this match is already a part of other widget.
if ( Widget.isDomWidgetWrapper( parents[ j ] ) ) {
match = null;
break;
}
// The closest ascendant-wrapper of this match defines to which widget
// this match belongs. If the ascendant is this widget's wrapper
// it means that the match is not nested in other widget.
if ( this.wrapper.equals( closestWrapper ) ) {
return match;
}

// The first match is a good match.
// Other matches are probably parts of other widgets instances.
if ( match != null )
break;
}

return match;
return null;
},

/**
Expand Down
7 changes: 1 addition & 6 deletions tests/core/dom/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,4 @@ <h1>Title</h1>

text

</p>
<div id="guardParent">
<div>
<span id="getParentsWithGuard"></span>
</div>
</div>
</p>
15 changes: 0 additions & 15 deletions tests/core/dom/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,21 +673,6 @@

assert.areSame( 3, node.getParents().length );
assert.areSame( node.getParents()[ 0 ], node.getParents( true )[ 2 ] );

},

test_getParents_guard: function() {
var guard = newNode( document.getElementById( 'guardParent' ) ),
node = newNode( document.getElementById( 'getParentsWithGuard' ) ),
wrongParent = newNode( document.getElementById( 'remove' ) );

assert.areSame( 3, node.getParents( false, guard ).length );
// guard element is not a parent of node - all nodes up to root are returned (+ body, html)
assert.areSame( 5, node.getParents( false, wrongParent ).length );
assert.areSame( node.getParents( false, guard )[ 0 ], guard );
assert.areSame( node.getParents( false, guard )[ 0 ], node.getParents( true, guard )[ 2 ] );
// guard and base node are the same elements - we should get only that node
assert.isTrue( node.getParents( false, node )[ 0 ].equals( node ) );
},

test_getCommonAncestor: function() {
Expand Down

0 comments on commit 5c2bd9c

Please sign in to comment.