mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 07:36:44 +02:00
Move beforeunload to plugin
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
## Adminer dev
|
## Adminer dev
|
||||||
- Confirm before exiting edited edit form
|
|
||||||
- Display collation at table structure if different from table
|
- Display collation at table structure if different from table
|
||||||
- Ctrl+click in select moves the cursor in modern browsers
|
- Ctrl+click in select moves the cursor in modern browsers
|
||||||
- URL parameter ?ext=pdo to force using PDO
|
- URL parameter ?ext=pdo to force using PDO
|
||||||
@@ -23,6 +22,7 @@
|
|||||||
- New plugin: IMAP driver created for fun
|
- New plugin: IMAP driver created for fun
|
||||||
- New plugin: Display links to tables referencing current row
|
- New plugin: Display links to tables referencing current row
|
||||||
- New plugin: Allow switching light and dark mode (bug #926)
|
- New plugin: Allow switching light and dark mode (bug #926)
|
||||||
|
- New plugin: Confirm before unloading page with changed form
|
||||||
- Uzbek translation
|
- Uzbek translation
|
||||||
|
|
||||||
## Adminer 5.0.6 (released 2025-03-17)
|
## Adminer 5.0.6 (released 2025-03-17)
|
||||||
|
@@ -81,7 +81,6 @@ if ($in) {
|
|||||||
echo "\n";
|
echo "\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
echo script("setupEditChange(qsl('form'));");
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<p>
|
<p>
|
||||||
|
@@ -513,7 +513,6 @@ function edit_form($table, $fields, $row, $update) {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
echo script("setupEditChange(qsl('form'));");
|
|
||||||
}
|
}
|
||||||
echo "<p>\n";
|
echo "<p>\n";
|
||||||
if ($fields) {
|
if ($fields) {
|
||||||
|
@@ -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
|
/** Create AJAX request
|
||||||
* @param string
|
* @param string
|
||||||
* @param function (XMLHttpRequest)
|
* @param function (XMLHttpRequest)
|
||||||
@@ -637,6 +616,8 @@ function ajaxSetHtml(url) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let editChanged; // used by plugins
|
||||||
|
|
||||||
/** Save form contents through AJAX
|
/** Save form contents through AJAX
|
||||||
* @param HTMLFormElement
|
* @param HTMLFormElement
|
||||||
* @param string
|
* @param string
|
||||||
|
33
plugins/before-unload.php
Normal file
33
plugins/before-unload.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** Display confirmation before unloading page if a form field was changed
|
||||||
|
* @link https://www.adminer.org/plugins/#use
|
||||||
|
* @author Jakub Vrana, https://www.vrana.cz/
|
||||||
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||||
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||||
|
*/
|
||||||
|
class AdminerBeforeUnload {
|
||||||
|
|
||||||
|
function head($dark = null) {
|
||||||
|
?>
|
||||||
|
<script <?php echo Adminer\nonce(); ?>>
|
||||||
|
// editChange is declared in functions.js
|
||||||
|
// ajaxForm sets editChange to null on success
|
||||||
|
|
||||||
|
addEvent(document, 'change', event => {
|
||||||
|
const el = event.target;
|
||||||
|
if (el.form && /post/i.test(el.form.method)) {
|
||||||
|
editChanged = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addEvent(document, 'submit', () => {
|
||||||
|
editChanged = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// all modern browsers ignore string returned from here
|
||||||
|
onbeforeunload = () => editChanged;
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user