瀏覽代碼

Changed: getParents to getAncestors.

Szymon Cofalik 9 年之前
父節點
當前提交
ccd273449e

+ 3 - 3
packages/ckeditor5-utils/src/dom/getparents.js

@@ -4,12 +4,12 @@
  */
 
 /**
- * Returns all parents of given DOM node, starting from the top-most (root). Includes the node itself.
+ * Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself.
  *
- * @param {Node} node DOM node.
+ * @param {Element|Text} node DOM node.
  * @returns {Array.<Node>} Array of given `node` parents.
  */
-export default function getParents( node ) {
+export default function getAncestors( node ) {
 	const nodes = [];
 
 	while ( node ) {

+ 6 - 6
packages/ckeditor5-utils/src/dom/getcommonancestor.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-import getParents from './getparents.js';
+import getAncestors from './getancestors.js';
 
 /**
  * Searches and returns the lowest common ancestor of two given nodes.
@@ -17,14 +17,14 @@ export default function getCommonAncestor( nodeA, nodeB ) {
 		return nodeA;
 	}
 
-	const parentsA = getParents( nodeA );
-	const parentsB = getParents( nodeB );
+	const ancestorsA = getAncestors( nodeA );
+	const ancestorsB = getAncestors( nodeB );
 
-	const minLength = Math.min( parentsA.length, parentsB.length );
+	const minLength = Math.min( ancestorsA.length, ancestorsB.length );
 
 	for ( let i = minLength - 1; i >= 0; i-- ) {
-		if ( parentsA[ i ] == parentsB[ i ] ) {
-			return parentsA[ i ];
+		if ( ancestorsA[ i ] == ancestorsB[ i ] ) {
+			return ancestorsA[ i ];
 		}
 	}
 

+ 2 - 2
packages/ckeditor5-utils/tests/dom/getparents.js

@@ -6,7 +6,7 @@
 /* globals document */
 /* bender-tags: dom, browser-only */
 
-import getParents from '/ckeditor5/utils/dom/getparents.js';
+import getAncestors from '/ckeditor5/utils/dom/getancestors.js';
 import createElement from '/ckeditor5/utils/dom/createelement.js';
 
 describe( 'getParents', () => {
@@ -24,6 +24,6 @@ describe( 'getParents', () => {
 		const p2 = createElement( document, 'p', {}, [ createElement( document, 'i' ) ] );
 		const div = createElement( document, 'div', {}, [ p1, p2 ] );
 
-		expect( getParents( b ) ).to.deep.equal( [ div, p1, span, b ] );
+		expect( getAncestors( b ) ).to.deep.equal( [ div, p1, span, b ] );
 	} );
 } );