mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
chore: 'compareDocumentPosition' to 'contains' (#6982)
The 'compareDocumentPosition' call was inherited from Closure Library, in order to work with IE 8 and earlier. Use the more modern 'contains' call instead. This change was originally added here: https://github.com/google/blockly/pull/1991 Remove the DOCUMENT_POSITION_CONTAINED_BY constant which is not a NodeType and should never have been part of that enum. This change was originally added here: https://github.com/google/blockly/pull/2736
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.utils.dom');
|
||||
|
||||
import * as deprecation from './deprecation.js';
|
||||
import type {Svg} from './svg.js';
|
||||
|
||||
|
||||
@@ -33,7 +34,6 @@ export enum NodeType {
|
||||
ELEMENT_NODE = 1,
|
||||
TEXT_NODE = 3,
|
||||
COMMENT_NODE = 8,
|
||||
DOCUMENT_POSITION_CONTAINED_BY = 16
|
||||
}
|
||||
|
||||
/** Temporary cache of text widths. */
|
||||
@@ -160,11 +160,13 @@ export function insertAfter(newNode: Element, refNode: Element) {
|
||||
* @param parent The node that should contain the other node.
|
||||
* @param descendant The node to test presence of.
|
||||
* @returns Whether the parent node contains the descendant node.
|
||||
* @deprecated Use native 'contains' DOM method.
|
||||
*/
|
||||
export function containsNode(parent: Node, descendant: Node): boolean {
|
||||
return !!(
|
||||
parent.compareDocumentPosition(descendant) &
|
||||
NodeType.DOCUMENT_POSITION_CONTAINED_BY);
|
||||
deprecation.warn(
|
||||
'Blockly.utils.dom.containsNode', 'version 10', 'version 11',
|
||||
'Use native "contains" DOM method');
|
||||
return parent.contains(descendant);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user