60 lines
1.1 KiB
JavaScript
60 lines
1.1 KiB
JavaScript
let wire = {
|
|
__mark_class__ : "wired",
|
|
|
|
__wired__ : [],
|
|
|
|
init : () => {
|
|
const cssRules = `
|
|
.wired {
|
|
position: absolute;
|
|
}
|
|
`;
|
|
|
|
var styleElement = document.createElement("style");
|
|
styleElement.textContent = cssRules;
|
|
document.head.appendChild(styleElement);
|
|
},
|
|
|
|
arm : () => {
|
|
__wired__ = document.querySelectorAll("." + wire.__mark_class__);
|
|
wire.update();
|
|
},
|
|
|
|
pack : (e) => {
|
|
const wired_regex = /^wire-(.*)-(.*)$/;
|
|
|
|
const r = {
|
|
status: false,
|
|
property: null,
|
|
target: null,
|
|
};
|
|
|
|
const match = wired_regex.exec(e);
|
|
|
|
if (match) {
|
|
[, r.property, r.destination] = match;
|
|
r.status = true;
|
|
}
|
|
|
|
return r;
|
|
},
|
|
|
|
render : (e, p, d) => {
|
|
e[p] = document.querySelector(d).getBoundingClientRect()[p];
|
|
},
|
|
|
|
update : () => {
|
|
for (var e of __wired__) {
|
|
for (let i = 0; i < e.classList.length; i++) {
|
|
const r = wire.pack(e.classList[i]);
|
|
if (r.status == false) { continue; }
|
|
console.log(r);
|
|
wire.render(e, r.property, r.destination);
|
|
}
|
|
}
|
|
},
|
|
}
|
|
|
|
wire.init();
|
|
window.addEventListener('load', wire.arm);
|