From 88821a5780428f0e3fed3fd0de6828dc08573ed2 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Mon, 24 Mar 2025 16:55:40 +0100 Subject: [PATCH] Move beforeunload to plugin --- CHANGELOG.md | 2 +- adminer/call.inc.php | 1 - adminer/include/html.inc.php | 1 - adminer/static/functions.js | 23 ++--------------------- plugins/before-unload.php | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 plugins/before-unload.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 99918e1e..aa9ed769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,4 @@ ## Adminer dev -- Confirm before exiting edited edit form - Display collation at table structure if different from table - Ctrl+click in select moves the cursor in modern browsers - URL parameter ?ext=pdo to force using PDO @@ -23,6 +22,7 @@ - New plugin: IMAP driver created for fun - New plugin: Display links to tables referencing current row - New plugin: Allow switching light and dark mode (bug #926) +- New plugin: Confirm before unloading page with changed form - Uzbek translation ## Adminer 5.0.6 (released 2025-03-17) diff --git a/adminer/call.inc.php b/adminer/call.inc.php index 5ae5fa44..a9df194d 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -81,7 +81,6 @@ if ($in) { echo "\n"; } echo "\n"; - echo script("setupEditChange(qsl('form'));"); } ?>

diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index f3baa751..5c41eb01 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -513,7 +513,6 @@ function edit_form($table, $fields, $row, $update) { ; } echo "\n"; - echo script("setupEditChange(qsl('form'));"); } echo "

\n"; if ($fields) { diff --git a/adminer/static/functions.js b/adminer/static/functions.js index 35d80e6f..9af1864c 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -567,27 +567,6 @@ function fieldChange() { -let editChanged; - -/** Setup saving editChanged on form fields -* @this HTMLFormElement -*/ -function setupEditChange(form) { - for (const el of qsa('input, select, textarea', form)) { - addEvent(el, 'change', () => { - editChanged = true; - }); - } - form.onsubmit = () => { - editChanged = null; // false doesn't work in Chrome - } -} - -// all modern browsers ignore string returned from here -onbeforeunload = () => editChanged; - - - /** Create AJAX request * @param string * @param function (XMLHttpRequest) @@ -637,6 +616,8 @@ function ajaxSetHtml(url) { }); } +let editChanged; // used by plugins + /** Save form contents through AJAX * @param HTMLFormElement * @param string diff --git a/plugins/before-unload.php b/plugins/before-unload.php new file mode 100644 index 00000000..5c37ca31 --- /dev/null +++ b/plugins/before-unload.php @@ -0,0 +1,33 @@ + + +