From 486c84321556d9652015fe5477fd8e017fddecb1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 28 Aug 2018 09:56:26 +0200 Subject: [PATCH] Add `source` parameters to all remaining `EventBus.dispatch` calls that are currently missing those This is necessary for subsequent patches, and will help avoid unnecessary event re-dispatching in cases where the event source is `window`. --- web/app.js | 9 ++++++--- web/pdf_presentation_mode.js | 8 ++++---- web/toolbar.js | 16 ++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/web/app.js b/web/app.js index f3d063500..34a4a6adf 100644 --- a/web/app.js +++ b/web/app.js @@ -160,7 +160,7 @@ let PDFViewerApplication = { this.l10n.translate(appContainer).then(() => { // Dispatch the 'localized' event on the `eventBus` once the viewer // has been fully initialized and translated. - this.eventBus.dispatch('localized'); + this.eventBus.dispatch('localized', { source: this, }); }); this.initialized = true; @@ -1371,14 +1371,15 @@ let PDFViewerApplication = { }; _boundEvents.windowHashChange = () => { eventBus.dispatch('hashchange', { + source: window, hash: document.location.hash.substring(1), }); }; _boundEvents.windowBeforePrint = () => { - eventBus.dispatch('beforeprint'); + eventBus.dispatch('beforeprint', { source: window, }); }; _boundEvents.windowAfterPrint = () => { - eventBus.dispatch('afterprint'); + eventBus.dispatch('afterprint', { source: window, }); }; window.addEventListener('wheel', webViewerWheel); @@ -1560,6 +1561,7 @@ function webViewerInitialized() { return; } PDFViewerApplication.eventBus.dispatch('fileinputchange', { + source: this, fileInput: evt.target, }); }); @@ -1578,6 +1580,7 @@ function webViewerInitialized() { return; } PDFViewerApplication.eventBus.dispatch('fileinputchange', { + source: this, fileInput: evt.dataTransfer, }); }); diff --git a/web/pdf_presentation_mode.js b/web/pdf_presentation_mode.js index c1794b5b4..93eedb2bf 100644 --- a/web/pdf_presentation_mode.js +++ b/web/pdf_presentation_mode.js @@ -60,19 +60,19 @@ class PDFPresentationMode { if (contextMenuItems) { contextMenuItems.contextFirstPage.addEventListener('click', () => { this.contextMenuOpen = false; - this.eventBus.dispatch('firstpage'); + this.eventBus.dispatch('firstpage', { source: this, }); }); contextMenuItems.contextLastPage.addEventListener('click', () => { this.contextMenuOpen = false; - this.eventBus.dispatch('lastpage'); + this.eventBus.dispatch('lastpage', { source: this, }); }); contextMenuItems.contextPageRotateCw.addEventListener('click', () => { this.contextMenuOpen = false; - this.eventBus.dispatch('rotatecw'); + this.eventBus.dispatch('rotatecw', { source: this, }); }); contextMenuItems.contextPageRotateCcw.addEventListener('click', () => { this.contextMenuOpen = false; - this.eventBus.dispatch('rotateccw'); + this.eventBus.dispatch('rotateccw', { source: this, }); }); } } diff --git a/web/toolbar.js b/web/toolbar.js index 19b43f35e..986f638f4 100644 --- a/web/toolbar.js +++ b/web/toolbar.js @@ -100,19 +100,19 @@ class Toolbar { let self = this; items.previous.addEventListener('click', function() { - eventBus.dispatch('previouspage'); + eventBus.dispatch('previouspage', { source: self, }); }); items.next.addEventListener('click', function() { - eventBus.dispatch('nextpage'); + eventBus.dispatch('nextpage', { source: self, }); }); items.zoomIn.addEventListener('click', function() { - eventBus.dispatch('zoomin'); + eventBus.dispatch('zoomin', { source: self, }); }); items.zoomOut.addEventListener('click', function() { - eventBus.dispatch('zoomout'); + eventBus.dispatch('zoomout', { source: self, }); }); items.pageNumber.addEventListener('click', function() { @@ -137,19 +137,19 @@ class Toolbar { }); items.presentationModeButton.addEventListener('click', function() { - eventBus.dispatch('presentationmode'); + eventBus.dispatch('presentationmode', { source: self, }); }); items.openFile.addEventListener('click', function() { - eventBus.dispatch('openfile'); + eventBus.dispatch('openfile', { source: self, }); }); items.print.addEventListener('click', function() { - eventBus.dispatch('print'); + eventBus.dispatch('print', { source: self, }); }); items.download.addEventListener('click', function() { - eventBus.dispatch('download'); + eventBus.dispatch('download', { source: self, }); }); // Suppress context menus for some controls.