Browse Source

Copy functionality for Bluetooth class field

master
Mobius K 3 years ago
parent
commit
7fef012370
  1. 2
      src/routes/index.pug
  2. 22
      src/scripts/bluetooth.js

2
src/routes/index.pug

@ -5,7 +5,7 @@ block content
h1
label(for="bluetoothClass", i18n="bluetoothClass")
input(type="text", disabled, id="bluetoothClass")
button(type="button", i18n="copy")
button(type="button", i18n="copy", onclick="copyBluetoothClassField()")
p Human readable class
hr

22
src/scripts/bluetooth.js

@ -1,18 +1,30 @@
let bluetoothClass = 0;
// Grab references to our DOM elements
const bluetoothClassField = document.getElementById("bluetoothClass");
const minorDeviceGroups = document.querySelectorAll("[class^='minor-devices'] > *");
const checkboxesAndRadios = document.querySelectorAll("input[type='checkbox'], input[type='radio']");
/**
* TODO: Document
* Write a hex string of our current Bluetooth class to the input
*/
function updateBluetoothClassField() {
let hex = bluetoothClass.toString(16);
hex = hex.toLocaleUpperCase();
hex = hex.padStart(6, "0");
hex = "0x" + hex;
document.getElementById("bluetoothClass").value = hex;
bluetoothClassField.value = hex;
}
/**
* Copy the current value of the Bluetooth class field to the clipboard
*/
function copyBluetoothClassField() {
navigator.clipboard.writeText(bluetoothClassField.value);
}
/**
* TODO: Document
* Depending on our selected major device category, hide or show groups of minor devices
*/
function updateBluetoothMinorDeviceFields() {
@ -22,7 +34,7 @@ function updateBluetoothMinorDeviceFields() {
const majorDeviceId = majorDeviceRadio.id.replace("majorDevice", "");
// Hide all minor device fields that don't match our major device id
document.querySelectorAll("[class^='minor-devices'] > *").forEach((element) => {
minorDeviceGroups.forEach((element) => {
element.classList.add("hidden");
if (element.classList.contains(majorDeviceId)) {
element.classList.remove("hidden");
@ -31,7 +43,7 @@ function updateBluetoothMinorDeviceFields() {
}
// Watch the page checkboxes and radio buttons for updating the Bluetooth class
document.querySelectorAll("input[type='checkbox'], input[type='radio']").forEach((element) => {
checkboxesAndRadios.forEach((element) => {
element.addEventListener("change", () => {
if (element.id.startsWith("majorService")) {

Loading…
Cancel
Save