mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-22 05:59:31 -07:00
refactor(main.ts): improve code readability by adding conditional check for ijs length before initializing stage or collection
fix(resources.ts): handle case when imagesJson element is not found to prevent error and return empty array
This commit is contained in:
@@ -16,10 +16,12 @@ initState(ijs.length)
|
|||||||
|
|
||||||
initNav()
|
initNav()
|
||||||
|
|
||||||
if (!isMobile()) {
|
if (ijs.length > 0) {
|
||||||
initStage(ijs)
|
if (!isMobile()) {
|
||||||
initStageNav()
|
initStage(ijs)
|
||||||
} else {
|
initStageNav()
|
||||||
initCollection(ijs)
|
} else {
|
||||||
initGallery(ijs)
|
initCollection(ijs)
|
||||||
|
initGallery(ijs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ export interface ImageJSON {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initResources(): ImageJSON[] {
|
export function initResources(): ImageJSON[] {
|
||||||
const imagesJson = document.getElementById('imagesSource') as HTMLScriptElement
|
const imagesJson = document.getElementById('imagesSource')
|
||||||
|
if (!imagesJson) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
return JSON.parse(imagesJson.textContent as string).sort(
|
return JSON.parse(imagesJson.textContent as string).sort(
|
||||||
(a: ImageJSON, b: ImageJSON) => {
|
(a: ImageJSON, b: ImageJSON) => {
|
||||||
if (a.index < b.index) {
|
if (a.index < b.index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user