-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwd.js
More file actions
23 lines (23 loc) · 741 Bytes
/
wd.js
File metadata and controls
23 lines (23 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function init(param) {
const el = param instanceof HTMLElement ? param : document.querySelector(param);
el.querySelectorAll('*').forEach(node => {
if (node.hasAttributes()) {
let attrs = [], classes = [], id = null;
for (const attr of node.attributes) {
switch (attr.name[0]) {
case '.':
classes.push(...attr.name.substring(1).split('.'));
attrs.push(attr.name);
break;
case '#':
id = attr.name.substring(1);
attrs.push(attr.name);
break;
}
}
for (const a of attrs) { node.removeAttribute(a) }
if (classes.length) node.classList.add(...classes);
if (id) node.id = id;
}
});
}