diff --git a/public/static/js/game.js b/public/static/js/game.js index 8a835c0..0f557ee 100644 --- a/public/static/js/game.js +++ b/public/static/js/game.js @@ -16,7 +16,7 @@ initialize: function () { document.getElementById('loading').style.visibility = 'visible'; - document.getElementById('guessCover').style.visibility = 'visible'; + document.getElementById('panoCover').style.visibility = 'visible'; document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS); document.getElementById('currentScoreSum').innerHTML = '0/0'; @@ -27,7 +27,7 @@ MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () { document.getElementById('loading').style.visibility = 'hidden'; - document.getElementById('guessCover').style.visibility = 'hidden'; + document.getElementById('panoCover').style.visibility = 'hidden'; if (this.response.error) { //TODO: handle this error @@ -98,7 +98,7 @@ lastRound.line.setVisible(false); } - document.getElementById('guessCover').style.visibility = 'hidden'; + document.getElementById('panoCover').style.visibility = 'hidden'; document.getElementById('showGuessButton').style.visibility = null; document.getElementById('guess').style.visibility = null; document.getElementById('guess').classList.remove('result') @@ -152,7 +152,7 @@ document.getElementById('guess').classList.remove('adapt'); } document.getElementById('loading').style.visibility = 'visible'; - document.getElementById('guessCover').style.visibility = 'visible'; + document.getElementById('panoCover').style.visibility = 'visible'; var data = new FormData(); data.append('lat', String(guessPosition.lat)); @@ -370,6 +370,14 @@ } }; + MapGuesser.sessionAvailableHooks.reinitializeGame = function () { + MapGuesser.httpRequest('GET', '/game/' + mapId + '/json', function () { + mapBounds = this.response.bounds; + + Game.initialize(); + }); + }; + if (!('ontouchstart' in document.documentElement)) { Game.adaptGuess = true; } diff --git a/public/static/js/mapguesser.js b/public/static/js/mapguesser.js index cc7198f..0af777a 100644 --- a/public/static/js/mapguesser.js +++ b/public/static/js/mapguesser.js @@ -1,4 +1,49 @@ var MapGuesser = { + cookiesAgreed: false, + sessionAvailableHooks: {}, + + initGoogleAnalitics: function () { + if (typeof GOOGLE_ANALITICS_ID === 'undefined') { + return; + } + + // Global site tag (gtag.js) - Google Analytics + var script = document.createElement('script'); + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GOOGLE_ANALITICS_ID; + script.async = true; + + document.head.appendChild(script); + + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', GOOGLE_ANALITICS_ID); + }, + + agreeCookies: function () { + if (MapGuesser.cookiesAgreed) { + return; + } + + var expirationDate = new Date(new Date().getTime() + 20 * 365 * 24 * 60 * 60 * 1000).toUTCString(); + document.cookie = 'COOKIES_CONSENT=1; expires=' + expirationDate + '; path=/'; + + MapGuesser.initGoogleAnalitics(); + MapGuesser.httpRequest('GET', '/startSession.json', function () { + ANTI_CSRF_TOKEN = this.response.antiCsrfToken; + + for (var hookId in MapGuesser.sessionAvailableHooks) { + if (!MapGuesser.sessionAvailableHooks.hasOwnProperty(hookId)) { + continue; + } + + MapGuesser.sessionAvailableHooks[hookId](); + } + }); + + MapGuesser.cookiesAgreed = true; + }, + httpRequest: function (method, url, callback, data) { var xhr = new XMLHttpRequest(); diff --git a/views/admin/map_editor.php b/views/admin/map_editor.php index 28b6c4d..5b8d74a 100644 --- a/views/admin/map_editor.php +++ b/views/admin/map_editor.php @@ -59,18 +59,20 @@ $jsFiles = [ -
-No panorama is available for this location.
-No panorama is available for this location.
+