docs: add JSDoc comments to javascript functions
Alan Pearce alan@alanpearce.eu
Sat, 22 Mar 2025 18:04:43 +0100
1 files changed, 31 insertions(+), 0 deletions(-)
jump to
M frontend/static/search.js → frontend/static/search.js
@@ -28,6 +28,10 @@ createHTML: (string) => string, }); } +/** + * + * @param {MouseEvent} ev + */ function openSiblingDialog(ev) { const dialog = ev.target.nextElementSibling; dialog.showModal(); @@ -36,6 +40,10 @@ dialog.close(); }); } +/** + * + * @param {HTMLElement} results + */ function addOpenDialogListeners(results) { results.querySelectorAll("a.open-dialog").forEach(function (element) { element.addEventListener("click", handleDialogOpen); @@ -45,12 +53,20 @@ element.addEventListener("click", openSiblingDialog); }); } +/** + * + * @param {MouseEvent} ev + */ function paginationLinkClicked(ev) { const url = new URL(ev.target.href); getResults(url); ev.preventDefault(); } +/** + * + * @param {HTMLElement} pagination + */ function addPaginationEventListeners(pagination) { Array.from(pagination.children).forEach((child) => child.addEventListener("click", paginationLinkClicked), @@ -70,6 +86,10 @@ addPaginationEventListeners(pagination); } } +/** + * + * @param {URL} url + */ async function getResults(url) { try { state.url = url.toJSON(); @@ -141,6 +161,10 @@ }); queryInput.value = ""; }); +/** + * + * @param {string} html + */ function renderDetails(html) { const fragment = detailsRange.createContextualFragment( escapePolicy !== null ? escapePolicy.createHTML(html) : html, @@ -157,6 +181,10 @@ dialog.querySelector("button").addEventListener("click", function () { dialog.close(); }); +/** + * + * @param {URL} url + */ async function getDetail(url) { try { state.url = url.toJSON(); @@ -178,6 +206,9 @@ renderDetails(new Text(error.message)); } } +/** + * @param {MouseEvent} ev + */ function handleDialogOpen(ev) { getDetail(new URL(ev.target.href)); ev.preventDefault();