Explorar o código

Changed: getAncestor uses node.nodeType instead of instanceof Document.

Szymon Cofalik %!s(int64=9) %!d(string=hai) anos
pai
achega
38d7f1045d

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

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  * For licensing, see LICENSE.md.
  */
  */
 
 
-/* globals Document */
+/* globals Node */
 
 
 /**
 /**
  * Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
  * Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
@@ -17,8 +17,8 @@
 export default function getAncestors( node ) {
 export default function getAncestors( node ) {
 	const nodes = [];
 	const nodes = [];
 
 
-	// Do not return Document object since it's not a `Node` and we are interested in `Node`s (and `DocumentFragment`s).
-	while ( node && !( node instanceof Document ) ) {
+	// We are interested in `Node`s `DocumentFragment`s only.
+	while ( node && node.nodeType != Node.DOCUMENT_NODE ) {
 		nodes.unshift( node );
 		nodes.unshift( node );
 		node = node.parentNode;
 		node = node.parentNode;
 	}
 	}

+ 1 - 1
packages/ckeditor5-utils/tests/dom/getancestors.js

@@ -9,7 +9,7 @@
 import getAncestors from '/ckeditor5/utils/dom/getancestors.js';
 import getAncestors from '/ckeditor5/utils/dom/getancestors.js';
 import createElement from '/ckeditor5/utils/dom/createelement.js';
 import createElement from '/ckeditor5/utils/dom/createelement.js';
 
 
-describe( 'getParents', () => {
+describe( 'getAncestors', () => {
 	it( 'should return all parents of given node and the node itself, starting from top-most parent', () => {
 	it( 'should return all parents of given node and the node itself, starting from top-most parent', () => {
 		// DIV
 		// DIV
 		//  |- P (1)
 		//  |- P (1)