feat: editor - warn on leave without save
This commit is contained in:
		| @@ -118,6 +118,7 @@ export default { | |||||||
|       dialogProgress: false, |       dialogProgress: false, | ||||||
|       dialogEditorSelector: false, |       dialogEditorSelector: false, | ||||||
|       dialogUnsaved: false, |       dialogUnsaved: false, | ||||||
|  |       exitConfirmed: false, | ||||||
|       initContentParsed: '' |       initContentParsed: '' | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| @@ -161,6 +162,14 @@ export default { | |||||||
|     } else { |     } else { | ||||||
|       this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}` |       this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}` | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     window.onbeforeunload = () => { | ||||||
|  |       if (!this.exitConfirmed && this.initContentParsed !== this.$store.get('editor/content')) { | ||||||
|  |         return 'You have unsaved edits. Are you sure you want to leave the editor?' | ||||||
|  |       } else { | ||||||
|  |         return undefined | ||||||
|  |       } | ||||||
|  |     } | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     openPropsModal(name) { |     openPropsModal(name) { | ||||||
| @@ -263,6 +272,7 @@ export default { | |||||||
|     exitGo() { |     exitGo() { | ||||||
|       this.$store.commit(`loadingStart`, 'editor-close') |       this.$store.commit(`loadingStart`, 'editor-close') | ||||||
|       this.currentEditor = '' |       this.currentEditor = '' | ||||||
|  |       this.exitConfirmed = true | ||||||
|       _.delay(() => { |       _.delay(() => { | ||||||
|         if (this.$store.get('editor/mode') === 'create') { |         if (this.$store.get('editor/mode') === 'create') { | ||||||
|           window.location.assign(`/`) |           window.location.assign(`/`) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user