@@ -400,108 +400,126 @@ function createPlatformCardElement(platform, platform_region_flag_map, metadata_
400400 return column ;
401401}
402402
403- $ ( document ) . ready ( function ( ) {
404- // Set cache = false for all jquery ajax requests.
405- $ . ajaxSetup ( {
406- cache : false ,
407- } )
403+ /**
404+ * Map platform release regions to display flags and Bootstrap font sizes.
405+ *
406+ * @type {Object.<string, {code: string, size: string}> }
407+ */
408+ const platform_region_flag_map = {
409+ "europe" : {
410+ "code" : String . fromCodePoint ( 0x1F1EA , 0x1F1FA ) ,
411+ "size" : "fs-2" ,
412+ } ,
413+ "north_america" : {
414+ "code" : String . fromCodePoint ( 0x1F1FA , 0x1F1F8 ) ,
415+ "size" : "fs-2" ,
416+ } ,
417+ "australia" : {
418+ "code" : String . fromCodePoint ( 0x1F1E6 , 0x1F1FA ) ,
419+ "size" : "fs-2" ,
420+ } ,
421+ "new_zealand" : {
422+ "code" : String . fromCodePoint ( 0x1F1F3 , 0x1F1FF ) ,
423+ "size" : "fs-2" ,
424+ } ,
425+ "japan" : {
426+ "code" : String . fromCodePoint ( 0x1F1EF , 0x1F1F5 ) ,
427+ "size" : "fs-2" ,
428+ } ,
429+ "china" : {
430+ "code" : String . fromCodePoint ( 0x1F1E8 , 0x1F1F3 ) ,
431+ "size" : "fs-2" ,
432+ } ,
433+ "asia" : {
434+ "code" : String . fromCodePoint ( 0x1F30F ) ,
435+ "size" : "fs-4" ,
436+ } ,
437+ "worldwide" : {
438+ "code" : String . fromCodePoint ( 0x1F30E ) ,
439+ "size" : "fs-4" ,
440+ } ,
441+ "korea" : {
442+ "code" : String . fromCodePoint ( 0x1F1F0 , 0x1F1F7 ) ,
443+ "size" : "fs-2" ,
444+ } ,
445+ "brazil" : {
446+ "code" : String . fromCodePoint ( 0x1F1E7 , 0x1F1F7 ) ,
447+ "size" : "fs-2" ,
448+ } ,
449+ }
408450
409- // get platform cross-reference from json
410- let platform_xref
411- let get_platform_xref = function ( ) {
412- $ . ajax ( {
413- url : `${ base_url } /platforms/cross-reference.json` ,
414- type : "GET" ,
415- dataType : "json" ,
416- async : false , // this is false, so we can set the platform_xref variable
417- success : function ( result ) {
418- platform_xref = result
419- }
420- } )
421- }
451+ /**
452+ * Map platform version metadata keys to Material Symbols icon names.
453+ *
454+ * Keys with null values are rendered by specialized handlers.
455+ *
456+ * @type {Object.<string, string|null> }
457+ */
458+ const metadata_key_icon_map = {
459+ // material icons
460+ 'os' : 'code_blocks' ,
461+ 'cpu' : 'memory' ,
462+ 'graphics' : 'developer_board' ,
463+ 'memory' : 'memory_alt' ,
464+ 'storage' : 'storage' ,
465+ 'media' : 'save' ,
466+ 'connectivity' : 'cable' ,
467+ 'output' : 'settings_input_component' ,
468+ 'resolutions' : 'aspect_ratio' ,
469+ 'sound' : 'volume_up' ,
470+ // these will be processed slightly differently
471+ 'platform_version_release_dates' : null ,
472+ 'summary' : null ,
473+ }
422474
423- let platform_region_flag_map = {
424- "europe" : {
425- "code" : String . fromCodePoint ( 0x1F1EA , 0x1F1FA ) ,
426- "size" : "fs-2" ,
427- } ,
428- "north_america" : {
429- "code" : String . fromCodePoint ( 0x1F1FA , 0x1F1F8 ) ,
430- "size" : "fs-2" ,
431- } ,
432- "australia" : {
433- "code" : String . fromCodePoint ( 0x1F1E6 , 0x1F1FA ) ,
434- "size" : "fs-2" ,
435- } ,
436- "new_zealand" : {
437- "code" : String . fromCodePoint ( 0x1F1F3 , 0x1F1FF ) ,
438- "size" : "fs-2" ,
439- } ,
440- "japan" : {
441- "code" : String . fromCodePoint ( 0x1F1EF , 0x1F1F5 ) ,
442- "size" : "fs-2" ,
443- } ,
444- "china" : {
445- "code" : String . fromCodePoint ( 0x1F1E8 , 0x1F1F3 ) ,
446- "size" : "fs-2" ,
447- } ,
448- "asia" : {
449- "code" : String . fromCodePoint ( 0x1F30F ) ,
450- "size" : "fs-4" ,
451- } ,
452- "worldwide" : {
453- "code" : String . fromCodePoint ( 0x1F30E ) ,
454- "size" : "fs-4" ,
455- } ,
456- "korea" : {
457- "code" : String . fromCodePoint ( 0x1F1F0 , 0x1F1F7 ) ,
458- "size" : "fs-2" ,
459- } ,
460- "brazil" : {
461- "code" : String . fromCodePoint ( 0x1F1E7 , 0x1F1F7 ) ,
462- "size" : "fs-2" ,
463- } ,
464- }
475+ /**
476+ * Fetch a JSON resource without using the browser HTTP cache.
477+ *
478+ * @param {string } url - URL to load.
479+ * @returns {Promise<object> } Parsed JSON response.
480+ */
481+ function fetchJson ( url ) {
482+ return fetch ( url , { cache : "no-store" } ) . then ( response => response . json ( ) ) ;
483+ }
465484
466- let metadata_key_icon_map = {
467- // material icons
468- 'os' : 'code_blocks' ,
469- 'cpu' : 'memory' ,
470- 'graphics' : 'developer_board' ,
471- 'memory' : 'memory_alt' ,
472- 'storage' : 'storage' ,
473- 'media' : 'save' ,
474- 'connectivity' : 'cable' ,
475- 'output' : 'settings_input_component' ,
476- 'resolutions' : 'aspect_ratio' ,
477- 'sound' : 'volume_up' ,
478- // these will be processed slightly differently
479- 'platform_version_release_dates' : null ,
480- 'summary' : null ,
481- }
485+ /**
486+ * Render platform cards after enriching IGDB platform data with cross-reference metadata.
487+ *
488+ * @param {Object.<string, object> } result - Platform records keyed by source identifier.
489+ * @param {Object.<string, object> } platform_xref - Platform cross-reference records.
490+ * @returns {void }
491+ */
492+ function renderPlatformCards ( result , platform_xref ) {
493+ const platforms = processPlatformsData ( result , platform_xref ) ;
494+ const sorted = platforms . toSorted ( globalThis . rankingSorter ( "name" , "id" ) ) . reverse ( ) ;
482495
496+ for ( let item in sorted ) {
497+ const column = createPlatformCardElement ( sorted [ item ] , platform_region_flag_map , metadata_key_icon_map , base_path ) ;
498+ platforms_container . appendChild ( column ) ;
499+ }
500+ }
483501
484- // create platform cards
485- let initialize = function ( ) {
486- $ . ajax ( {
487- url : `${ base_url } /platforms/all.json` ,
488- type : "GET" ,
489- dataType :"json" ,
490- success : function ( result ) {
491- const platforms = processPlatformsData ( result , platform_xref ) ;
492- const sorted = platforms . toSorted ( globalThis . rankingSorter ( "name" , "id" ) ) . reverse ( ) ;
502+ /**
503+ * Load platform cross-reference and platform data, then render the platform card grid.
504+ *
505+ * @returns {Promise<void> } Resolves when platform cards have been rendered.
506+ */
507+ function initializePlatformCards ( ) {
508+ return fetchJson ( `${ base_url } /platforms/cross-reference.json` )
509+ . then ( platform_xref => fetchJson ( `${ base_url } /platforms/all.json` )
510+ . then ( result => {
511+ renderPlatformCards ( result , platform_xref ) ;
512+ } ) ) ;
513+ }
493514
494- for ( let item in sorted ) {
495- const column = createPlatformCardElement ( sorted [ item ] , platform_region_flag_map , metadata_key_icon_map , base_path ) ;
496- platforms_container . appendChild ( column ) ;
497- }
498- }
515+ /* istanbul ignore next */
516+ if ( typeof module === "undefined" ) {
517+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
518+ initializePlatformCards ( ) . catch ( error => {
519+ console . error ( "Failed to initialize platform cards" , error ) ;
499520 } ) ;
500- }
501-
502- get_platform_xref ( )
503- initialize ( )
504- } )
521+ } ) ;
522+ }
505523
506524/**
507525 * Search for games by name across all buckets.
@@ -609,6 +627,9 @@ if (typeof module !== "undefined") {
609627 addMetadataItemToFooter,
610628 processPlatformsData,
611629 createPlatformCardElement,
630+ fetchJson,
631+ renderPlatformCards,
632+ initializePlatformCards,
612633 run_search,
613634 } ;
614635}
0 commit comments