Skip to content

Commit

Permalink
Only run $.getJSON once
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarciabriseno committed Jan 26, 2024
1 parent a1eba37 commit 2f32c37
Showing 1 changed file with 99 additions and 114 deletions.
213 changes: 99 additions & 114 deletions resources/js/CustomHandling/CustomHandling.js
Original file line number Diff line number Diff line change
@@ -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('<span class="hvenclabels"></span>');
//$('#soho-psp-tree-trajectory').append('<span id="hvencpagination">'+pspencnum+'</span>');

$('.hvenclabels').html('<br>Encounter '+pspencnum);
//document.getElementsByClassName("hover-date-container").innerHTML+= '<br>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('<span class="hvenclabels"></span>');
//$('#soho-psp-tree-trajectory').append('<span id="hvencpagination">'+pspencnum+'</span>');

$('.hvenclabels').html('<br>Encounter '+pspencnum);
//document.getElementsByClassName("hover-date-container").innerHTML+= '<br>Encounter '+pspencnum;
if(menuenclblexists=='no') {
// prepend Encounter label
$('#soho-psp-tree-trajectory a, #stereo_a-psp-tree-trajectory a').after('<br><br><ins class="jstree-icon" style="background:none;">&nbsp;</ins><span class="menuenclabel" style="font-family: \'Courier New\',Courier,monospace;">Encounter: </span>');
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('<br><br><ins class="jstree-icon" style="background:none;">&nbsp;</ins><span class="menuenclabel" style="font-family: \'Courier New\',Courier,monospace;">Encounter: </span>');
menuenclblexists='yes';
if(pspencnum == pspenctotal) {
encdash2='';
}
else {
encdash2=' - ';
}

// show current encounter in the pagination (SOHO)
$('#soho-psp-tree-trajectory .decoration').eq(1).html(encdash1+'<span style="border-radius:2px;background:white;color:black;font-weight:bold;">&nbsp;'+pspencnum+'&nbsp;</span>'+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+'<span style="border-radius:2px;background:white;color:black;font-weight:bold;">&nbsp;'+pspencnum+'&nbsp;</span>'+encdash2);

// show current encounter in the pagination (Stereo A)
$('#stereo_a-psp-tree-trajectory .decoration').eq(1).html(encdash1+'<span style="border-radius:2px;background:white;color:black;font-weight:bold;">&nbsp;'+pspencnum+'&nbsp;</span>'+encdash2);

// make the first and last .decoration <span> 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('<br><ins class="jstree-icon" style="background:none;">&nbsp;</ins>&#9664; '+encpagprev);
}
else if(pspencnum == 1) {
$('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('<br>&nbsp;&nbsp;');
}

// get next encounter
if(pspencnum != pspenctotal) {
encpagnxt=pspencnum+1;
$('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html(encpagnxt+' &#9654;');
}
else if(pspencnum == pspenctotal) {
$('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html('&nbsp;&nbsp;');
}
// show current encounter in the pagination (Stereo A)
$('#stereo_a-psp-tree-trajectory .decoration').eq(1).html(encdash1+'<span style="border-radius:2px;background:white;color:black;font-weight:bold;">&nbsp;'+pspencnum+'&nbsp;</span>'+encdash2);

// make the first and last .decoration <span> 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('<br><ins class="jstree-icon" style="background:none;">&nbsp;</ins>&#9664; '+encpagprev);
}
else if(pspencnum == 1) {
$('#soho-psp-tree-trajectory .button:first, #stereo_a-psp-tree-trajectory .button:first').html('<br>&nbsp;&nbsp;');
}

// get next encounter
if(pspencnum != pspenctotal) {
encpagnxt=pspencnum+1;
$('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html(encpagnxt+' &#9654;');
}
else if(pspencnum == pspenctotal) {
$('#soho-psp-tree-trajectory .button:last, #stereo_a-psp-tree-trajectory .button:last').html('&nbsp;&nbsp;');
}


$('#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);
Expand Down

0 comments on commit 2f32c37

Please sign in to comment.