mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-10 03:35:16 +02:00
fix detached window updation in webapp
This commit is contained in:
parent
6b018310f0
commit
16acb03593
@ -24,6 +24,8 @@ gulp.task('copyFiles', [], function() {
|
|||||||
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers'));
|
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers'));
|
||||||
gulp.src('src/partials/*').pipe(gulp.dest('app/partials'));
|
gulp.src('src/partials/*').pipe(gulp.dest('app/partials'));
|
||||||
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib'));
|
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib'));
|
||||||
|
gulp.src('src/preview.html').pipe(gulp.dest('app'));
|
||||||
|
gulp.src('src/detached-window.js').pipe(gulp.dest('app'));
|
||||||
gulp.src('src/icon-48.png').pipe(gulp.dest('app'));
|
gulp.src('src/icon-48.png').pipe(gulp.dest('app'));
|
||||||
gulp.src('src/icon-128.png').pipe(gulp.dest('app'));
|
gulp.src('src/icon-128.png').pipe(gulp.dest('app'));
|
||||||
gulp
|
gulp
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
window.addEventListener('message', e => {
|
window.addEventListener('message', e => {
|
||||||
document.querySelector('iframe').src = e.data;
|
if (e.data && e.data.contents) {
|
||||||
|
const frame = document.querySelector('iframe');
|
||||||
|
frame.src = frame.src;
|
||||||
|
setTimeout(() => {
|
||||||
|
frame.contentDocument.open();
|
||||||
|
frame.contentDocument.write(e.data.contents);
|
||||||
|
frame.contentDocument.close();
|
||||||
|
}, 10);
|
||||||
|
} else {
|
||||||
|
document.querySelector('iframe').src = e.data;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -1132,12 +1132,17 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldInlineJs) {
|
if (shouldInlineJs) {
|
||||||
frame.src = frame.src;
|
if (scope.detachedWindow) {
|
||||||
setTimeout(() => {
|
utils.log('✉️ Sending message to detached window');
|
||||||
frame.contentDocument.open();
|
scope.detachedWindow.postMessage({ contents }, '*');
|
||||||
frame.contentDocument.write(contents);
|
} else {
|
||||||
frame.contentDocument.close();
|
frame.src = frame.src;
|
||||||
}, 10);
|
setTimeout(() => {
|
||||||
|
frame.contentDocument.open();
|
||||||
|
frame.contentDocument.write(contents);
|
||||||
|
frame.contentDocument.close();
|
||||||
|
}, 10);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// we need to store user script in external JS file to prevent inline-script
|
// we need to store user script in external JS file to prevent inline-script
|
||||||
// CSP from affecting it.
|
// CSP from affecting it.
|
||||||
@ -2007,16 +2012,18 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn
|
|||||||
'Web Maker',
|
'Web Maker',
|
||||||
`width=${iframeWidth},height=${iframeHeight},resizable,scrollbars=yes,status=1`
|
`width=${iframeWidth},height=${iframeHeight},resizable,scrollbars=yes,status=1`
|
||||||
);
|
);
|
||||||
|
// Trigger initial render in detached window
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scope.detachedWindow.postMessage(frame.src, '*');
|
scope.setPreviewContent(true);
|
||||||
}, 1000);
|
}, 1500);
|
||||||
function checkWindow() {
|
function checkWindow() {
|
||||||
if (scope.detachedWindow && scope.detachedWindow.closed) {
|
if (scope.detachedWindow && scope.detachedWindow.closed) {
|
||||||
clearInterval(intervalID);
|
clearInterval(intervalID);
|
||||||
document.body.classList.remove('is-detached-mode');
|
document.body.classList.remove('is-detached-mode');
|
||||||
$('#js-demo-side').insertBefore(consoleEl, null);
|
$('#js-demo-side').insertBefore(consoleEl, null);
|
||||||
scope.detachedWindow = null;
|
scope.detachedWindow = null;
|
||||||
// Update main frame preview
|
// Update main frame preview to get latest changes (which were not
|
||||||
|
// getting reflected while detached window was open)
|
||||||
scope.setPreviewContent(true);
|
scope.setPreviewContent(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user