Skip to content

Commit

Permalink
confirm on leaving from playground after editor content was changed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jul 12, 2021
1 parent 472514a commit 75eefce
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ jobs:

const debounceInterval = isMobile.phone ? 1000 : 300;
let debounceId: number | null = null;
let contentChanged = false;
editor.on('change', function (_, e) {
contentChanged = true;

if (typeof window.runActionlint !== 'function') {
showError('Preparing Wasm file is not completed yet. Please wait for a while and try again.');
return;
Expand Down Expand Up @@ -138,6 +141,7 @@ jobs:
a.rel = 'noopener';
a.textContent = url;
a.className = 'has-text-info-light is-underlined';
a.addEventListener('click', e => e.stopPropagation());
ret.push(a);

rest = rest.slice(idx + url.length);
Expand Down Expand Up @@ -191,6 +195,13 @@ jobs:
window.showError = showError;
window.onCheckCompleted = onCheckCompleted;
window.dismissLoading = dismissLoading;

window.addEventListener('beforeunload', e => {
if (contentChanged) {
e.preventDefault();
e.returnValue = '';
}
});
}

try {
Expand Down

0 comments on commit 75eefce

Please sign in to comment.