properly update hash when closing UI
This commit is contained in:
parent
bcc98d913b
commit
9e009726c5
|
@ -11,14 +11,16 @@ const router = {
|
||||||
return new URLSearchParams(location.search).get(key);
|
return new URLSearchParams(location.search).get(key);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** When showing the UI, `showHide` function must resolve only when the UI is closed */
|
||||||
makeToggle(hashId, showHide, deps) {
|
makeToggle(hashId, showHide, deps) {
|
||||||
const hash = '#' + hashId;
|
const hash = '#' + hashId;
|
||||||
const selector = '.' + hash.slice(1);
|
const selector = '.' + hashId;
|
||||||
router.watch({hash}, async state => {
|
router.watch({hash}, async state => {
|
||||||
const el = $(selector);
|
const el = $(selector);
|
||||||
if (!state === !el) return;
|
if (!state === !el) return;
|
||||||
if (state && deps) await require(deps);
|
if (state && deps) await require(deps);
|
||||||
await showHide(state, el, selector);
|
await showHide(state, el, selector);
|
||||||
|
if (state) router.updateHash('');
|
||||||
});
|
});
|
||||||
return router.updateHash.bind(router, hash);
|
return router.updateHash.bind(router, hash);
|
||||||
},
|
},
|
||||||
|
|
|
@ -108,7 +108,6 @@ newUI.renderClass();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
msg.onExtension(onRuntimeMessage);
|
msg.onExtension(onRuntimeMessage);
|
||||||
window.on('closeOptions', () => router.updateHash(''));
|
|
||||||
|
|
||||||
function onRuntimeMessage(msg) {
|
function onRuntimeMessage(msg) {
|
||||||
switch (msg.method) {
|
switch (msg.method) {
|
||||||
|
@ -135,6 +134,7 @@ async function toggleEmbeddedOptions(show, el, selector) {
|
||||||
if (show) {
|
if (show) {
|
||||||
$.root.appendChild($create('iframe' + selector, {src: '/options.html'}))
|
$.root.appendChild($create('iframe' + selector, {src: '/options.html'}))
|
||||||
.focus();
|
.focus();
|
||||||
|
await new Promise(resolve => window.on('closeOptions', resolve, {once: true}));
|
||||||
} else {
|
} else {
|
||||||
el.contentDocument.body.classList.add('scaleout');
|
el.contentDocument.body.classList.add('scaleout');
|
||||||
await animateElement(el, 'fadeout');
|
await animateElement(el, 'fadeout');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user