-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPdfViewer.razor.js
More file actions
48 lines (39 loc) · 1.35 KB
/
PdfViewer.razor.js
File metadata and controls
48 lines (39 loc) · 1.35 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { addLink } from "../BootstrapBlazor/modules/utility.js"
import Data from "../BootstrapBlazor/modules/data.js"
export async function init(id, invoke, options) {
await addLink("./_content/BootstrapBlazor.PdfViewer/pdf-viewer.css");
const el = document.getElementById(id);
const pdfViewer = { el, invoke, options };
Data.set(id, pdfViewer);
await loadPdf(id, options.url);
}
export async function loadPdf(id, url) {
const pdfViewer = Data.get(id);
const { el, invoke, options } = pdfViewer;
if (!navigator.pdfViewerEnabled) {
await invoke.invokeMethodAsync(options.notSupportCallback);
return;
}
delete pdfViewer.frame;
el.innerHTML = '';
if (url) {
const { frame } = pdfViewer;
const viewer = frame || createFrame(el);
if (options.loadedCallaback) {
viewer.onload = () => {
invoke.invokeMethodAsync(options.loadedCallaback);
};
}
const useGoogleDocs = el.getAttribute('data-bb-google-docs') === 'true';
if (useGoogleDocs) {
url = `https://docs.google.com/viewer?url=${url}&embedded=true`
}
viewer.src = url;
}
}
const createFrame = el => {
const frame = document.createElement('iframe');
frame.classList.add('bb-pdf-viewer');
el.appendChild(frame);
return frame;
}