diff --git a/resources/assets/javascripts/lib/wiki.js b/resources/assets/javascripts/lib/wiki.js index 5e273c366a0e3a086cb74490893da2f79b4e9bdc..4f68fc945c2ed02698f30825ed053307e0254642 100644 --- a/resources/assets/javascripts/lib/wiki.js +++ b/resources/assets/javascripts/lib/wiki.js @@ -76,6 +76,10 @@ const Wiki = { this.$nextTick(() => { this.editor.editing.view.focus(); }); + }, + securityHandler(event) { + event.preventDefault(); + event.returnValue = true; } }, mounted() { @@ -86,7 +90,7 @@ const Wiki = { editor.editing.view.focus(); } editor.model.document.on('change:data',() => { - this.isChanged = true; + this.isChanged = editor.getData() !== this.content; this.lastChangeDate = new Date(); }); this.editor = editor; @@ -99,6 +103,15 @@ const Wiki = { .sort((a, b) => a.fullname.localeCompare(b.fullname)); } }, + watch: { + isChanged(current) { + if (current) { + window.addEventListener('beforeunload', this.securityHandler); + } else { + window.removeEventListener('beforeunload', this.securityHandler); + } + } + }, components: { WikiEditorOnlineUsers } }); }).then((app) => {