proper cleanup on close + builtin event emitter
This commit is contained in:
parent
b553325d7c
commit
54963ee298
|
@ -110,7 +110,7 @@ async function handleExternalUpdate({style, reason}) {
|
||||||
} else {
|
} else {
|
||||||
await editor.replaceStyle(style);
|
await editor.replaceStyle(style);
|
||||||
}
|
}
|
||||||
editor.updateSettings();
|
window.dispatchEvent(new Event('styleSettings'));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.on('beforeunload', e => {
|
window.on('beforeunload', e => {
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function StyleSettings() {
|
function StyleSettings() {
|
||||||
|
const ssId = 'styleSettings';
|
||||||
const AUTOSAVE_DELAY = 500; // same as config-dialog.js
|
const AUTOSAVE_DELAY = 500; // same as config-dialog.js
|
||||||
const ui = t.template.styleSettings.cloneNode(true);
|
const ui = t.template[ssId].cloneNode(true);
|
||||||
const elAuto = $('[id="config.autosave"]', ui);
|
const elAuto = $('[id="config.autosave"]', ui);
|
||||||
const elSave = $('#ss-save', ui);
|
const elSave = $('#ss-save', ui);
|
||||||
const pendingSetters = new Map();
|
const pendingSetters = new Map();
|
||||||
|
@ -22,10 +23,10 @@ function StyleSettings() {
|
||||||
initArea('inclusions'),
|
initArea('inclusions'),
|
||||||
initArea('exclusions'),
|
initArea('exclusions'),
|
||||||
];
|
];
|
||||||
(editor.updateSettings = () => {
|
update();
|
||||||
updaters.forEach(fn => fn());
|
window.on(ssId, update);
|
||||||
})();
|
window.on('closeHelp', () => window.off(ssId, update), {once: true});
|
||||||
helpPopup.show(t('styleSettings'), ui, {
|
helpPopup.show(t(ssId), ui, {
|
||||||
className: 'style-settings-popup',
|
className: 'style-settings-popup',
|
||||||
});
|
});
|
||||||
elSave.onclick = save;
|
elSave.onclick = save;
|
||||||
|
@ -81,6 +82,7 @@ function StyleSettings() {
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
pendingSetters.forEach((fn, el) => fn(el.value));
|
pendingSetters.forEach((fn, el) => fn(el.value));
|
||||||
|
pendingSetters.clear();
|
||||||
helpPopup.div.classList.remove('dirty');
|
helpPopup.div.classList.remove('dirty');
|
||||||
elSave.disabled = true;
|
elSave.disabled = true;
|
||||||
}
|
}
|
||||||
|
@ -88,4 +90,8 @@ function StyleSettings() {
|
||||||
function textToList(text) {
|
function textToList(text) {
|
||||||
return text.split(/\n/).map(s => s.trim()).filter(Boolean);
|
return text.split(/\n/).map(s => s.trim()).filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
updaters.forEach(fn => fn());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user