Skip to content

Commit

Permalink
Fixes legalthings#30: Ability to unbind events registered by pdf viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
anshul-chhangani committed Sep 20, 2018
1 parent ea77fe8 commit be5561a
Showing 1 changed file with 78 additions and 26 deletions.
104 changes: 78 additions & 26 deletions pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13617,32 +13617,84 @@ var PDFViewerApplication = {
eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
eventBus.on('fileinputchange', webViewerFileInputChange);
},
bindWindowEvents: function pdfViewBindWindowEvents() {
var eventBus = this.eventBus;
window.addEventListener('wheel', webViewerWheel);
window.addEventListener('click', webViewerClick);
window.addEventListener('keydown', webViewerKeyDown);
window.addEventListener('resize', function windowResize() {
eventBus.dispatch('resize');
});
window.addEventListener('hashchange', function windowHashChange() {
eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
});
window.addEventListener('beforeprint', function windowBeforePrint() {
eventBus.dispatch('beforeprint');
});
window.addEventListener('afterprint', function windowAfterPrint() {
eventBus.dispatch('afterprint');
});
window.addEventListener('change', function windowChange(evt) {
var files = evt.target.files;
if (!files || files.length === 0) {
return;
}
if (evt.target.id == PDFViewerApplication.appConfig.openFileInputName)
eventBus.dispatch('fileinputchange', { fileInput: evt.target });
});
}
bindWindowEvents: function pdfViewBindWindowEvents() {
var eventBus = this.eventBus,
_boundEvents = this._boundEvents;
_boundEvents.windowResize = function () {
eventBus.dispatch('resize');
};
_boundEvents.windowHashChange = function () {
eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
};
_boundEvents.windowBeforePrint = function () {
eventBus.dispatch('beforeprint');
};
_boundEvents.windowAfterPrint = function () {
eventBus.dispatch('afterprint');
};
_boundEvents.windowChange = function (evt) {
var files = evt.target.files;
if (!files || files.length === 0) {
return;
}
if (evt.target.id == PDFViewerApplication.appConfig.openFileInputName)
eventBus.dispatch('fileinputchange', {fileInput: evt.target});
};
window.addEventListener('wheel', webViewerWheel);
window.addEventListener('click', webViewerClick);
window.addEventListener('keydown', webViewerKeyDown);
window.addEventListener('resize', _boundEvents.windowResize);
window.addEventListener('hashchange', _boundEvents.windowHashChange);
window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
window.addEventListener('change', _boundEvents.windowChange);
},
unbindEvents: function unbindEvents() {
var eventBus = this.eventBus;
eventBus.off('resize', webViewerResize);
eventBus.off('hashchange', webViewerHashchange);
eventBus.off('beforeprint', this.beforePrint.bind(this));
eventBus.off('afterprint', this.afterPrint.bind(this));
eventBus.off('pagerendered', webViewerPageRendered);
eventBus.off('textlayerrendered', webViewerTextLayerRendered);
eventBus.off('updateviewarea', webViewerUpdateViewarea);
eventBus.off('pagechanging', webViewerPageChanging);
eventBus.off('scalechanging', webViewerScaleChanging);
eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
eventBus.off('pagemode', webViewerPageMode);
eventBus.off('namedaction', webViewerNamedAction);
eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
eventBus.off('presentationmode', webViewerPresentationMode);
eventBus.off('openfile', webViewerOpenFile);
eventBus.off('print', webViewerPrint);
eventBus.off('download', webViewerDownload);
eventBus.off('firstpage', webViewerFirstPage);
eventBus.off('lastpage', webViewerLastPage);
eventBus.off('nextpage', webViewerNextPage);
eventBus.off('previouspage', webViewerPreviousPage);
eventBus.off('zoomin', webViewerZoomIn);
eventBus.off('zoomout', webViewerZoomOut);
eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
eventBus.off('scalechanged', webViewerScaleChanged);
eventBus.off('rotatecw', webViewerRotateCw);
eventBus.off('rotateccw', webViewerRotateCcw);
eventBus.off('documentproperties', webViewerDocumentProperties);
eventBus.off('find', webViewerFind);
eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
eventBus.off('fileinputchange', webViewerFileInputChange);
},
unbindWindowEvents: function unbindWindowEvents() {
var _boundEvents = this._boundEvents;

window.removeEventListener('wheel', webViewerWheel);
window.removeEventListener('click', webViewerClick);
window.removeEventListener('keydown', webViewerKeyDown);
window.removeEventListener('resize', _boundEvents.windowResize);
window.removeEventListener('hashchange', _boundEvents.windowHashChange);
window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
window.removeEventListener('change', _boundEvents.windowChange);
}
};
var validateFileURL;
var HOSTED_VIEWER_ORIGINS = [
Expand Down

0 comments on commit be5561a

Please sign in to comment.