-
-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathsample.js
More file actions
61 lines (50 loc) · 1.4 KB
/
sample.js
File metadata and controls
61 lines (50 loc) · 1.4 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
49
50
51
52
53
54
55
56
57
58
59
60
61
import { addLink, addScript, getTheme } from '../../BootstrapBlazor/modules/utility.js'
import Data from '../../BootstrapBlazor/modules/data.js'
import EventHandler from "../../BootstrapBlazor/modules/event-handler.js"
export async function init(id, invoke, options) {
await addLink('./_content/BootstrapBlazor.JitViewer/jit-viewer.css');
await addScript('./_content/BootstrapBlazor.JitViewer/lib/jit-viewer.min.js');
const el = document.getElementById(id);
if (el === null) {
return;
}
if (options.locale.startsWith('en')) {
options.locale = 'en';
}
if (options.theme === 'auto') {
options.theme = getTheme();
}
const { createViewer } = window.JitViewer;
const viewer = createViewer({
target: el,
...options
});
viewer.mount();
Data.set(id, {
el,
invoke,
viewer
});
const updateTheme = e => viewer.setTheme(e.theme);
EventHandler.on(document, 'changed.bb.theme', updateTheme);
}
export function setFile(id, file, fileName) {
const data = Data.get(id);
if (data === null) {
return;
}
const { viewer } = data;
if (viewer) {
viewer.setFile(file, fileName);
}
}
export function dispose(id) {
const data = Data.get(id);
if (data === null) {
return;
}
const { viewer } = data;
if (viewer) {
viewer.destroy();
}
}