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 {
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>
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