Show an alert when trying to close the window with unsaved changes

This commit is contained in:
Jacob Schatz 2017-07-28 20:15:32 -04:00
parent 9e806fd437
commit 8a95648b89
2 changed files with 14 additions and 0 deletions

View file

@ -17,6 +17,19 @@ function addEventsForNonVueEls() {
$(document).on('change', '.dropdown', () => {
Store.targetBranch = $('.project-refs-target-form input[name="ref"]').val();
});
window.onbeforeunload = function (e) {
const hasChanged = Store.openedFiles
.some(file => file.changed);
console.log('hasChanged',hasChanged)
if(!hasChanged) return;
e = e || window.event;
if (e) {
e.returnValue = 'Are you sure you want to lose unsaved changes?';
}
// For Safari
return 'Are you sure you want to lose unsaved changes?';
};
}
function initRepo() {

View file

@ -158,6 +158,7 @@
span.help-block {
padding-top: 7px;
margin-top: 0;
}
}