From 3870e560ec8f467734f0e063b0bd5347449701f1 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Mon, 6 Apr 2026 19:11:47 +0100 Subject: [PATCH] Bring localstorage stuff in from jsutils, it's only used here --- templates/about.html | 2 +- templates/add_spot.html | 4 ++-- templates/alerts.html | 4 ++-- templates/bands.html | 6 +++--- templates/base.html | 7 +++---- templates/conditions.html | 4 ++-- templates/map.html | 6 +++--- templates/spots.html | 6 +++--- templates/status.html | 4 ++-- webassets/js/common.js | 33 +++++++++++++++++++++++++++++++++ 10 files changed, 54 insertions(+), 22 deletions(-) diff --git a/templates/about.html b/templates/about.html index 39eca55..ffcf7c4 100644 --- a/templates/about.html +++ b/templates/about.html @@ -67,7 +67,7 @@

This software is dedicated to the memory of Tom G1PJB, SK, a friend and colleague who sadly passed away around the time I started writing it in Autumn 2025. I was looking forward to showing it to you when it was done.

- + {% end %} \ No newline at end of file diff --git a/templates/add_spot.html b/templates/add_spot.html index 7f1410f..7dc30ca 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -69,8 +69,8 @@ - - + + {% end %} \ No newline at end of file diff --git a/templates/alerts.html b/templates/alerts.html index fb9dc9e..292b693 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -56,8 +56,8 @@ - - + + {% end %} \ No newline at end of file diff --git a/templates/bands.html b/templates/bands.html index e824300..20b08aa 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -62,9 +62,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index d60a710..e668de4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -46,10 +46,9 @@ crossorigin="anonymous"> - - - - + + + diff --git a/templates/conditions.html b/templates/conditions.html index 78687f7..73a50d2 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -230,8 +230,8 @@ - - + + diff --git a/templates/map.html b/templates/map.html index d4146a2..13a1db9 100644 --- a/templates/map.html +++ b/templates/map.html @@ -79,9 +79,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/spots.html b/templates/spots.html index 2437e85..2529307 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -87,9 +87,9 @@ - - - + + + {% end %} \ No newline at end of file diff --git a/templates/status.html b/templates/status.html index 142449c..655dd7c 100644 --- a/templates/status.html +++ b/templates/status.html @@ -59,8 +59,8 @@ - - + + diff --git a/webassets/js/common.js b/webassets/js/common.js index dafe0b9..861e444 100644 --- a/webassets/js/common.js +++ b/webassets/js/common.js @@ -2,6 +2,39 @@ var options = {}; // Last time we updated the spots/alerts list on display. var lastUpdateTime; +// Normally load user settings from local storage, unless embedded mode is in use +let useLocalStorage = true; + +// Save settings to local storage. Suppressed if "use local storage" is false. +function saveSettings() { + if (useLocalStorage) { + // Find all storeable UI elements, store a key of "element id:property name" mapped to the value of that + // property. For a checkbox, that's the "checked" property. + $(".storeable-checkbox").each(function() { + localStorage.setItem("#" + $(this)[0].id + ":checked", JSON.stringify($(this)[0].checked)); + }); + $(".storeable-select").each(function() { + localStorage.setItem("#" + $(this)[0].id + ":value", JSON.stringify($(this)[0].value)); + }); + $(".storeable-text").each(function() { + localStorage.setItem("#" + $(this)[0].id + ":value", JSON.stringify($(this)[0].value)); + }); + } +} + +// Load settings from local storage and set up the filter selectors. Suppressed if "use local storage" is false. +function loadSettings() { + if (useLocalStorage) { + // Find all local storage entries and push their data to the corresponding UI element + Object.keys(localStorage).forEach(function(key) { + if (key.startsWith("#") && key.includes(":")) { + // Split the key back into an element ID and a property + var split = key.split(":"); + $(split[0]).prop(split[1], JSON.parse(localStorage.getItem(key))); + } + }); + } +} // Load and apply any URL params. This is used for "embedded mode" where another site can embed a version of // Spothole and provide its own interface options rather than using the user's saved ones. These may select things