aboutsummaryrefslogtreecommitdiffstats
path: root/theme
diff options
context:
space:
mode:
Diffstat (limited to 'theme')
-rw-r--r--theme/admin/rsrc/main.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/theme/admin/rsrc/main.js b/theme/admin/rsrc/main.js
index 842ef47..94fc591 100644
--- a/theme/admin/rsrc/main.js
+++ b/theme/admin/rsrc/main.js
@@ -158,3 +158,34 @@ if(document.getElementById("delete-button")) {
}
}
})();
+
+//==============================================================================
+// Detect unsaved changes in content editor
+//==============================================================================
+(function() {
+ if(document.getElementById("content-editor")) {
+ const editor = document.getElementById("content-editor");
+ const initialValue = editor.value;
+
+ function showConfirmationPrompt(e) {
+ if(editor.value !== initialValue) {
+ e.returnValue = '';
+ e.preventDefault();
+ }
+ }
+
+ window.addEventListener('beforeunload', showConfirmationPrompt);
+
+ const buttons = [];
+ buttons.push(document.getElementById('insert-button'));
+ buttons.push(document.getElementById('update-button'));
+
+ for(let i = 0; i < buttons.length; ++i) {
+ if(buttons[i] !== null) {
+ buttons[i].addEventListener('click', function() {
+ window.removeEventListener('beforeunload', showConfirmationPrompt);
+ });
+ }
+ }
+ }
+})();