-
-
Notifications
You must be signed in to change notification settings - Fork 851
/
Copy pathruffle.js
53 lines (44 loc) · 1.37 KB
/
ruffle.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
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
// eslint-disable-next-line no-unused-vars
/* global __webpack_public_path__:writable */
import { Setup } from "ruffle-core";
let currentScriptURL = null;
try {
if (
document.currentScript !== undefined &&
document.currentScript !== null &&
"src" in document.currentScript &&
document.currentScript.src !== ""
) {
let src = document.currentScript.src;
// CDNs allow omitting the filename. If it's omitted, append a slash to
// prevent the last component from being dropped.
if (!src.endsWith(".js") && !src.endsWith("/")) {
src += "/";
}
currentScriptURL = new URL(".", src);
}
// eslint-disable-next-line no-unused-vars
} catch (_e) {
console.warn("Unable to get currentScript URL");
}
function publicPath(config) {
// Default to the directory where this script resides.
let path = currentScriptURL?.href ?? "";
if (
"publicPath" in config &&
config.publicPath !== null &&
config.publicPath !== undefined
) {
path = config.publicPath;
}
// Webpack expects the paths to end with a slash.
if (path !== "" && !path.endsWith("/")) {
path += "/";
}
return path;
}
Setup.installRuffle("local", {
onFirstLoad: () => {
__webpack_public_path__ = publicPath(window.RufflePlayer?.config);
},
});