From acbb5da886e5854dcc57f1264e818bd822b71f7c Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Thu, 7 Mar 2024 21:42:39 -0500 Subject: [PATCH] Improving frequency display. --- htdocs/lib/MessagePanel.js | 6 +++--- htdocs/lib/Utils.js | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js index d87c4ca1..0a54a4aa 100644 --- a/htdocs/lib/MessagePanel.js +++ b/htdocs/lib/MessagePanel.js @@ -586,10 +586,10 @@ DscMessagePanel.prototype.pushMessage = function(msg) { var message = ( (msg.distress? ' ' + msg.distress : '') + (msg.id? ' SHIP ' + Utils.linkifyVessel(msg.id) : '') - + (msg.loc? ' @' + msg.loc : '') + + (msg.loc? ' AT ' + msg.loc : '') + (msg.num? ' DIAL ' + msg.num : '') - + (msg.rxfreq? ' RX ' + msg.rxfreq : '') - + (msg.txfreq? ' TX ' + msg.txfreq : '') + + (msg.rxfreq? ' RX ' + Utils.printFreq(msg.rxfreq) : '') + + (msg.txfreq? ' TX ' + Utils.printFreq(msg.txfreq) : '') + symbols ).trim(); diff --git a/htdocs/lib/Utils.js b/htdocs/lib/Utils.js index 5ac71212..7ea6218c 100644 --- a/htdocs/lib/Utils.js +++ b/htdocs/lib/Utils.js @@ -29,11 +29,24 @@ Utils.setIcaoUrl = function(url) { this.icao_url = url; }; -// Escape HTML code. +// Escape HTML code Utils.htmlEscape = function(input) { return $('
').text(input).html() }; +// Print frequency (in Hz) in a nice way +Utils.printFreq = function(freq) { + if (isNaN(parseInt(freq))) { + return freq; + } else if (freq >= 30000000) { + return '' + (freq / 1000000.0) + 'MHz'; + } else if (freq >= 10000) { + return '' + (freq / 1000.0) + 'kHz'; + } else { + return '' + freq + 'Hz'; + } +} + // Change frequency as required by given modulation Utils.offsetFreq = function(freq, mod) { switch(mod) { @@ -98,17 +111,8 @@ Utils.linkifyIcao = function(icao, content = null) { // Create link to tune OWRX to the given frequency and modulation. Utils.linkifyFreq = function(freq, mod) { - var text; - if (freq >= 30000000) { - text = '' + (freq / 1000000.0) + 'MHz'; - } else if (freq >= 10000) { - text = '' + (freq / 1000.0) + 'kHz'; - } else { - text = '' + freq + 'Hz'; - } - return '' + text + ''; + + freq + ',mod=' + mod + '">' + Utils.printFreq(freq) + ''; }; // Linkify given content so that clicking them opens the map with