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.
This commit is contained in:
Jonas Jenwald 2020-12-15 17:20:15 +01:00
parent 2a83c965e8
commit 0e69973d71

View File

@ -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);
});
}
}