-
Notifications
You must be signed in to change notification settings - Fork 72
/
pdfjs-init.js
25 lines (22 loc) · 960 Bytes
/
pdfjs-init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
// Script that loads the Hypothesis client after PDF.js is initialized.
// After making changes to this file, copy it to viewer/web/pdfjs-init.js.
// Listen for `webviewerloaded` event to configure the viewer after its files
// have been loaded but before it is initialized.
//
// PDF.js >= v2.10.377 fires this event at the parent document if it is embedded
// in a same-origin iframe. See https://github.com/mozilla/pdf.js/pull/11837.
try {
parent.document.addEventListener('webviewerloaded', onViewerLoaded);
} catch (err) {
// Parent document is cross-origin. The event will be fired at the current
// document instead.
document.addEventListener('webviewerloaded', onViewerLoaded);
}
function onViewerLoaded() {
PDFViewerApplication.initializedPromise.then(() => {
const embedScript = document.createElement('script');
embedScript.src = 'https://hypothes.is/embed.js';
document.body.appendChild(embedScript);
});
}