1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-08-05 04:47:32 +02:00

get back code to do inline style replacement when only css changes, instead of refreshing the page DOM

This commit is contained in:
Kushagra Gour
2025-07-21 19:34:23 +05:30
parent 0d4ba6314d
commit 83d346ee3c
3 changed files with 29 additions and 13 deletions

View File

@@ -1,7 +1,17 @@
window.addEventListener('message', e => {
// Recieving from app window
if (e.data && e.data.contents && e.data.contents.match(/<html/)) {
if (e.data && e.data.isCssOnly) {
const frame = document.querySelector('iframe');
if (
frame.contentDocument &&
frame.contentDocument.querySelector('#webmakerstyle')
) {
frame.contentDocument.querySelector('#webmakerstyle').textContent =
e.data.css;
}
} else if (e.data && e.data.contents && e.data.contents.match(/<html/)) {
const frame = document.querySelector('iframe');
frame.src = frame.src;
setTimeout(() => {
frame.contentDocument.open();
@@ -9,6 +19,7 @@ window.addEventListener('message', e => {
frame.contentDocument.close();
}, 10);
}
// for files mode
if (e.data && e.data.url && e.data.url.match(/index\.html/)) {
document.querySelector('iframe').src = e.data.url;
}