@@ -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+
364433document . addEventListener ( "DOMContentLoaded" , ( ) => {
365434 loadItemDetail ( "games" , renderGame ) ;
366435} ) ;
0 commit comments