-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPdfViewer.razor.js
More file actions
43 lines (37 loc) · 1.19 KB
/
PdfViewer.razor.js
File metadata and controls
43 lines (37 loc) · 1.19 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
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");
if (!navigator.pdfViewerEnabled) {
await invoke.invokeMethodAsync(options.notSupportCallback);
}
const el = document.getElementById(id);
const pdfViewer = { el, invoke, options };
Data.set(id, pdfViewer);
const url = el.getAttribute('data-bb-url');
loadPdf(id, url);
}
export function loadPdf(id, url) {
const pdfViewer = Data.get(id);
const { el } = pdfViewer;
if (url) {
const { frame, invoke, options } = pdfViewer;
const viewer = frame || createFrame(el);
if (options.loadedCallaback) {
viewer.onload = () => {
invoke.invokeMethodAsync(options.loadedCallaback);
};
}
viewer.src = url;
}
else {
delete pdfViewer.frame;
el.innerHTML = '';
}
}
const createFrame = el => {
const frame = document.createElement('iframe');
frame.classList.add('bb-pdf-viewer');
el.appendChild(frame);
return frame;
}