restore the original toggle* functions

This commit is contained in:
tophf 2022-01-13 14:13:29 +03:00
parent adfd94001b
commit 549c0ba2c9

View File

@ -102,20 +102,8 @@ newUI.renderClass();
msg.onExtension(onRuntimeMessage); msg.onExtension(onRuntimeMessage);
window.on('closeOptions', () => router.updateHash('')); window.on('closeOptions', () => router.updateHash(''));
router.watch( router.watch({hash: '#stylus-options'}, toggleEmbeddedOptions);
{hash: '#stylus-options'}, router.watch({hash: '#injection-order'}, toggleInjectionOrder);
Embed(() => $create('iframe', {
id: 'stylus-embedded-options',
src: '/options.html',
}))
);
router.watch(
{hash: '#injection-order'},
EmbedDialog(() => $create('iframe', {
id: 'injection-order',
src: '/injection-order/injection-order.html',
}))
);
function onRuntimeMessage(msg) { function onRuntimeMessage(msg) {
switch (msg.method) { switch (msg.method) {
@ -138,53 +126,36 @@ function onRuntimeMessage(msg) {
setTimeout(sorter.updateStripes, 0, {onlyWhenColumnsChanged: true}); setTimeout(sorter.updateStripes, 0, {onlyWhenColumnsChanged: true});
} }
/** async function toggleEmbeddedOptions(state) {
* @param {function():Node|string} create const el = $('#stylus-embedded-options') ||
*/ state && document.documentElement.appendChild($create('iframe', {
function EmbedDialog(create) { id: 'stylus-embedded-options',
let shown = false; src: '/options.html',
return toggle; }));
if (state) {
function toggle(state) { el.focus();
if (state && !shown) { } else if (el) {
messageBoxProxy.show({ el.contentDocument.body.classList.add('scaleout');
title: t('styleInjectionOrder'), await animateElement(el, 'fadeout');
contents: create(), el.remove();
className: 'injection-order-dialog center-dialog',
blockScroll: true,
})
.then(() => {
shown = false;
router.updateHash('');
});
shown = true;
} else if (!state && shown) {
messageBoxProxy.close();
shown = false;
}
} }
} }
/** async function toggleInjectionOrder(state) {
* @param {function():Node|string} create const sel = 'iframe#injection-order';
*/ const shown = $(sel);
function Embed(create) { if (state && !shown) {
let el; await messageBoxProxy.show({
return toggle; title: t('styleInjectionOrder'),
async function toggle(state) { contents: $create(sel, {
if (state) { src: '/injection-order/injection-order.html',
if (!el) el = create(); }),
if (!el.parentNode) { className: 'injection-order-dialog center-dialog',
document.body.append(el); blockScroll: true,
} buttons: [t('confirmClose')],
el.focus(); });
} else { router.updateHash('');
if (!el || !el.parentNode) return; } else if (!state && shown) {
if (el.contentDocument) { await messageBoxProxy.close();
el.contentDocument.body.classList.add('scaleout');
}
await animateElement(el, 'fadeout');
el.remove();
}
} }
} }