Repository navigation
Expand file tree
/
Copy pathdom.ts
More file actions
50 lines (47 loc) · 1.64 KB
/
Copy pathdom.ts
File metadata and controls
50 lines (47 loc) · 1.64 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at
* http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at
* http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
export const isCEPolyfill = window.customElements !== undefined &&
(window.customElements as any).polyfillWrapFlushCallback !== undefined;
/**
* Reparents nodes, starting from `startNode` (inclusive) to `endNode`
* (exclusive), into another container (could be the same container), before
* `beforeNode`. If `beforeNode` is null, it appends the nodes to the
* container.
*/
export const reparentNodes =
(container: Node,
start: Node|null,
end: Node|null = null,
before: Node|null = null): void => {
let node = start;
while (node !== end) {
const n = node!.nextSibling;
container.insertBefore(node!, before as Node);
node = n;
}
};
/**
* Removes nodes, starting from `startNode` (inclusive) to `endNode`
* (exclusive), from `container`.
*/
export const removeNodes =
(container: Node, startNode: Node|null, endNode: Node|null = null):
void => {
let node = startNode;
while (node !== endNode) {
const n = node!.nextSibling;
container.removeChild(node!);
node = n;
}
};