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 -------------------------------------- // -- Title Settings --------------------------------------
// Show number of aircraft and/or messages per second in the page title // Show number of aircraft and/or messages per second in the page title
NumPlanesInTitle = true; PlaneCountInTitle = true;
NumMessagesInTitle = true; MessageRateInTitle = false;
// -- Output Settings ------------------------------------- // -- Output Settings -------------------------------------
// Show metric values // Show metric values

View file

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