demo: Allow specifying file in demo via query params
This commit is contained in:
parent
a02a81f80f
commit
c3e64f1b12
|
@ -9,6 +9,7 @@ window.RufflePlayer = PublicAPI.negotiate(
|
||||||
let ruffle;
|
let ruffle;
|
||||||
let player;
|
let player;
|
||||||
let jsonData;
|
let jsonData;
|
||||||
|
let initialFile;
|
||||||
|
|
||||||
let container = document.getElementById("main");
|
let container = document.getElementById("main");
|
||||||
let author_container = document.getElementById("author-container");
|
let author_container = document.getElementById("author-container");
|
||||||
|
@ -24,6 +25,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
player = ruffle.createPlayer();
|
player = ruffle.createPlayer();
|
||||||
player.id = "player";
|
player.id = "player";
|
||||||
container.appendChild(player);
|
container.appendChild(player);
|
||||||
|
initialFile = new URLSearchParams(window.location.search).get("file");
|
||||||
fetch("swfs.json").then((response) => {
|
fetch("swfs.json").then((response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
response.json().then((data) => {
|
response.json().then((data) => {
|
||||||
|
@ -40,11 +42,22 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sampleFileInputContainer.style.display = "inline-block";
|
sampleFileInputContainer.style.display = "inline-block";
|
||||||
|
|
||||||
|
if (initialFile) {
|
||||||
|
let opts = Array.from(sampleFileInput.options).map(
|
||||||
|
(item) => item.value
|
||||||
|
);
|
||||||
|
sampleFileInput.selectedIndex = Math.max(
|
||||||
|
opts.findIndex((item) => item.endsWith(initialFile)),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
} else {
|
||||||
// Load a random file.
|
// Load a random file.
|
||||||
let rn = Math.floor(
|
let rn = Math.floor(
|
||||||
Math.random() * Math.floor(jsonData.swfs.length)
|
Math.random() * Math.floor(jsonData.swfs.length)
|
||||||
);
|
);
|
||||||
sampleFileInput.selectedIndex = rn + 1;
|
sampleFileInput.selectedIndex = rn + 1;
|
||||||
|
}
|
||||||
sampleFileSelected();
|
sampleFileSelected();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue