Remove beforeunload listener for cancel button

This commit is contained in:
Sam Bigelow 2018-12-13 16:27:23 -05:00
parent 07e079e8dd
commit 5ee5203d60
3 changed files with 17 additions and 0 deletions

View File

@ -17,6 +17,11 @@ export default () => {
const currentAction = $('.js-file-title').data('currentAction');
const projectId = editBlobForm.data('project-id');
const commitButton = $('.js-commit-button');
const cancelLink = $('.btn.btn-cancel');
cancelLink.on('click', () => {
window.onbeforeunload = null;
});
commitButton.on('click', () => {
window.onbeforeunload = null;

View File

@ -0,0 +1,5 @@
---
title: Only prompt user once when navigating away from file editor
merge_request: 23820
author: Sam Bigelow
type: fixed

View File

@ -14,6 +14,7 @@ describe('EditBlob', () => {
setFixtures(`
<div class="js-edit-blob-form">
<button class="js-commit-button"></button>
<a class="btn btn-cancel" href="#"></a>
</div>`);
blobBundle();
});
@ -27,4 +28,10 @@ describe('EditBlob', () => {
expect(window.onbeforeunload).toBeNull();
});
it('removes beforeunload listener when cancel link is clicked', () => {
$('.btn.btn-cancel').click();
expect(window.onbeforeunload).toBeNull();
});
});