Skip to content

Commit 422bb90

Browse files
Replace carousel with beautiful-jekyll-next banner
Replace the Bootstrap carousel-based banner with a beautiful-jekyll-next style banner implementation. HTML: remove the carousel markup and add a hidden #game-big-imgs element to store artwork data attributes and a visible #game-banner-header with an .img-desc for captions. JS: stop building carousel items; instead set data-img-src-X and data-num-img on #game-big-imgs and introduce initGameBanner() which initializes the header background, prefetches images, and cycles them with a fade transition (timing/prefetch logic included). Keeps existing content rendering and preserves fallback when no artworks are present.
1 parent 5faa1ac commit 422bb90

2 files changed

Lines changed: 89 additions & 27 deletions

File tree

gh-pages-template/assets/js/game_detail.js

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@ function renderGame(data) {
99
document.title = (data.name || "Game") + " – GameDB";
1010
document.getElementById("game-name").textContent = data.name || "Unknown Game";
1111

12-
// Banner/Artworks carousel
12+
// Banner/Artworks (beautiful-jekyll-next style)
1313
if (data.artworks && data.artworks.length > 0) {
14-
const bannerSection = document.getElementById("game-banner-section");
15-
const bannerInner = document.getElementById("game-banner-inner");
16-
bannerSection.classList.remove("d-none");
14+
const bigImgsEl = document.getElementById("game-big-imgs");
15+
const bannerHeader = document.getElementById("game-banner-header");
1716

17+
// Set data attributes for each artwork
18+
bigImgsEl.setAttribute("data-num-img", data.artworks.length);
1819
data.artworks.forEach((artwork, index) => {
19-
const item = document.createElement("div");
20-
item.className = `carousel-item${index === 0 ? " active" : ""}`;
21-
const img = document.createElement("img");
22-
img.src = igdbImageUrl(artwork.url, "t_screenshot_huge");
23-
img.className = "d-block w-100";
24-
img.alt = `${data.name} artwork ${index + 1}`;
25-
img.style.maxHeight = "400px";
26-
img.style.objectFit = "cover";
27-
item.appendChild(img);
28-
bannerInner.appendChild(item);
20+
const imgNum = index + 1;
21+
bigImgsEl.setAttribute(`data-img-src-${imgNum}`, igdbImageUrl(artwork.url, "t_screenshot_huge"));
2922
});
23+
24+
// Show the banner
25+
bannerHeader.classList.remove("d-none");
26+
27+
// Initialize the image display (mimics beautifuljekyll.js behavior)
28+
initGameBanner();
3029
}
3130

3231
// Cover
@@ -361,6 +360,76 @@ function getRegionFlag(regionName) {
361360
return map[regionName] || "🌐";
362361
}
363362

363+
/**
364+
* Initialize game banner with cycling images (mimics beautiful-jekyll-next behavior)
365+
*/
366+
function initGameBanner() {
367+
const bigImgsEl = document.getElementById("game-big-imgs");
368+
const numImgs = parseInt(bigImgsEl.getAttribute("data-num-img"));
369+
370+
if (!numImgs || numImgs === 0) return;
371+
372+
// Set initial image
373+
const getImgInfo = function(imgNum) {
374+
const src = bigImgsEl.getAttribute(`data-img-src-${imgNum}`);
375+
const desc = bigImgsEl.getAttribute(`data-img-desc-${imgNum}`);
376+
return { src, desc };
377+
};
378+
379+
const setImg = function(src, desc) {
380+
const bannerHeader = document.getElementById("game-banner-header");
381+
bannerHeader.style.backgroundImage = `url(${src})`;
382+
383+
const imgDesc = bannerHeader.querySelector(".img-desc");
384+
if (desc && desc !== "null") {
385+
imgDesc.textContent = desc;
386+
imgDesc.style.display = "block";
387+
} else {
388+
imgDesc.style.display = "none";
389+
}
390+
};
391+
392+
// Set first image
393+
const firstImg = getImgInfo(1);
394+
setImg(firstImg.src, firstImg.desc);
395+
396+
// Cycle through images if multiple
397+
if (numImgs > 1) {
398+
let currentImgNum = 1;
399+
400+
const getNextImg = function() {
401+
currentImgNum = (currentImgNum % numImgs) + 1;
402+
const imgInfo = getImgInfo(currentImgNum);
403+
const src = imgInfo.src;
404+
const desc = imgInfo.desc;
405+
406+
// Prefetch next image
407+
const prefetchImg = new Image();
408+
prefetchImg.src = src;
409+
410+
setTimeout(function() {
411+
const img = document.createElement("div");
412+
img.className = "big-img-transition";
413+
img.style.backgroundImage = `url(${src})`;
414+
document.getElementById("game-banner-header").prepend(img);
415+
416+
setTimeout(function() {
417+
img.style.opacity = "1";
418+
}, 50);
419+
420+
// After fade-in completes, update main image and remove transition element
421+
setTimeout(function() {
422+
setImg(src, desc);
423+
img.remove();
424+
getNextImg();
425+
}, 1000);
426+
}, 6000);
427+
};
428+
429+
getNextImg();
430+
}
431+
}
432+
364433
document.addEventListener("DOMContentLoaded", () => {
365434
loadItemDetail("games", renderGame);
366435
});

gh-pages-template/browse/games.html

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,12 @@
2828

2929
<div id="item-content" class="d-none">
3030

31-
<!-- Banner Carousel -->
32-
<div id="game-banner-section" class="d-none mb-4">
33-
<div id="gameBannerCarousel" class="carousel slide" data-bs-ride="carousel">
34-
<div class="carousel-inner rounded" id="game-banner-inner"></div>
35-
<button class="carousel-control-prev" type="button" data-bs-target="#gameBannerCarousel" data-bs-slide="prev">
36-
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
37-
<span class="visually-hidden">Previous</span>
38-
</button>
39-
<button class="carousel-control-next" type="button" data-bs-target="#gameBannerCarousel" data-bs-slide="next">
40-
<span class="carousel-control-next-icon" aria-hidden="true"></span>
41-
<span class="visually-hidden">Next</span>
42-
</button>
43-
</div>
31+
<!-- Banner Images (hidden, holds data attributes) -->
32+
<div id="game-big-imgs" style="display:none;"></div>
33+
34+
<!-- Banner Header (styled like beautiful-jekyll-next cover-img) -->
35+
<div id="game-banner-header" class="intro-header big-img d-none" style="margin-top: -70px; margin-bottom: 30px;">
36+
<span class='img-desc'></span>
4437
</div>
4538

4639
<div class="row gx-4 gy-4 mb-4">

0 commit comments

Comments
 (0)