mirror of
https://github.com/chinchang/web-maker.git
synced 2025-06-08 18:54:49 +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/partials/*').pipe(gulp.dest('app/partials'));
|
||||
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-128.png').pipe(gulp.dest('app'));
|
||||
gulp
|
||||
|
@ -1,3 +1,13 @@
|
||||
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) {
|
||||
frame.src = frame.src;
|
||||
setTimeout(() => {
|
||||
frame.contentDocument.open();
|
||||
frame.contentDocument.write(contents);
|
||||
frame.contentDocument.close();
|
||||
}, 10);
|
||||
if (scope.detachedWindow) {
|
||||
utils.log('✉️ Sending message to detached window');
|
||||
scope.detachedWindow.postMessage({ contents }, '*');
|
||||
} else {
|
||||
frame.src = frame.src;
|
||||
setTimeout(() => {
|
||||
frame.contentDocument.open();
|
||||
frame.contentDocument.write(contents);
|
||||
frame.contentDocument.close();
|
||||
}, 10);
|
||||
}
|
||||
} else {
|
||||
// we need to store user script in external JS file to prevent inline-script
|
||||
// CSP from affecting it.
|
||||
@ -2007,16 +2012,18 @@ loginModal, profileModal, profileAvatarImg, profileUserName, openItemsBtn
|
||||
'Web Maker',
|
||||
`width=${iframeWidth},height=${iframeHeight},resizable,scrollbars=yes,status=1`
|
||||
);
|
||||
// Trigger initial render in detached window
|
||||
setTimeout(() => {
|
||||
scope.detachedWindow.postMessage(frame.src, '*');
|
||||
}, 1000);
|
||||
scope.setPreviewContent(true);
|
||||
}, 1500);
|
||||
function checkWindow() {
|
||||
if (scope.detachedWindow && scope.detachedWindow.closed) {
|
||||
clearInterval(intervalID);
|
||||
document.body.classList.remove('is-detached-mode');
|
||||
$('#js-demo-side').insertBefore(consoleEl, 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user