forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domutils.ts
35 lines (30 loc) · 789 Bytes
/
domutils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
ArrayExt
} from '@phosphor/algorithm';
import {
ElementExt
} from '@phosphor/domutils';
/**
* The namespace for DOM utilities.
*/
export
namespace DOMUtils {
/**
* Get the index of the node at a client position, or `-1`.
*/
export
function hitTestNodes(nodes: HTMLElement[] | HTMLCollection, x: number, y: number): number {
return ArrayExt.findFirstIndex(nodes, node => {
return ElementExt.hitTest(node, x, y);
});
}
/**
* Find the first element matching a class name.
*/
export
function findElement(parent: HTMLElement, className: string): HTMLElement {
return parent.querySelector(`.${className}`) as HTMLElement;
}
}