Merge pull request #11837 from Snuffleupagus/webviewerloaded-top

Always attempt to dispatch the "webviewerloaded" event at the embedding `document` (PR 10318 follow-up, issue 11829)
This commit is contained in:
Tim van der Meij 2020-04-23 23:56:50 +02:00 committed by GitHub
commit e23d5f6022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,8 +211,20 @@ function webViewerLoad() {
// set various `AppOptions`, by dispatching an event once all viewer
// files are loaded but *before* the viewer initialization has run.
const event = document.createEvent("CustomEvent");
event.initCustomEvent("webviewerloaded", true, true, {});
document.dispatchEvent(event);
event.initCustomEvent("webviewerloaded", true, true, {
source: window,
});
try {
// Attempt to dispatch the event at the embedding `document`,
// in order to support cases where the viewer is embedded in
// a *dynamically* created <iframe> element.
parent.document.dispatchEvent(event);
} catch (ex) {
// The viewer could be in e.g. a cross-origin <iframe> element,
// fallback to dispatching the event at the current `document`.
console.error(`webviewerloaded: ${ex}`);
document.dispatchEvent(event);
}
}
pdfjsWebApp.PDFViewerApplication.run(config);