Skip to content

Commit

Permalink
Merge branch 'bugfix/search-single-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioDA committed Oct 12, 2018
2 parents 48e1c13 + 7faff03 commit 1ad6b5c
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/app/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from '@angular/core';
import {PDFDocumentProxy, PDFViewerParams, PDFPageProxy, PDFSource, PDFProgressData, PDFPromise} from 'pdfjs-dist';

import {createEventBus} from '../utils/event-bus-utils';

let PDFJS: any;
let PDFJSViewer: any;

Expand Down Expand Up @@ -289,7 +291,7 @@ export class PdfViewerComponent implements OnChanges, OnInit, OnDestroy {
this.pdfMultiPageLinkService = new PDFJSViewer.PDFLinkService();

const pdfOptions: PDFViewerParams | any = {
eventBus: new PDFJSViewer.EventBus(),
eventBus: createEventBus(PDFJSViewer),
container: this.element.nativeElement.querySelector('div'),
removePageBorders: true,
linkService: this.pdfMultiPageLinkService,
Expand All @@ -310,7 +312,7 @@ export class PdfViewerComponent implements OnChanges, OnInit, OnDestroy {
this.pdfSinglePageLinkService = new PDFJSViewer.PDFLinkService();

const pdfOptions: PDFViewerParams | any = {
eventBus: new PDFJSViewer.EventBus(),
eventBus: createEventBus(PDFJSViewer),
container: this.element.nativeElement.querySelector('div'),
removePageBorders: true,
linkService: this.pdfSinglePageLinkService,
Expand Down Expand Up @@ -458,4 +460,5 @@ export class PdfViewerComponent implements OnChanges, OnInit, OnDestroy {
}

}

}
121 changes: 121 additions & 0 deletions src/app/utils/event-bus-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
function _createEventBus(pdfJsViewer: any): any {

const globalEventBus = new pdfJsViewer.EventBus(true);
attachDOMEventsToEventBus(globalEventBus);

return globalEventBus;
}


function attachDOMEventsToEventBus(eventBus: any) {
eventBus.on('documentload', function () {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('documentload', true, true, {});
window.dispatchEvent(event);
});
eventBus.on('pagerendered', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('pagerendered', true, true, {
pageNumber: evt.pageNumber,
cssTransform: evt.cssTransform,
});
evt.source.div.dispatchEvent(event);
});
eventBus.on('textlayerrendered', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('textlayerrendered', true, true, {
pageNumber: evt.pageNumber,
});
evt.source.textLayerDiv.dispatchEvent(event);
});
eventBus.on('pagechange', function (evt) {
const event = document.createEvent('UIEvents');
event.initUIEvent('pagechange', true, true, window, 0);
event['pageNumber'] = evt.pageNumber;
evt.source.container.dispatchEvent(event);
});
eventBus.on('pagesinit', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('pagesinit', true, true, null);
evt.source.container.dispatchEvent(event);
});
eventBus.on('pagesloaded', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('pagesloaded', true, true, {
pagesCount: evt.pagesCount,
});
evt.source.container.dispatchEvent(event);
});
eventBus.on('scalechange', function (evt) {
const event = document.createEvent('UIEvents');
event.initUIEvent('scalechange', true, true, window, 0);
event['scale'] = evt.scale;
event['presetValue'] = evt.presetValue;
evt.source.container.dispatchEvent(event);
});
eventBus.on('updateviewarea', function (evt) {
const event = document.createEvent('UIEvents');
event.initUIEvent('updateviewarea', true, true, window, 0);
event['location'] = evt.location;
evt.source.container.dispatchEvent(event);
});
eventBus.on('find', function (evt) {
if (evt.source === window) {
return; // event comes from FirefoxCom, no need to replicate
}
const event = document.createEvent('CustomEvent');
event.initCustomEvent('find' + evt.type, true, true, {
query: evt.query,
phraseSearch: evt.phraseSearch,
caseSensitive: evt.caseSensitive,
highlightAll: evt.highlightAll,
findPrevious: evt.findPrevious,
});
window.dispatchEvent(event);
});
eventBus.on('attachmentsloaded', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('attachmentsloaded', true, true, {
attachmentsCount: evt.attachmentsCount,
});
evt.source.container.dispatchEvent(event);
});
eventBus.on('sidebarviewchanged', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('sidebarviewchanged', true, true, {
view: evt.view,
});
evt.source.outerContainer.dispatchEvent(event);
});
eventBus.on('pagemode', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('pagemode', true, true, {
mode: evt.mode,
});
evt.source.pdfViewer.container.dispatchEvent(event);
});
eventBus.on('namedaction', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('namedaction', true, true, {
action: evt.action,
});
evt.source.pdfViewer.container.dispatchEvent(event);
});
eventBus.on('presentationmodechanged', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('presentationmodechanged', true, true, {
active: evt.active,
switchInProgress: evt.switchInProgress,
});
window.dispatchEvent(event);
});
eventBus.on('outlineloaded', function (evt) {
const event = document.createEvent('CustomEvent');
event.initCustomEvent('outlineloaded', true, true, {
outlineCount: evt.outlineCount,
});
evt.source.container.dispatchEvent(event);
});
}

export const createEventBus = _createEventBus;

0 comments on commit 1ad6b5c

Please sign in to comment.