Files
xamxam/app/public/assets/js/app/beforeunload-guard.js
Pontoporeia b56d073210 refactor: extract inline JS into app/ modules, remove dead overtype-webcomponent
- Remove overtype-webcomponent.min.js (zero references)
- Extract copyLogContent + fallbackCopy + HTMX tab-updater → app/admin-logs.js
  (removes duplicate from both system.php and parametres.php)
- Extract copyUrl → app/clipboard.js (shared by acces.php)
- Extract tag/language pill-search logic → app/pill-search.js
  Generalized with data-pill-search attributes, auto-inits via
  DOMContentLoaded + htmx:afterSwap
- Extract access-request form handler → app/access-request.js
  (was inline in templates/public/tfe.php)

Files created: admin-logs.js, clipboard.js, pill-search.js, access-request.js
Files modified: 9 templates/controllers to drop inline scripts and
  reference external JS files
2026-05-19 00:08:06 +02:00

26 lines
884 B
JavaScript

/**
* Beforeunload guard — prompts the user before navigating away from unsaved changes.
*
* Attach to any form with a data-beforeunload-guard attribute.
* Also watches window.__xamxamDirty (set by file-upload-filepond.js on FilePond events).
* No effect when JavaScript is unavailable (form posts normally).
*/
(() => {
const forms = document.querySelectorAll('form[data-beforeunload-guard]');
if (!forms.length) return;
let dirty = false;
for (const form of forms) {
form.addEventListener('input', () => { dirty = true; });
form.addEventListener('change', () => { dirty = true; });
form.addEventListener('submit', () => { dirty = false; window.__xamxamDirty = false; });
}
window.addEventListener('beforeunload', (e) => {
if (dirty || window.__xamxamDirty) {
e.preventDefault();
}
});
})();