-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOfficeViewer.razor.js
More file actions
37 lines (30 loc) · 1.1 KB
/
OfficeViewer.razor.js
File metadata and controls
37 lines (30 loc) · 1.1 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
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.OfficeViewer/office-viewer.css");
const el = document.getElementById(id);
const officeViewer = { el, invoke, options };
Data.set(id, officeViewer);
await load(id, options.url);
}
export async function load(id, url) {
const officeViewer = Data.get(id);
const { el, invoke, options } = officeViewer;
el.innerHTML = '';
if (url) {
const { frame } = officeViewer;
const viewer = frame || createFrame(el);
if (options.loadedCallaback) {
viewer.onload = () => {
invoke.invokeMethodAsync(options.loadedCallaback);
};
}
viewer.src = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(url)}`;
}
}
const createFrame = el => {
const frame = document.createElement('iframe');
frame.classList.add('bb-office-viewer');
el.appendChild(frame);
return frame;
}