From 0e69973d710f80ad0ced5048837f774de3635a9d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald <jonas.jenwald@gmail.com> Date: Tue, 15 Dec 2020 17:20:15 +0100 Subject: [PATCH] Add a new "pagesdestroy" event, dispatched *before* the `BaseViewer` removes an existing document This new event essentially mirrors the existing "pagesinit" event, and will allow e.g. a custom implementation of the viewer to be notified before the current PDF document is removed from the viewer. By using this new event, we're thus able to dispatch a "pageclose" event for JavaScript actions when closing the existing document. --- web/base_viewer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/base_viewer.js b/web/base_viewer.js index 1bbff87eb..df50b3761 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -460,6 +460,8 @@ class BaseViewer { */ setDocument(pdfDocument) { if (this.pdfDocument) { + this.eventBus.dispatch("pagesdestroy", { source: this }); + this._cancelRendering(); this._resetView(); @@ -1555,6 +1557,10 @@ class BaseViewer { eventBus._on("pagesinit", () => { dispatchPageOpen(this._currentPageNumber); }); + + eventBus._on("pagesdestroy", () => { + dispatchPageClose(this._currentPageNumber); + }); } }