Difference between revisions of "Widget:Ctarailtimes"

From Transit.Wiki
m
m
 
(11 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
     var wait<!--{$stopid}--> = setTimeout(function(){
 
     var wait<!--{$stopid}--> = setTimeout(function(){
 
     livetime<!--{$stopid}-->();
 
     livetime<!--{$stopid}-->();
     var refresh<!--{$stopid}--> = setInterval(livetime<!--{$stopid}-->,45000);
+
     var refresh<!--{$stopid}--> = setInterval(livetime<!--{$stopid}-->,60000);
 
},<!--{if isset($wait)}-->1000<!--{else}-->0<!--{/if}-->);
 
},<!--{if isset($wait)}-->1000<!--{else}-->0<!--{/if}-->);
 
});
 
});
  
var bigurl<!--{$stopid}--> = "/extensions/feedgen.php?service=ctarailtimes&command=%26stpid%<!--{$stopid}-->";
+
var bigurl<!--{$stopid}--> = "/extensions/feedgen.php?service=ctarailtimes&command=<!--{if isset($stationid)}-->%26mapid%3D<!--{else}-->%26stpid%3D<!--{/if}--><!--{$stopid}-->";
  
 
var parseData<!--{$stopid}--> = parseData;
 
var parseData<!--{$stopid}--> = parseData;
Line 30: Line 30:
  
 
function parseData(data) {
 
function parseData(data) {
 +
var data3 = data.ctatt.eta;
 
var lines1 = [];
 
var lines1 = [];
 
var alltimes = "<div style='display:table;width:100%;'>";
 
var alltimes = "<div style='display:table;width:100%;'>";
 
var times = [];
 
var times = [];
for (var g = 0; g < data.ctatt.eta.length; g++) {
+
if (typeof data3 !== "undefined") {
 +
for (var g = 0; g < data3.length; g++) {
 
   lines1.push(data3[g].rt);
 
   lines1.push(data3[g].rt);
 
}
 
}
Line 42: Line 44:
 
for (var h = 0; h < linesunique.length; h++) {
 
for (var h = 0; h < linesunique.length; h++) {
 
   times = data3.filter(obj => obj.rt == linesunique[h]);
 
   times = data3.filter(obj => obj.rt == linesunique[h]);
   alltimes += "<div style='font-weight: bold;'>" + linesunique[h] + "</div> ";
+
let newlinename = linesunique[h]
 +
  .replace("G","Green Line")
 +
  .replace("Org","Orange Line")
 +
  .replace("Pink","Pink Line")
 +
  .replace("P","Purple Line")
 +
  .replace("Red","Red Line")
 +
  .replace("Y","Yellow Line")
 +
  .replace("Brn","Brown Line")
 +
  .replace("Blue","Blue Line");
 +
   alltimes += "<div style='font-weight: bold;'>" + newlinename + "</div> ";
 
   var destin = [];
 
   var destin = [];
  
Line 60: Line 71:
 
     }
 
     }
 
     for (var k = 0; k < kt; k++) {
 
     for (var k = 0; k < kt; k++) {
 
      if (times2[k].predictedDepartureTime == 0) {
 
 
       date1 = new Date(times2[k].arrT);
 
       date1 = new Date(times2[k].arrT);
      }
 
 
       date2 = new Date(data.ctatt.tmst);
 
       date2 = new Date(data.ctatt.tmst);
 
       Difference_In_Time = date1.getTime() - date2.getTime();
 
       Difference_In_Time = date1.getTime() - date2.getTime();
Line 83: Line 91:
 
alltimes = alltimes.slice(0, -5);
 
alltimes = alltimes.slice(0, -5);
 
$("#output<!--{$stopid}-->").append(alltimes);
 
$("#output<!--{$stopid}-->").append(alltimes);
 
+
}
if (data3 == "") {
+
else {
 
$("#output<!--{$stopid}-->").append("<p>No predictions available.</p>");
 
$("#output<!--{$stopid}-->").append("<p>No predictions available.</p>");
 
}
 
}

Latest revision as of 02:20, 18 May 2024