Commit da28312a authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

prevent accidental loss of changes in content editor. refs #303

parent 984212a2
Pipeline #1089 failed with stage
......@@ -80,6 +80,21 @@ function editor (CodeMirror, SimpleMDE, el, opts) {
containerEl.classList.toggle('editor-container-active', editor.codemirror.hasFocus())
})
// prevent users from accidentally leaving the page when
// they’ve changed the content of the editor
let editorHasChanged = false
const changeListener = on(codemirrorEvents, 'change', () => {
editorHasChanged = true
})
const beforeUnloadListener = on(window, 'beforeunload', event => {
const message = 'Du hast Änderungen am Inhalt vorgenommen. Bist du sicher, dass du die ' +
'Seite verlassen willst?'
if (editorHasChanged) {
event.returnValue = message
return message
}
})
// whenever images have been selected and uploaded insert image
// markdown image references into the editor
imageEditor.emitter.on('files:select', files => {
......@@ -123,6 +138,8 @@ function editor (CodeMirror, SimpleMDE, el, opts) {
citeListener.destroy()
scrollListener.destroy()
focusListener.destroy()
changeListener.destroy()
beforeUnloadListener.destroy()
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment