Tweaks to title mangling:

* use PageName, not literal "DUMP1090"
 * use document.title directly, not a selector
 * include number of positionless aircraft too
 * rename the config options
 * some simplification of the changes
This commit is contained in:
Oliver Jowett 2015-02-22 11:51:58 +00:00
parent 288a8242dd
commit 268599a211
2 changed files with 35 additions and 28 deletions

View file

@ -7,8 +7,8 @@
// -- Title Settings --------------------------------------
// Show number of aircraft and/or messages per second in the page title
NumPlanesInTitle = true;
NumMessagesInTitle = true;
PlaneCountInTitle = true;
MessageRateInTitle = false;
// -- Output Settings -------------------------------------
// Show metric values

View file

@ -1,3 +1,4 @@
// -*- mode: javascript; indent-tabs-mode: nil; c-basic-offset: 8 -*-
"use strict";
// Define our global variables
@ -34,7 +35,7 @@ var StaleReceiverCount = 0;
var FetchPending = null;
var MessageCountHistory = [];
var MessagesPerSecond = 0;
var MessageRate = 0;
var NBSP='\u00a0';
@ -140,7 +141,7 @@ function fetchData() {
var PositionHistorySize = 0;
function initialize() {
// Set page basics
$("head title").text(PageName); // page title
document.title = PageName;
$("#infoblock_name").text(PageName);
PlaneRowTemplate = document.getElementById("plane_row_template");
@ -488,22 +489,37 @@ function reaper() {
// Page Title update function
function refreshPageTitle() {
if(NumPlanesInTitle && !NumMessagesInTitle){
$("head title").text("DUMP1090 - " + TrackedAircraftPositions);
}
else if(!NumPlanesInTitle && NumMessagesInTitle){
$("head title").text("DUMP1090 - " + MessagesPerSecond.toFixed(1));
}
else if(NumPlanesInTitle && NumMessagesInTitle){
$("head title").text("DUMP1090 - " + TrackedAircraftPositions + " | " + MessagesPerSecond.toFixed(1));
}
if (!PlaneCountInTitle && !MessageRateInTitle)
return;
var subtitle = "";
if (PlaneCountInTitle) {
subtitle += TrackedAircraftPositions + '/' + TrackedAircraft;
}
if (MessageRateInTitle) {
if (subtitle) subtitle += ' | ';
subtitle += MessageRate.toFixed(1) + '/s';
}
document.title = PageName + ' - ' + subtitle;
}
// Refresh the detail window about the plane
function refreshSelected() {
if (MessageCountHistory.length > 1) {
var message_time_delta = MessageCountHistory[MessageCountHistory.length-1].time - MessageCountHistory[0].time;
var message_count_delta = MessageCountHistory[MessageCountHistory.length-1].messages - MessageCountHistory[0].messages;
if (message_time_delta > 0)
MessageRate = message_count_delta / message_time_delta;
} else {
MessageRate = null;
}
refreshPageTitle();
var selected = false;
var selected = false;
if (typeof SelectedPlane !== 'undefined' && SelectedPlane != "ICAO" && SelectedPlane != null) {
selected = Planes[SelectedPlane];
}
@ -516,21 +532,12 @@ function refreshSelected() {
$('#dump1090_total_ac_positions').text(TrackedAircraftPositions);
$('#dump1090_total_history').text(TrackedHistorySize);
var message_rate = null;
if (MessageCountHistory.length > 1) {
var message_time_delta = MessageCountHistory[MessageCountHistory.length-1].time - MessageCountHistory[0].time;
var message_count_delta = MessageCountHistory[MessageCountHistory.length-1].messages - MessageCountHistory[0].messages;
if (message_time_delta > 0)
message_rate = message_count_delta / message_time_delta;
}
if (message_rate !== null){
MessagesPerSecond = message_rate;
$('#dump1090_message_rate').text(message_rate.toFixed(1));
}
else
if (MessageRate !== null) {
$('#dump1090_message_rate').text(MessageRate.toFixed(1));
} else {
$('#dump1090_message_rate').text("n/a");
}
return;
}