properly start live-preview after first save
This commit is contained in:
parent
1f347df8cf
commit
f5750c7ab6
|
@ -591,27 +591,32 @@ onDOMscriptReady('/codemirror.js').then(() => {
|
||||||
setTimeout(setupLivePreview);
|
setTimeout(setupLivePreview);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!styleId) {
|
if (styleId) {
|
||||||
new MutationObserver((_, observer) => {
|
$('#editor.livePreview').onchange = livePreviewToggled;
|
||||||
if (!styleId) return;
|
|
||||||
observer.disconnect();
|
|
||||||
setupLivePreview();
|
|
||||||
}).observe($('#preview-label'), {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ['class'],
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('#editor.livePreview').onchange = function () {
|
// wait for #preview-label's class to lose 'hidden' after the first save
|
||||||
const previewing = this.checked;
|
new MutationObserver((_, observer) => {
|
||||||
editors.forEach(cm => cm[previewing ? 'on' : 'off']('changes', updatePreview));
|
if (!styleId) return;
|
||||||
const addRemove = previewing ? 'addEventListener' : 'removeEventListener';
|
observer.disconnect();
|
||||||
$('#enabled')[addRemove]('change', updatePreview);
|
setupLivePreview();
|
||||||
$('#sections')[addRemove]('change', updatePreview);
|
livePreviewToggled();
|
||||||
if (!previewing || document.body.classList.contains('dirty')) {
|
}).observe($('#preview-label'), {
|
||||||
updatePreview(null, previewing);
|
attributes: true,
|
||||||
}
|
attributeFilter: ['class'],
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function livePreviewToggled() {
|
||||||
|
const me = this instanceof Node ? this : $('#editor.livePreview');
|
||||||
|
const previewing = me.checked;
|
||||||
|
editors.forEach(cm => cm[previewing ? 'on' : 'off']('changes', updatePreview));
|
||||||
|
const addRemove = previewing ? 'addEventListener' : 'removeEventListener';
|
||||||
|
$('#enabled')[addRemove]('change', updatePreview);
|
||||||
|
$('#sections')[addRemove]('change', updatePreview);
|
||||||
|
if (!previewing || document.body.classList.contains('dirty')) {
|
||||||
|
updatePreview(null, previewing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePreview(data, previewing) {
|
function updatePreview(data, previewing) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user