chore: add JS/ESLint toolchain, refactor onclick to event delegation
- Add ESLint config for web/ui (flat config, golangci-lint-compatible) - Add js-lint task to mise.toml (npm run lint in web/ui) - Add ESLint check to check-toolchain.sh - Add .golangci.yml for golangci-lint v2 with correct exclusions - Refactor app.js: replace inline onclick with data-action + event delegation - Add null checks and HTTP status checks to browseWavs - Add web/ui/node_modules/ to .gitignore
This commit is contained in:
+17
-3
@@ -46,8 +46,8 @@ function renderResults(items) {
|
||||
<span>${r.downloads.toLocaleString()} downloads</span>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn-dl" onclick="downloadItem('${esc(r.identifier)}')">Download ISOs</button>
|
||||
<button class="btn-list" onclick="listItem('${esc(r.identifier)}')">List Files</button>
|
||||
<button class="btn-dl" data-action="download" data-identifier="${esc(r.identifier)}">Download ISOs</button>
|
||||
<button class="btn-list" data-action="list" data-identifier="${esc(r.identifier)}">List Files</button>
|
||||
</div>
|
||||
<div id="list-${sanitize(r.identifier)}" class="file-list"></div>
|
||||
</div>
|
||||
@@ -218,7 +218,7 @@ async function browseWavs() {
|
||||
list.innerHTML = data.map(f => `
|
||||
<div class="wav-item" data-file="${esc(f)}">
|
||||
<span class="wav-name" title="${esc(f)}">${esc(f)}</span>
|
||||
<button class="wav-play-btn" onclick="playWav('${esc(f)}')">Play</button>
|
||||
<button class="wav-play-btn" data-action="play" data-wav="${esc(f)}">Play</button>
|
||||
</div>
|
||||
`).join('');
|
||||
} catch (e) {
|
||||
@@ -332,3 +332,17 @@ function formatBytes(bytes) {
|
||||
|
||||
// Initial load
|
||||
doSearch();
|
||||
|
||||
// Event delegation for dynamically generated buttons
|
||||
document.addEventListener('click', function(e) {
|
||||
const btn = e.target.closest('[data-action]');
|
||||
if (!btn) return;
|
||||
const action = btn.dataset.action;
|
||||
if (action === 'download') {
|
||||
downloadItem(btn.dataset.identifier);
|
||||
} else if (action === 'list') {
|
||||
listItem(btn.dataset.identifier);
|
||||
} else if (action === 'play') {
|
||||
playWav(btn.dataset.wav);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user