Fix indent

This commit is contained in:
toasted-nutbread 2020-02-15 19:46:20 -05:00
parent f8f03f3af0
commit 1944f7a215

View File

@ -18,43 +18,43 @@
class PageExitPrevention { class PageExitPrevention {
constructor() { constructor() {
} }
start() { start() {
PageExitPrevention._addInstance(this); PageExitPrevention._addInstance(this);
} }
end() { end() {
PageExitPrevention._removeInstance(this); PageExitPrevention._removeInstance(this);
} }
static _addInstance(instance) { static _addInstance(instance) {
const size = PageExitPrevention._instances.size; const size = PageExitPrevention._instances.size;
PageExitPrevention._instances.set(instance, true); PageExitPrevention._instances.set(instance, true);
if (size === 0) { if (size === 0) {
window.addEventListener('beforeunload', PageExitPrevention._onBeforeUnload); window.addEventListener('beforeunload', PageExitPrevention._onBeforeUnload);
} }
} }
static _removeInstance(instance) { static _removeInstance(instance) {
if ( if (
PageExitPrevention._instances.delete(instance) && PageExitPrevention._instances.delete(instance) &&
PageExitPrevention._instances.size === 0 PageExitPrevention._instances.size === 0
) { ) {
window.removeEventListener('beforeunload', PageExitPrevention._onBeforeUnload); window.removeEventListener('beforeunload', PageExitPrevention._onBeforeUnload);
} }
} }
static _onBeforeUnload(e) { static _onBeforeUnload(e) {
if (PageExitPrevention._instances.size === 0) { if (PageExitPrevention._instances.size === 0) {
return; return;
} }
e.preventDefault(); e.preventDefault();
e.returnValue = ''; e.returnValue = '';
return ''; return '';
} }
} }
PageExitPrevention._instances = new Map(); PageExitPrevention._instances = new Map();