forked from VadimDez/ng2-pdf-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bugfix/search-single-page'
- Loading branch information
Showing
2 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |