+
+
+
+
+
+
+ 5
+ meters
+
+
+
@@ -1032,6 +1158,9 @@
Settings Saved ✓
+
@@ -2051,8 +2180,39 @@
}
}
+ // Debounce function for saving
+ function debounce(func, wait) {
+ let timeout;
+ return function executedFunction(...args) {
+ const later = () => {
+ clearTimeout(timeout);
+ func(...args);
+ };
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+ };
+ }
+
+ // Show save indicator
+ function showSaveIndicator(message = 'Settings Saved ✓') {
+ const indicator = document.getElementById('adminSaveIndicator');
+ if (indicator) {
+ indicator.textContent = message;
+ indicator.classList.add('show');
+ setTimeout(() => {
+ indicator.classList.remove('show');
+ }, 2000);
+ }
+ }
+
+ // Debounced save function
+ const debouncedSave = debounce(() => {
+ saveAdminSettings();
+ showSaveIndicator();
+ }, 500);
+
function setupAdminInputListeners() {
- // Add change listeners to all admin inputs
+ // Add change and input listeners to all admin inputs
const adminInputs = [
{ id: 'geocacheRange', setting: 'geocacheRange', type: 'number' },
{ id: 'geocacheAlertRange', setting: 'geocacheAlertRange', type: 'number' },
@@ -2065,10 +2225,30 @@
{ id: 'proximityCheckInterval', setting: 'proximityCheckInterval', type: 'number' }
];
+ // Setup range sliders if they exist
+ const sliderPairs = [
+ { slider: 'geocacheRangeSlider', input: 'geocacheRange', value: 'geocacheRangeValue' }
+ ];
+
+ sliderPairs.forEach(pair => {
+ const slider = document.getElementById(pair.slider);
+ const input = document.getElementById(pair.input);
+ const valueDisplay = document.getElementById(pair.value);
+
+ if (slider && input && valueDisplay) {
+ slider.addEventListener('input', function() {
+ input.value = this.value;
+ valueDisplay.textContent = this.value;
+ input.dispatchEvent(new Event('input'));
+ });
+ }
+ });
+
adminInputs.forEach(input => {
const element = document.getElementById(input.id);
if (element) {
- element.addEventListener('change', function() {
+ // Use both input and change events for better responsiveness
+ const updateHandler = function() {
let value;
if (input.type === 'checkbox') {
value = this.checked;
@@ -2078,9 +2258,41 @@
value = this.value;
}
adminSettings[input.setting] = value;
- saveAdminSettings();
- updateStatus(`${input.setting} updated to ${value}`);
+ debouncedSave();
+ };
+
+ if (input.type === 'checkbox') {
+ element.addEventListener('change', updateHandler);
+ } else {
+ element.addEventListener('input', updateHandler);
+ element.addEventListener('change', updateHandler);
+ }
+ }
+ });
+
+ // Setup collapsible sections
+ document.querySelectorAll('.section.collapsible').forEach(section => {
+ const title = section.querySelector('.section-title');
+ if (title) {
+ title.addEventListener('click', () => {
+ section.classList.toggle('collapsed');
+ // Save collapsed state
+ const sectionName = section.dataset.section;
+ if (sectionName) {
+ const collapsedSections = JSON.parse(localStorage.getItem('collapsedSections') || '{}');
+ collapsedSections[sectionName] = section.classList.contains('collapsed');
+ localStorage.setItem('collapsedSections', JSON.stringify(collapsedSections));
+ }
});
+
+ // Restore collapsed state
+ const sectionName = section.dataset.section;
+ if (sectionName) {
+ const collapsedSections = JSON.parse(localStorage.getItem('collapsedSections') || '{}');
+ if (collapsedSections[sectionName]) {
+ section.classList.add('collapsed');
+ }
+ }
}
});
}