From 193af24a56af08b1b0d5a852ed0e013c5ffcd676 Mon Sep 17 00:00:00 2001 From: William Toohey Date: Sat, 19 Mar 2016 17:57:33 +1000 Subject: [PATCH] Warn for unsaved editor changes --- src/js/HuesEditor.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/HuesEditor.js b/src/js/HuesEditor.js index 84fbc99..4fcde42 100644 --- a/src/js/HuesEditor.js +++ b/src/js/HuesEditor.js @@ -1091,6 +1091,8 @@ HuesEditor.prototype.setText = function(editor, text, caretFromEnd) { if(commitUndo) { this.commitUndo(); } + // Make sure you can't accidentally close the tab + window.onbeforeunload = this.confirmLeave; this.song[editor._rhythm] = text; this.reflow(editor, this.song[editor._rhythm]); this.setCaret(editor._beatmap, caret); @@ -1278,6 +1280,10 @@ HuesEditor.prototype.drawOneWave = function(wave, center, width) { } catch(e) {} }; +HuesEditor.prototype.confirmLeave = function() { + return "Unsaved beatmap - leave anyway?"; +} + HuesEditor.prototype.alert = function(msg) { this.statusMsg.classList.remove("fade"); this.statusMsg.textContent = msg; @@ -1329,6 +1335,8 @@ HuesEditor.prototype.saveXML = function() { element.click(); document.body.removeChild(element); + + window.onbeforeunload = null; }; // http://stackoverflow.com/a/30810322