-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathWire.js
More file actions
33 lines (30 loc) · 962 Bytes
/
Wire.js
File metadata and controls
33 lines (30 loc) · 962 Bytes
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
'use strict';
const { append } = require('../shared/utils.js');
const { doc, fragment } = require('../shared/easy-dom.js');
function Wire(childNodes) {
this.childNodes = childNodes;
this.length = childNodes.length;
this.first = childNodes[0];
this.last = childNodes[this.length - 1];
}
Object.defineProperty(exports, '__esModule', {value: true}).default = Wire
// when a wire is inserted, all its nodes will follow
Wire.prototype.insert = function insert() {
const df = fragment(this.first);
append(df, this.childNodes);
return df;
};
// when a wire is removed, all its nodes must be removed as well
Wire.prototype.remove = function remove() {
const first = this.first;
const last = this.last;
if (this.length === 2) {
last.parentNode.removeChild(last);
} else {
const range = doc(first).createRange();
range.setStartBefore(this.childNodes[1]);
range.setEndAfter(last);
range.deleteContents();
}
return first;
};