Skip to content
Snippets Groups Projects
Commit 353d62ab authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

add before unload handler to avoid data loss in wiki, fixes #4522

Closes #4522

Merge request studip/studip!3332
parent 5ddf03c0
No related branches found
No related tags found
No related merge requests found
...@@ -182,12 +182,17 @@ export default { ...@@ -182,12 +182,17 @@ export default {
online: this.isOnlineAndEditing online: this.isOnlineAndEditing
}; };
if (this.isChanged) { if (this.autosave && this.isChanged) {
data.content = this.editor.getData(); data.content = this.editor.getData();
this.isChanged = false; this.isChanged = false;
} }
return data; return data;
},
securityHandler(event) {
event.preventDefault();
event.returnValue = true;
} }
}, },
mounted() { mounted() {
...@@ -195,9 +200,7 @@ export default { ...@@ -195,9 +200,7 @@ export default {
STUDIP.wysiwyg.replace(textarea).then((editor) => { STUDIP.wysiwyg.replace(textarea).then((editor) => {
editor.model.document.on('change:data', () => { editor.model.document.on('change:data', () => {
if (this.autosave) { this.isChanged = editor.getData() !== this.content;
this.isChanged = true;
}
}); });
if (this.isEditing) { if (this.isEditing) {
...@@ -227,6 +230,15 @@ export default { ...@@ -227,6 +230,15 @@ export default {
}, },
() => this.getUpdaterData() () => this.getUpdaterData()
) )
},
watch: {
isChanged(current) {
if (current) {
window.addEventListener('beforeunload', this.securityHandler);
} else {
window.removeEventListener('beforeunload', this.securityHandler);
}
}
} }
} }
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment