Skip to content

Commit aa4be9c

Browse files
Support both package HTML and SB3
1 parent 87bed38 commit aa4be9c

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

docs/projects/index.html

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@
1313
<link rel="icon" type="image/svg+xml" href="resources/favicon.svg">
1414
<link rel="stylesheet" href="resources/styles.css">
1515
<script>
16-
const id = new URLSearchParams(window.location.search).get("q");
17-
18-
fetch('projects/projects.json')
19-
.then(response => response.json())
20-
.then(data => {
21-
if (id) {
22-
if (!data[id]) {
23-
window.location.href = '404.html';
24-
} else {
25-
loadProject(id, data);
26-
}
27-
} else {
28-
loadGallery(data);
29-
}
30-
})
31-
.catch(error => {
32-
console.error('Error fetching project gallery data:', error);
33-
const alert = document.createElement("div");
34-
alert.innerHTML = `<b>Error Loading Projects</b>`;
35-
alert.setAttribute("class", "alert alert-danger");
36-
alert.style.color = "darkred";
37-
document.getElementById("projectContainer").append(alert);
38-
});
39-
4016
function loadGallery(data) {
4117
if (data.length == 0) {
4218
const container = `
@@ -83,16 +59,20 @@ <h5 class="card-title text-truncate" style="margin-bottom: 0; color: darkgreen;"
8359

8460
function loadProject(id, data) {
8561
const projectName = data[id].slice(data[id].indexOf("/") + 1, data[id].lastIndexOf("/"));
86-
const project = `projects/${data[id].slice(0, data[id].indexOf("/"))}/${projectName}/${projectName}.sb3`
87-
const html = `
88-
<h1>${data[id].slice(data[id].indexOf("/") + 1, data[id].lastIndexOf("/"))}</h1>
89-
<h5 style="margin: 0; padding-bottom: 25px">${data[id].slice(0, data[id].indexOf("/"))}</h5>
90-
<div style="padding-bottom: 25px;">
91-
<a href="${project}" class="btn btn-outline-primary" download><i style="padding-right: 5px;" class="fa-solid fa-download"></i> Download Project</a>
92-
<a href="https://turbowarp.org/editor?project_url=https://brackets-coder.github.io/BlockifyVR/${project}" target="_blank" class="btn btn-outline-primary">See Inside <i style="padding-left: 5px;" class="fa-solid fa-up-right-from-square"></i></a>
93-
</div>
94-
<iframe src="https://turbowarp.org/embed?project_url=https://brackets-coder.github.io/BlockifyVR/${project}" allow="xr-spatial-tracking; vr; webxr; accelerometer; gyroscope; magnetometer" allowfullscreen allowvr="yes" frameborder="0"></iframe>`;
95-
document.getElementById("projectContainer").appendChild(document.createRange().createContextualFragment(html));
62+
let project = `projects/${data[id].slice(0, data[id].indexOf("/"))}/${projectName}/${projectName}`;
63+
let frameSrc;
64+
fetch(project + ".html").then(response => {
65+
(response.ok) ? frameSrc = project + ".html" : frameSrc = "https://turbowarp.org/embed?project_url=https://brackets-coder.github.io/BlockifyVR/" + project + ".sb3";
66+
const html = `
67+
<h1>${data[id].slice(data[id].indexOf("/") + 1, data[id].lastIndexOf("/"))}</h1>
68+
<h5 style="margin: 0; padding-bottom: 25px">${data[id].slice(0, data[id].indexOf("/"))}</h5>
69+
<div style="padding-bottom: 25px;">
70+
<a href="${project}.sb3" class="btn btn-outline-primary" download><i style="padding-right: 5px;" class="fa-solid fa-download"></i> Download Project</a>
71+
<a href="https://turbowarp.org/editor?project_url=https://brackets-coder.github.io/BlockifyVR/${project}.sb3" target="_blank" class="btn btn-outline-primary">See Inside <i style="padding-left: 5px;" class="fa-solid fa-up-right-from-square"></i></a>
72+
</div>
73+
<iframe src="${frameSrc}" allow="xr-spatial-tracking; vr; webxr; accelerometer; gyroscope; magnetometer" allowfullscreen allowvr="yes" frameborder="0"></iframe>`;
74+
document.getElementById("projectContainer").appendChild(document.createRange().createContextualFragment(html));
75+
});
9676
}
9777

9878
function searchProject(value) {
@@ -109,6 +89,30 @@ <h5 style="margin: 0; padding-bottom: 25px">${data[id].slice(0, data[id].indexOf
10989
}
11090
});
11191
}
92+
93+
const id = new URLSearchParams(window.location.search).get("q");
94+
95+
fetch('projects/projects.json')
96+
.then(response => response.json())
97+
.then(data => {
98+
if (id) {
99+
if (!data[id]) {
100+
window.location.href = '404.html';
101+
} else {
102+
loadProject(id, data);
103+
}
104+
} else {
105+
loadGallery(data);
106+
}
107+
})
108+
.catch(error => {
109+
console.error('Error fetching project gallery data:', error);
110+
const alert = document.createElement("div");
111+
alert.innerHTML = `<b>Error Loading Projects</b>`;
112+
alert.setAttribute("class", "alert alert-danger");
113+
alert.style.color = "darkred";
114+
document.getElementById("projectContainer").append(alert);
115+
});
112116
</script>
113117

114118
<style>

0 commit comments

Comments
 (0)