diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-08-28 09:25:44 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-08-28 09:25:44 +0000 |
| commit | 353d62ab03aa9ce430da047afa4ff6797b065c44 (patch) | |
| tree | 0e1cdbe2d3f00938777957b5248aecbe3acf14a3 | |
| parent | 5ddf03c012a44b14b9585b27352b86e8487c1657 (diff) | |
add before unload handler to avoid data loss in wiki, fixes #4522
Closes #4522
Merge request studip/studip!3332
| -rw-r--r-- | resources/vue/components/WikiEditor.vue | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/resources/vue/components/WikiEditor.vue b/resources/vue/components/WikiEditor.vue index 6aae50c..52290cd 100644 --- a/resources/vue/components/WikiEditor.vue +++ b/resources/vue/components/WikiEditor.vue @@ -182,12 +182,17 @@ export default { online: this.isOnlineAndEditing }; - if (this.isChanged) { + if (this.autosave && this.isChanged) { data.content = this.editor.getData(); this.isChanged = false; } return data; + }, + securityHandler(event) { + event.preventDefault(); + + event.returnValue = true; } }, mounted() { @@ -195,9 +200,7 @@ export default { STUDIP.wysiwyg.replace(textarea).then((editor) => { editor.model.document.on('change:data', () => { - if (this.autosave) { - this.isChanged = true; - } + this.isChanged = editor.getData() !== this.content; }); if (this.isEditing) { @@ -227,6 +230,15 @@ export default { }, () => this.getUpdaterData() ) + }, + watch: { + isChanged(current) { + if (current) { + window.addEventListener('beforeunload', this.securityHandler); + } else { + window.removeEventListener('beforeunload', this.securityHandler); + } + } } } </script> |
