Files
Alfredv2/alfred/app/static/js/dona-ui-v9-2-1-close.js
T
2026-10-31 11:04:45 +01:00

60 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* DONA_UI_V921_CLOSE — Répare le panneau Raccourcis V9.2. */
(() => {
'use strict';
if (window.DonaUIV921Close) return;
let attempts = 0;
function init() {
const root = document.getElementById('alfredMainV1');
const tray = root?.querySelector('.dona-tools-tray');
const grid = tray?.querySelector('.av-shortcuts');
const toolbar = tray?.querySelector('.dv92-shortcut-toolbar');
if (!grid || !toolbar || !root?.querySelector('#dv92Hamburger')) {
if (++attempts < 80) window.setTimeout(init, 150);
return;
}
if (tray.dataset.dv921Close === 'ready') return;
tray.dataset.dv921Close = 'ready';
const closeTray = () => { tray.open = false; };
const heading = document.createElement('div');
heading.className = 'dv921-tray-heading';
const label = document.createElement('span');
label.textContent = 'Raccourcis';
const close = document.createElement('button');
close.type = 'button';
close.className = 'dv921-tray-close';
close.textContent = '×';
close.title = 'Fermer les raccourcis';
close.setAttribute('aria-label', 'Fermer les raccourcis');
close.addEventListener('click', (event) => {
event.stopPropagation();
closeTray();
});
heading.append(label, close);
// V9.2 régénère la grille après une modification : réinstaller l'entête.
const ensureHeading = () => {
if (grid.firstElementChild !== heading) grid.prepend(heading);
};
ensureHeading();
new MutationObserver(ensureHeading).observe(grid, { childList: true });
// Fermer sur clic à l'extérieur, sans bloquer les autres commandes.
document.addEventListener('pointerdown', (event) => {
if (tray.open && !tray.contains(event.target)) closeTray();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && tray.open) closeTray();
});
// Fermer aussi lorsqu'un raccourci est lancé.
grid.addEventListener('click', (event) => {
if (event.target.closest('button.dv92-shortcut')) closeTray();
});
// L'éditeur ne nécessite pas que le panneau reste ouvert derrière lui.
toolbar.addEventListener('click', (event) => {
if (event.target.closest('.dv92-edit-open')) closeTray();
});
window.DonaUIV921Close = { close: closeTray };
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else init();
})();