This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
function setupEditor(root) {
|
||||
const editor = root.querySelector('[data-blog-editor]');
|
||||
const hiddenInput = root.querySelector('[data-blog-editor-value]');
|
||||
const publishedToggle = root.querySelector('[data-blog-published-toggle]');
|
||||
const publishedValue = root.querySelector('[data-blog-published-value]');
|
||||
const form = root.querySelector('form');
|
||||
const preview = root.querySelector('[data-blog-preview]');
|
||||
const buttons = root.querySelectorAll('[data-blog-command]');
|
||||
|
||||
@@ -32,6 +35,21 @@
|
||||
});
|
||||
});
|
||||
|
||||
const syncPublishedState = () => {
|
||||
if (publishedValue && publishedToggle) {
|
||||
publishedValue.value = publishedToggle.checked ? 'true' : 'false';
|
||||
}
|
||||
};
|
||||
|
||||
if (publishedToggle) {
|
||||
publishedToggle.addEventListener('change', syncPublishedState);
|
||||
syncPublishedState();
|
||||
}
|
||||
|
||||
if (form) {
|
||||
form.addEventListener('submit', syncPublishedState);
|
||||
}
|
||||
|
||||
syncEditor(editor, hiddenInput);
|
||||
renderPreview();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user