-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstyle.js
More file actions
44 lines (39 loc) · 911 Bytes
/
style.js
File metadata and controls
44 lines (39 loc) · 911 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
34
35
36
37
38
39
40
41
42
43
44
// Custom CSS classes are great.
const style = wrap(() => {
const el = document.createElement('style');
el.type = 'text/css';
eventManager.on(':loaded', function appendStyle() {
document.head.append(el);
});
function add(...styles) {
return wrapper(append(styles));
}
function append(styles = [], nodes = []) {
styles.forEach((newStyle) => {
const node = document.createTextNode(newStyle);
nodes.push(node);
el.appendChild(node);
});
return nodes;
}
function wrapper(nodes) {
return {
remove() {
nodes.forEach((node) => node.remove());
nodes.splice(0);
return this;
},
replace(...styles) {
return this.remove().append(styles);
},
append(...styles) {
append(styles, nodes);
return this;
},
};
}
api.register('addStyle', add);
return {
add,
};
});