diff --git a/resources/js/CustomHandling/CustomHandling.js b/resources/js/CustomHandling/CustomHandling.js index edab8c226..40c2638b9 100644 --- a/resources/js/CustomHandling/CustomHandling.js +++ b/resources/js/CustomHandling/CustomHandling.js @@ -1,148 +1,133 @@ // START Encounter Count var menuenclblexists='no'; -function showEncounter() { - - - - var thishvurlstr = window.location.href; - - - if(thishvurlstr.search('beta.helioviewer')==-1) { - thishvapiurl= "https://api.helioviewer.org"; - } - else { +let _pspdata = new Promise((resolve, reject) => { + let thishvurlstr = window.location.href; + let thishvapiurl = "https://api.helioviewer.org"; + if(thishvurlstr.search('beta.helioviewer')!=-1) { thishvapiurl= "https://api.beta.helioviewer.org"; } - - setTimeout(function() { - - - $.getJSON(thishvapiurl+"/resources/JSON/celestial-objects/soho/psp/soho_psp_dictionary.json", function(pspdata){ + $.getJSON(thishvapiurl+"/resources/JSON/celestial-objects/soho/psp/soho_psp_dictionary.json", resolve).fail(reject); +}); - var pspenctotal= Object.keys(pspdata).length; +async function showEncounter() { + let pspdata = await _pspdata; + setTimeout(function() { + var pspenctotal= Object.keys(pspdata).length; + + + var pspencnum=0; + + // loop through each encounter + $.each(pspdata, function(pspvalue, pspkey){ + pspencnum++; - var pspencnum=0; - // loop through each encounter - $.each(pspdata, function(pspvalue, pspkey){ + //JSON.stringify(pspkey.start); + + // parse the JSON data: get the "start" value + var myPSPObj = JSON.parse(pspkey.start); + var pspstartenc = myPSPObj; + + + + // if the very first appropriate encounter div exists + if($('#soho-psp-container-hover-date-'+pspstartenc).length > 0 || $('#stereo_a-psp-trajectory-hover-date-'+pspstartenc).length > 0) { + $(".hover-date-container").removeClass("hvenclabels"); - pspencnum++; + $('.hover-date-container').css('height','33px'); + + + + + const hvencelems = document.getElementsByClassName('hvenclabels'); + while(hvencelems.length > 0){ + hvencelems[0].parentNode.removeChild(hvencelems[0]); + } + /*if($("#hvencpagination").length > 0) { + const hvencpaginationelem = document.getElementById('hvencpagination'); + hvencpaginationelem.remove(); + }*/ + + //hvencpaginationelem[0].parentNode.removeChild(hvencpaginationelem[0]); - //JSON.stringify(pspkey.start); + $(".hover-date-container").removeClass("hvenclabels"); - // parse the JSON data: get the "start" value - var myPSPObj = JSON.parse(pspkey.start); - var pspstartenc = myPSPObj; + $('.hover-date-container').append(''); + //$('#soho-psp-tree-trajectory').append(''+pspencnum+''); + $('.hvenclabels').html('
Encounter '+pspencnum); + //document.getElementsByClassName("hover-date-container").innerHTML+= '
Encounter '+pspencnum; - // if the very first appropriate encounter div exists - if($('#soho-psp-container-hover-date-'+pspstartenc).length > 0 || $('#stereo_a-psp-trajectory-hover-date-'+pspstartenc).length > 0) { - $(".hover-date-container").removeClass("hvenclabels"); - - - $('.hover-date-container').css('height','33px'); - - - - - const hvencelems = document.getElementsByClassName('hvenclabels'); - while(hvencelems.length > 0){ - hvencelems[0].parentNode.removeChild(hvencelems[0]); - } - - /*if($("#hvencpagination").length > 0) { - const hvencpaginationelem = document.getElementById('hvencpagination'); - hvencpaginationelem.remove(); - }*/ - - //hvencpaginationelem[0].parentNode.removeChild(hvencpaginationelem[0]); - - $(".hover-date-container").removeClass("hvenclabels"); - - $('.hover-date-container').append(''); - //$('#soho-psp-tree-trajectory').append(''+pspencnum+''); - - $('.hvenclabels').html('
Encounter '+pspencnum); - //document.getElementsByClassName("hover-date-container").innerHTML+= '
Encounter '+pspencnum; + if(menuenclblexists=='no') { + // prepend Encounter label + $('#soho-psp-tree-trajectory a, #stereo_a-psp-tree-trajectory a').after('

 Encounter: '); + menuenclblexists='yes'; + } + + + // START generate encounter "pagination" + if(pspencnum == 1) { + encdash1=''; + } + else { + encdash1=' - '; + } - if(menuenclblexists=='no') { - // prepend Encounter label - $('#soho-psp-tree-trajectory a, #stereo_a-psp-tree-trajectory a').after('

 Encounter: '); - menuenclblexists='yes'; + if(pspencnum == pspenctotal) { + encdash2=''; + } + else { + encdash2=' - '; } + // show current encounter in the pagination (SOHO) + $('#soho-psp-tree-trajectory .decoration').eq(1).html(encdash1+' '+pspencnum+' '+encdash2); - // START generate encounter "pagination" - - if(pspencnum == 1) { - encdash1=''; - } - else { - encdash1=' - '; - } - - if(pspencnum == pspenctotal) { - encdash2=''; - } - else { - encdash2=' - '; - } - - // show current encounter in the pagination (SOHO) - $('#soho-psp-tree-trajectory .decoration').eq(1).html(encdash1+' '+pspencnum+' '+encdash2); - - // show current encounter in the pagination (Stereo A) - $('#stereo_a-psp-tree-trajectory .decoration').eq(1).html(encdash1+' '+pspencnum+' '+encdash2); - - // make the first and last .decoration elements blank - $('#soho-psp-tree-trajectory .decoration:first, #soho-psp-tree-trajectory .decoration:last, #stereo_a-psp-tree-trajectory .decoration:first, #stereo_a-psp-tree-trajectory .decoration:last').html(''); - - - - - // get previous encounter - if(pspencnum != 1) { - encpagprev=pspencnum-1; - $('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('
 ◀ '+encpagprev); - } - else if(pspencnum == 1) { - $('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('
  '); - } - - // get next encounter - if(pspencnum != pspenctotal) { - encpagnxt=pspencnum+1; - $('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html(encpagnxt+' ▶'); - } - else if(pspencnum == pspenctotal) { - $('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html('  '); - } + // show current encounter in the pagination (Stereo A) + $('#stereo_a-psp-tree-trajectory .decoration').eq(1).html(encdash1+' '+pspencnum+' '+encdash2); + // make the first and last .decoration elements blank + $('#soho-psp-tree-trajectory .decoration:first, #soho-psp-tree-trajectory .decoration:last, #stereo_a-psp-tree-trajectory .decoration:first, #stereo_a-psp-tree-trajectory .decoration:last').html(''); - $('#soho-psp-tree-trajectory .button, #soho-psp-tree-trajectory .decoration').css('display','inline'); - $('#stereo_a-psp-tree-trajectory .button, #stereo_a-psp-tree-trajectory .decoration').css('display','inline'); - // END generate encounter "pagination" + - if(typeof datetimemobModule === 'function') { - datetimemobModule(); + // get previous encounter + if(pspencnum != 1) { + encpagprev=pspencnum-1; + $('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('
 ◀ '+encpagprev); + } + else if(pspencnum == 1) { + $('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('
  '); } + // get next encounter + if(pspencnum != pspenctotal) { + encpagnxt=pspencnum+1; + $('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html(encpagnxt+' ▶'); + } + else if(pspencnum == pspenctotal) { + $('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html('  '); + } + + + $('#soho-psp-tree-trajectory .button, #soho-psp-tree-trajectory .decoration').css('display','inline'); + $('#stereo_a-psp-tree-trajectory .button, #stereo_a-psp-tree-trajectory .decoration').css('display','inline'); + + // END generate encounter "pagination" + + if(typeof datetimemobModule === 'function') { + datetimemobModule(); } - }); - - - + } - }).fail(function(){ - console.log('Parker Solar Probe JSON failed'); }); }, 500);