var links = []; var curTime = 0; var fullScreen = false; var satelliteSection = "satellites"; var latestDateSynced = false; var playing = false; var v = 1000; var slideInterval = setInterval(function() {}, v); clearInterval(slideInterval); var satelliteAjaxTimeout = 15000; function getSatelliteDomenId() { var domen = $('input:radio[name=domenSel]:checked').val(); if (domen !== undefined && domen !== null && domen !== '') { return domen; } domen = $('#domen').val(); if (domen !== undefined && domen !== null && domen !== '') { return domen; } return null; } function withSatelliteDomen(data) { var payload = data || {}; var idDomen = getSatelliteDomenId(); if (idDomen !== null) { payload.id_domen = idDomen; } if (window.HmcDataAccess) { payload = HmcDataAccess.withSite(payload); } else if (!payload.hmc_site) { payload.hmc_site = 'satellites'; } return payload; } function hideSatelliteLoading() { $("#plug").hide(); } function satelliteNotFoundElement() { if ($("#not_found").length) { return $("#not_found"); } return $("#not_find"); } function showSatelliteNotFound(opts) { hideSatelliteLoading(); $("#map").hide(); var el = satelliteNotFoundElement(); if (window.HmcDataAccess) { HmcDataAccess.fillNotFoundMessage(el, opts || {}); } // .not-found uses flex centering; jQuery .show() would force display:block. if (el.hasClass('not-found') || el.is('#not_found')) { el.css('display', 'flex'); } else { el.show(); } } jQuery(function($) { $("#date").change(function() { if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } var date = $("#date").val(); $.ajax({ type: "POST", url: "php/date/date.php", data: {date: date} }).done(function(result) {}); getTime(); }); $( "#map" ).on("load", function() { if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } satelliteNotFoundElement().hide(); $( "#plug" ).hide(); $( "#map" ).show(); }); $("#map").on("error", function() { showSatelliteNotFound({ authRequired: false }); }); $("#previous").click(function() { pause(); curTime = previous(); }); $("#next").click(function() { pause(); curTime = next(); }); $("input:radio[name=speed]").change(function() { pause(); v = $('input:radio[name=speed]:checked').val(); }); $("#pause").click(function() { if(playing) pause (); else curTime = play(v); }); var map = document.getElementById('map'); map.addEventListener("wheel", function(e) { if(!($("#popup").length) && document.documentElement.clientWidth > 849) { if (e.deltaY < 0) { curTime = previous(); } else if (e.deltaY > 0) { curTime = next(); } } }); let started = false; let x = 0, y = 0; let newX = 0, newY = 0; let deltaX = 0, deltaY = 0; let touch = null; map.addEventListener("touchstart", function(event) { if (event.touches.length != 1 || started) return; touch = event.changedTouches[0]; x = touch.pageX; y = touch.pageY; }); map.addEventListener("touchmove", function() { started = true; }); map.addEventListener("touchend", function(event) { if (!started) return; newX = event.changedTouches[0].pageX; newY = event.changedTouches[0].pageY; deltaX = newX - x; deltaY = newY - y; event.preventDefault(); if(Math.abs(deltaX) >= Math.abs(deltaY)) { if (deltaX < 0) next(); else previous(); } [x, y, newX, newY, deltaX, deltaY, started] = [0, 0, 0, 0, 0, 0, false]; }); $(document).keyup(function(e){ if(!($("#popup").length)) { if (e.which == 37) { curTime = previous(); } } }); $(document).keyup(function(e){ if(!($("#popup").length)) { if (e.which == 39) { curTime = next(); } } }); }); function getSatelliteList(section) { satelliteSection = section; var requestToken = window._analysisLoadToken || 0; $.ajax({ type: "POST", url: "../assets/php/satellite/satellitehandler.php", data: withSatelliteDomen({id_section: section}), beforeSend: function() { $("#map").hide(); $("#plug").show(); }, timeout: satelliteAjaxTimeout }).done(function(result) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } $("#satellite_wrapper").empty(); $("#satellite_wrapper").html(result); getChannelList(); }).fail(function() { if (requestToken !== (window._analysisLoadToken || 0)) { return; } showSatelliteNotFound({ authRequired: false }); }); } function getChannelList() { var satellite = $('input:radio[name=satelliteSel]:checked').val(); var requestToken = window._analysisLoadToken || 0; pause(); $.ajax({ type: "POST", url: "../assets/php/satellite/channelhandler.php", data: withSatelliteDomen({ id_section: satelliteSection, id_satellite: satellite }), beforeSend: function() { $("#map").hide(); $("#plug").show(); }, timeout: satelliteAjaxTimeout }).done(function(result) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } $("#channel_wrapper").empty(); $("#channel_wrapper").html(result); if (!document.querySelector('#channel_wrapper input')) { showSatelliteNotFound({ authRequired: false }); return; } document.querySelector('#channel_wrapper input').checked = true; let satelliteId = sessionStorage.getItem('selectedSatelliteId'); let channelId = sessionStorage.getItem('selectedSatelliteChannelId'); let currentSatellite = $('input:radio[name=satelliteSel]:checked').val(); if(satelliteId && satelliteId === currentSatellite) { document.querySelectorAll('#satellite_wrapper input').forEach((item) => { if(item.value == satelliteId) item.checked = true; }); if(channelId) { document.querySelectorAll('#channel_wrapper input').forEach((item) => { if(item.value == channelId) item.checked = true; }); } } sessionStorage.setItem('selectedSatelliteId', currentSatellite); if (!latestDateSynced) { syncLatestDate(); } else { getTime(); } }).fail(function() { showSatelliteNotFound({ authRequired: false }); }); } function parseJsonResponse(result) { if (typeof result === "string") { return JSON.parse(result); } return result; } function syncLatestDate() { var satellite = $('input:radio[name=satelliteSel]:checked').val(); var channel = $('input:radio[name=channelSel]:checked').val(); $.ajax({ type: "POST", url: "../assets/php/satellite/lasttimehandler.php", data: withSatelliteDomen({ id_section: satelliteSection, id_satellite: satellite, id_channel: channel }), timeout: satelliteAjaxTimeout }).done(function(result) { latestDateSynced = true; var payload = parseJsonResponse(result); if (payload.date) { $("#date").val(payload.date); $.ajax({ type: "POST", url: "php/date/date.php", data: {date: payload.date} }); } getTime(); }).fail(function() { latestDateSynced = true; getTime(); }); } function getTime() { var satellite = $('input:radio[name=satelliteSel]:checked').val(); var channel = $('input:radio[name=channelSel]:checked').val(); var date = formDate($("#date").val()); var requestToken = window._analysisLoadToken || 0; sessionStorage.setItem('selectedSatelliteChannelId', channel); pause(); $.ajax({ type: "POST", url: "../assets/php/satellite/timehandler.php", data: withSatelliteDomen({ id_section: satelliteSection, id_satellite: satellite, id_channel: channel, date: date }), beforeSend: function() { $("#map").hide(); $("#plug").show(); }, timeout: satelliteAjaxTimeout }).done(function(result) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } $("#time_wrapper").empty(); $("#time_wrapper").html(result); getLink(); }).fail(function(xhr) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } var authRequired = window.HmcDataAccess && HmcDataAccess.handleAjaxError(xhr); showSatelliteNotFound({ authRequired: !!authRequired }); }); } function getLink() { var satellite = $('input:radio[name=satelliteSel]:checked').val(); var channel = $('input:radio[name=channelSel]:checked').val(); var date = formDate($("#date").val()); var requestToken = window._analysisLoadToken || 0; pause(); $.ajax({ type: "POST", url: "../assets/php/satellite/linkhandler.php", data: withSatelliteDomen({ id_section: satelliteSection, id_satellite: satellite, id_channel: channel, date: date }), beforeSend: function() { $("#map").hide(); $("#plug").show(); }, timeout: satelliteAjaxTimeout }).done(function(result) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } if (typeof getActiveSource === "function" && getActiveSource() !== "satellite") { return; } window.curTime = 0; window.links = parseJsonResponse(result); links = window.links; if (window.links && window.links.error === 'auth_required_for_recent') { if (window.HmcDataAccess) HmcDataAccess.updateBanner(window.links.reason || ''); showSatelliteNotFound({ authRequired: true }); return; } if (!window.links || !window.links.length) { showSatelliteNotFound({ authRequired: false }); return; } border(0); if (typeof analysisSetMapSrc === "function") { analysisSetMapSrc(window.links[0]); } else { $("#map").attr("src", window.links[0]); } $("#full-screen__map").attr("src", window.links[0]); $("#map").show(); $("#plug").hide(); satelliteNotFoundElement().hide(); }).fail(function(xhr) { if (requestToken !== (window._analysisLoadToken || 0)) { return; } var authRequired = window.HmcDataAccess && HmcDataAccess.handleAjaxError(xhr); showSatelliteNotFound({ authRequired: !!authRequired }); }); } function getImg(time) { pause(); window.curTime = time; border(window.curTime); $("#map").attr("src", window.links[window.curTime]); $("#full-screen__map").attr("src", window.links[window.curTime]); } function previous() { pause(); if(curTime == 0) curTime = window.links.length - 1 else curTime--; border(curTime); $("#map").attr("src", window.links[curTime]); $("#full-screen__map").attr("src", window.links[curTime]); if(fullScreen) $("#popup_img").attr("src", window.links[curTime]); return curTime; } function next() { pause(); if(curTime == window.links.length - 1) curTime = 0 else curTime++; border(curTime); $("#map").attr("src", window.links[curTime]); $("#full-screen__map").attr("src", window.links[curTime]); if(fullScreen) $("#popup_img").attr("src", window.links[curTime]); return curTime; } function pause () { document.getElementById("pause").classList.remove("pause"); document.getElementById("pause").classList.add("triangle"); playing = false; clearInterval(window.slideInterval); } function play (v) { document.getElementById("pause").classList.add("pause"); document.getElementById("pause").classList.remove("triangle"); playing = true; window.slideInterval = setInterval(function() { if(window.curTime == window.links.length - 1) window.curTime = 0 else window.curTime++; border(window.curTime); $("#map").attr("src", window.links[window.curTime]); $("#full-screen__map").attr("src", window.links[window.curTime]); }, v); return window.curTime; } function formDate(obj) { var year = obj.substring(0, 4); var month = obj.substring(5, 7); var day = obj.substring(8); var result = year + month + day; return result; } function border (obj) { var name; var linkCount = window.links ? window.links.length : 0; for(var i=0; i