Path: blob/main/ehtsite/assets/games/subway/js/boot.js
2252 views
/* eslint-disable func-names */1/* eslint-disable no-var */2/** Load script file */3function loadScript(path, onComplete)4{5var script = document.createElement('script');67if (onComplete) script.onload = onComplete;8script.src = path;9document.head.appendChild(script);10}1112/** Start up Poki SDK */13function initPokiSDK(onComplete)14{15var PokiSDK = window.PokiSDK;1617// No PokiSDK available, move on.18if (!PokiSDK) return onComplete();1920// Promise callback, should be dispatched either way21function onInitComplete(adBlockerOn)22{23PokiSDK.adBlockerOn = adBlockerOn;24PokiSDK.gameLoadingStart();25if (onComplete) onComplete();26}2728// Init the SDK and notify about loading start29return PokiSDK.init()30.then(function ()31{32onInitComplete(false);33})34.catch(function ()35{36onInitComplete(true);37});38}3940/** Init app */41function initApp()42{43// Set SDK debug mode44if (window.PokiSDK && window.GAME_CONFIG && window.GAME_CONFIG.pokiSdkDebug !== undefined)45{46window.PokiSDK.setDebug(window.GAME_CONFIG.pokiSdkDebug);47}4849loadScript('./js/dependencies.bundle.js');50loadScript(window.MAIN ? window.MAIN : './js/index.js');51}5253/** Prevent arrows and space from scrolling browser */54function preventDefaultKeyboardEvents()55{56const keys = [57' ',58'ArrowUp',59'ArrowDown',60'ArrowLeft',61'ArrowRight',62];6364function onKey(e)65{66if (keys.indexOf(e.key) < 0) return;67e.preventDefault();68}6970window.addEventListener('keydown', onKey);71window.addEventListener('keyup', onKey);72}7374function registerServiceWorker(onComplete)75{76if (navigator.serviceWorker && !window.NOSW)77{78console.log('Service worker available');79navigator.serviceWorker.register('./sw.js', { scope: './' })80.then(function ()81{82console.log('Service worker registered');83if (onComplete) onComplete();84})85.catch(function (error)86{87// eslint-disable-next-line prefer-template88console.log('Service worker registration failed - ' + error);89if (onComplete) onComplete();90});91}92else if (onComplete)93{94onComplete();95}96}9798/** Prevent default keyboard events */99preventDefaultKeyboardEvents();100101/** Register service worker if available */102registerServiceWorker(function ()103{104initPokiSDK(function ()105{106initApp();107});108});109110111112