Add beforeunload confirmation to prevent losing unsaved written text.
return this.currentNote.content;
},
+ setBeforeUnloadConfirmation: function (enable = true) {
+ if (enable) {
+ window.onbeforeunload = function() {
+ return true;
+ };
+ } else {
+ window.onbeforeunload = null;
+ }
+ },
+
setEditMode: function (editMode = true) {
let parent = this;
// To Edit Mode
if (editMode === true) {
+ this.setBeforeUnloadConfirmation(true);
this.titleInput = this.currentNote.title;
let draftContent = localStorage.getItem(this.currentNote.title);
else {
this.titleInput = null;
this.initialContent = null;
+ this.setBeforeUnloadConfirmation(false);
this.editMode = false;
}
},