feat: widget sdk

This commit is contained in:
Tristan Yang
2022-10-27 21:21:54 +08:00
parent 23320ab637
commit 1987c257ba
25 changed files with 456 additions and 96 deletions
+40
View File
@@ -0,0 +1,40 @@
const {
domain = location.origin,
hostId = 1,
closeWidth = 52,
closeHeight = 52,
openWidth = 600,
openHeight = 800
} = document.currentScript.dataset;
const wrapper = document.createElement("iframe");
const styles = {
position: "fixed",
right: "15px",
bottom: "15px",
border: "none"
};
Object.assign(wrapper.style, styles);
wrapper.src = `${domain}/widget.html?host=${hostId}`;
wrapper.width = closeWidth;
wrapper.height = closeHeight;
wrapper.frameborder = 0;
window.addEventListener(
"message",
(event) => {
const { data: CMD } = event;
switch (CMD) {
case "OPEN":
wrapper.setAttribute("width", openWidth);
wrapper.setAttribute("height", openHeight);
break;
case "CLOSE":
wrapper.setAttribute("width", closeWidth);
wrapper.setAttribute("height", closeHeight);
break;
default:
break;
}
},
false
);
document.body.appendChild(wrapper);