From ecd7b64f3dfb42783b80af034178deebf7b9a56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 23 Oct 2018 15:35:07 +0200 Subject: [PATCH] dashboard: Remove file-added and complete event handlers on uninstall. --- packages/@uppy/dashboard/src/index.js | 35 ++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/@uppy/dashboard/src/index.js b/packages/@uppy/dashboard/src/index.js index 32d2dfe9b..5a5e420d2 100644 --- a/packages/@uppy/dashboard/src/index.js +++ b/packages/@uppy/dashboard/src/index.js @@ -155,7 +155,9 @@ module.exports = class Dashboard extends Plugin { this.maintainFocus = this.maintainFocus.bind(this) this.initEvents = this.initEvents.bind(this) - this.onKeydown = this.onKeydown.bind(this) + this.handleKeyDown = this.handleKeyDown.bind(this) + this.handleFileAdded = this.handleFileAdded.bind(this) + this.handleComplete = this.handleComplete.bind(this) this.handleClickOutside = this.handleClickOutside.bind(this) this.toggleFileCard = this.toggleFileCard.bind(this) this.toggleAddFilesPanel = this.toggleAddFilesPanel.bind(this) @@ -317,7 +319,7 @@ module.exports = class Dashboard extends Plugin { } // handle ESC and TAB keys in modal dialog - document.addEventListener('keydown', this.onKeydown) + document.addEventListener('keydown', this.handleKeyDown) // this.rerender(this.uppy.getState()) this.setFocusToBrowse() @@ -351,7 +353,7 @@ module.exports = class Dashboard extends Plugin { } // handle ESC and TAB keys in modal dialog - document.removeEventListener('keydown', this.onKeydown) + document.removeEventListener('keydown', this.handleKeyDown) this.savedActiveElement.focus() @@ -370,7 +372,7 @@ module.exports = class Dashboard extends Plugin { return !this.getPluginState().isHidden || false } - onKeydown (event) { + handleKeyDown (event) { // close modal on esc key press if (event.keyCode === ESC_KEY) this.requestCloseModal(event) // maintainFocus on tab key press @@ -457,15 +459,19 @@ module.exports = class Dashboard extends Plugin { this.ro.observe(this.el.querySelector('.uppy-Dashboard-inner')) this.uppy.on('plugin-remove', this.removeTarget) - this.uppy.on('file-added', (ev) => { - this.toggleAddFilesPanel(false) - }) - this.uppy.on('complete', ({ failed, uploadID }) => { - if (this.opts.closeAfterFinish && failed.length === 0) { - // All uploads are done - this.requestCloseModal() - } - }) + this.uppy.on('file-added', this.handleFileAdded) + this.uppy.on('complete', this.handleComplete) + } + + handleFileAdded () { + this.toggleAddFilesPanel(false) + } + + handleComplete ({ failed, uploadID }) { + if (this.opts.closeAfterFinish && failed.length === 0) { + // All uploads are done + this.requestCloseModal() + } } removeEvents () { @@ -480,7 +486,8 @@ module.exports = class Dashboard extends Plugin { // window.removeEventListener('resize', this.throttledUpdateDashboardElWidth) window.removeEventListener('popstate', this.handlePopState, false) this.uppy.off('plugin-remove', this.removeTarget) - this.uppy.off('file-added', (ev) => this.toggleAddFilesPanel(false)) + this.uppy.off('file-added', this.handleFileAdded) + this.uppy.off('complete', this.handleComplete) } toggleFileCard (fileId) {