-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (32 loc) · 914 Bytes
/
index.js
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
function reactOnMessageFromIFrame(event) {
console.group("Event from iframe");
console.log(`${event}`);
console.groupEnd();
const {
data: { type, value },
} = event;
switch (type) {
case "colorChange": {
const [r, g, b, _] = value.levels;
document.documentElement.style.setProperty(
"--color-background",
`rgb(${r - 10}, ${g - 10}, ${b - 10})`
);
document.documentElement.style.setProperty(
"--color-foreground",
`rgb(${255 - r}, ${255 - g}, ${255 - b})`
);
break;
}
}
}
const sketchIframe = document.querySelector("#sketch");
if (window.addEventListener) {
// For standards-compliant web browsers
window.addEventListener("message", reactOnMessageFromIFrame, false);
} else {
window.attachEvent("onmessage", reactOnMessageFromIFrame);
}
window.addEventListener("touchstart", () => {
console.log("Touch");
});