Skip to content

Commit

Permalink
Warn user when navigating away from unsaved changes. Fixes #64.
Browse files Browse the repository at this point in the history
  • Loading branch information
redimp committed Aug 2, 2024
1 parent 7d8d7df commit 645021c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions otterwiki/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,22 @@ <h5 class="sidebar-title"><a class="sidebar-title-link" href="{{ url_for('attach
bottom_panel,
]; // document.querySelector("#editor_block");
const preview_block = document.querySelector("#preview_block");
/* prevent user leaving with unsaved changes */
window.onbeforeunload = function(e) {
e = e || window.event;
if (!cm_editor.doc.isClean()) {
// will not be shown in modern browsers
return "You have unsaved changes.";
}
};
/* save */
document.getElementById('saveform').onsubmit = function() {
const content_editor = cm_editor.getValue();
const cm_cursor = cm_editor.getCursor();
document.getElementById('save_content').value = content_editor;
document.getElementById('save_cursor_line').value = cm_cursor.line;
document.getElementById('save_cursor_ch').value = cm_cursor.ch;
cm_editor.doc.markClean();
};
/* preview */
preview_btn.onclick = function() {
Expand Down

0 comments on commit 645021c

Please sign in to comment.