| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
(function () { |
| 16 |
var pending = null; |
| 17 |
document.body.addEventListener('htmx:before:request', function () { |
| 18 |
var el = document.activeElement; |
| 19 |
pending = el && el.id && el.closest('#discover-sidebar') ? el.id : null; |
| 20 |
}); |
| 21 |
document.body.addEventListener('htmx:after:settle', function () { |
| 22 |
if (!pending) return; |
| 23 |
var el = document.getElementById(pending); |
| 24 |
|
| 25 |
|
| 26 |
if (!el || el === document.activeElement) return; |
| 27 |
el.focus({ preventScroll: true }); |
| 28 |
pending = null; |
| 29 |
}); |
| 30 |
})(); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
(function() { |
| 35 |
function applyView(view) { |
| 36 |
var container = document.getElementById('results-container-inner'); |
| 37 |
if (container) { |
| 38 |
container.className = 'results-container results-' + view; |
| 39 |
} |
| 40 |
document.querySelectorAll('.view-btn').forEach(function(btn) { |
| 41 |
btn.classList.toggle('is-selected', btn.dataset.view === view); |
| 42 |
}); |
| 43 |
|
| 44 |
var header = document.querySelector('.table-header'); |
| 45 |
if (header) { |
| 46 |
header.classList.toggle('is-hidden', view !== 'list'); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
document.addEventListener('DOMContentLoaded', function() { |
| 52 |
var saved = safeStorageGet('discoverViewPref') || 'grid'; |
| 53 |
applyView(saved); |
| 54 |
}); |
| 55 |
|
| 56 |
|
| 57 |
document.querySelectorAll('.view-btn').forEach(function(btn) { |
| 58 |
btn.addEventListener('click', function() { |
| 59 |
var view = btn.dataset.view; |
| 60 |
applyView(view); |
| 61 |
safeStorageSet('discoverViewPref', view); |
| 62 |
}); |
| 63 |
}); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
document.body.addEventListener('htmx:after:settle', function(evt) { |
| 79 |
var el = evt.target; |
| 80 |
if (!el || !el.querySelector) return; |
| 81 |
var arrived = el.id === 'results-container' |
| 82 |
|| el.id === 'results-container-inner' |
| 83 |
|| el.querySelector('#results-container-inner'); |
| 84 |
if (arrived) { |
| 85 |
var saved = safeStorageGet('discoverViewPref') || 'grid'; |
| 86 |
applyView(saved); |
| 87 |
} |
| 88 |
}); |
| 89 |
})(); |
| 90 |
|