From c5b5241d7f4f3f337fb61ef84f257b488f7d8eff Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Thu, 25 Apr 2024 19:02:18 -0400 Subject: [PATCH] Moved UI and utility functions outside openwebrx.js. --- htdocs/index.html | 2 +- htdocs/lib/MessagePanel.js | 4 ++-- htdocs/lib/UI.js | 19 +++++++++++++++ htdocs/lib/Utils.js | 24 +++++++++++++++++++ htdocs/openwebrx.js | 48 -------------------------------------- 5 files changed, 46 insertions(+), 51 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index c8eb32bc..075818ee 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -329,7 +329,7 @@
-
REC
+
REC
diff --git a/htdocs/lib/MessagePanel.js b/htdocs/lib/MessagePanel.js index 8aa6411f..980eb8ae 100644 --- a/htdocs/lib/MessagePanel.js +++ b/htdocs/lib/MessagePanel.js @@ -740,7 +740,7 @@ SstvMessagePanel.prototype.pushMessage = function(msg) { var f = msg.frequency>0? ' at ' + Math.floor(msg.frequency/1000) + 'kHz' : ''; var h = '
' + msg.timestamp + ' ' + msg.width + 'x' + msg.height + ' ' + msg.sstvMode + f + '
'; - var c = '
' + + var c = '
' + '
'; @@ -809,7 +809,7 @@ FaxMessagePanel.prototype.pushMessage = function(msg) { var f = msg.frequency>0? ' at ' + Math.floor(msg.frequency/1000) + 'kHz' : ''; var h = '
' + msg.timestamp + ' ' + msg.width + 'x' + msg.height + ' ' + msg.faxMode + f + '
'; - var c = '
' + + var c = '
' + '
'; diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index 6228fbad..15c903cc 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -139,6 +139,25 @@ UI.updateNR = function() { })); } +// +// Audio Recording Controls +// + +UI.toggleRecording = function(on) { + // If no argument given, toggle audio recording + var toggle = typeof(on) === 'undefined'; + + var $recButton = $('.openwebrx-record-button'); + + if (audioEngine.recording && (toggle || !on)) { + audioEngine.stopRecording(); + $recButton.css('animation-name', ''); + } else if (toggle || on) { + audioEngine.startRecording(); + $recButton.css('animation-name', 'openwebrx-record-animation'); + } +}; + // // Look & Feel Controls // diff --git a/htdocs/lib/Utils.js b/htdocs/lib/Utils.js index e565ac68..af6056a2 100644 --- a/htdocs/lib/Utils.js +++ b/htdocs/lib/Utils.js @@ -233,6 +233,30 @@ Utils.mmsiIsGround = function(mmsi) { return mmsi.substring(0, 2) === '00'; }; +// Save given canvas into a PNG file. +Utils.saveCanvas = function(canvas) { + // Get canvas by its ID + var c = document.getElementById(canvas); + if (c == null) return; + + // Convert canvas to a data blob + c.toBlob(function(blob) { + // Create and click a link to the canvas data URL + var a = document.createElement('a'); + a.href = window.URL.createObjectURL(blob); + a.style = 'display: none'; + a.download = canvas + ".png"; + document.body.appendChild(a); + a.click(); + + // Get rid of the canvas data URL + setTimeout(function() { + document.body.removeChild(a); + window.URL.revokeObjectURL(a.href); + }, 0); + }, 'image/png'); +}; + // // Local Storage Access // diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 47574c66..ea521b13 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -35,54 +35,6 @@ var secondary_fft_size; var tuning_step_default = 1; var tuning_step = 1; -function toggleSection(el) { - var next_el = el.nextElementSibling; - if (next_el) { - if (next_el.style.display === "none") { - el.innerHTML = el.innerHTML.replace("\u25B4", "\u25BE"); - next_el.style.display = "block"; - } else { - el.innerHTML = el.innerHTML.replace("\u25BE", "\u25B4"); - next_el.style.display = "none"; - } - } -} - -function toggleRecording() { - var $recButton = $('.openwebrx-record-button'); - - if (audioEngine.recording) { - audioEngine.stopRecording(); - $recButton.css('animation-name', ''); - } else { - audioEngine.startRecording(); - $recButton.css('animation-name', 'openwebrx-record-animation'); - } -} - -function saveCanvas(canvas) { - // Get canvas by its ID - var c = document.getElementById(canvas); - if (c == null) return; - - // Convert canvas to a data blob - c.toBlob(function(blob) { - // Create and click a link to the canvas data URL - var a = document.createElement('a'); - a.href = window.URL.createObjectURL(blob); - a.style = 'display: none'; - a.download = canvas + ".png"; - document.body.appendChild(a); - a.click(); - - // Get rid of the canvas data URL - setTimeout(function() { - document.body.removeChild(a); - window.URL.revokeObjectURL(a.href); - }, 0); - }, 'image/png'); -} - function zoomInOneStep() { zoom_set(zoom_level + 1); }