diff --git a/assets/js/clipboard.js b/assets/js/clipboard.js index cd928c1..10e02c6 100644 --- a/assets/js/clipboard.js +++ b/assets/js/clipboard.js @@ -8,33 +8,38 @@ const addCopyButtons = () => { let els = document.getElementsByClassName("highlight"); // for each highlight for (let i = 0; i < els.length; i++) { - if (els[i].getElementsByClassName("clipboard-button").length) continue; + try { + if (els[i].getElementsByClassName("clipboard-button").length) continue; - // find pre > code inside els[i] - let codeBlocks = els[i].getElementsByTagName("code"); + // find pre > code inside els[i] + let codeBlocks = els[i].getElementsByTagName("code"); - // line numbers are inside first code block - let lastCodeBlock = codeBlocks[codeBlocks.length - 1]; - const button = document.createElement("button"); - button.className = "clipboard-button"; - button.type = "button"; - button.innerHTML = svgCopy; - // remove every second newline from lastCodeBlock.innerText - button.addEventListener("click", () => { - navigator.clipboard.writeText(lastCodeBlock.innerText.replace(/\n\n/g, "\n")).then( - () => { - button.blur(); - button.innerHTML = svgCheck; - setTimeout(() => { - button.innerHTML = svgCopy - button.style.borderColor = "" - }, 2000); - }, - (error) => (button.innerHTML = "Error") - ); - }); - // find chroma inside els[i] - let chroma = els[i].getElementsByClassName("chroma")[0]; - els[i].insertBefore(button, chroma); + // line numbers are inside first code block + let lastCodeBlock = codeBlocks[codeBlocks.length - 1]; + const button = document.createElement("button"); + button.className = "clipboard-button"; + button.type = "button"; + button.innerHTML = svgCopy; + button.ariaLabel = "opy the shown code"; + // remove every second newline from lastCodeBlock.innerText + button.addEventListener("click", () => { + navigator.clipboard.writeText(lastCodeBlock.innerText.replace(/\n\n/g, "\n")).then( + () => { + button.blur(); + button.innerHTML = svgCheck; + setTimeout(() => { + button.innerHTML = svgCopy + button.style.borderColor = "" + }, 2000); + }, + (error) => (button.innerHTML = "Error") + ); + }); + // find chroma inside els[i] + let chroma = els[i].getElementsByClassName("chroma")[0]; + els[i].insertBefore(button, chroma); + } catch(error) { + console.debug(error); + } } } diff --git a/assets/js/code-title.js b/assets/js/code-title.js index 698edc9..325e16d 100644 --- a/assets/js/code-title.js +++ b/assets/js/code-title.js @@ -1,13 +1,17 @@ function addTitleToCodeBlocks() { - var els = document.getElementsByClassName("highlight"); - for (var i = 0; i < els.length; i++) { - if (els[i].title.length) { - let div = document.createElement("div"); - if (els[i].getElementsByClassName("code-title").length) continue; - div.textContent=els[i].title; - div.classList.add("code-title") - els[i].insertBefore(div, els[i].firstChild); + const els = document.getElementsByClassName("highlight"); + for (let i = 0; i < els.length; i++) { + try { + if (els[i].title.length) { + let div = document.createElement("div"); + if (els[i].getElementsByClassName("code-title").length) continue; + div.textContent = els[i].title; + div.classList.add("code-title") + els[i].insertBefore(div, els[i].firstChild); + } + } catch (error) { + console.debug(error); } } -}; +} diff --git a/assets/js/full-text-search.js b/assets/js/full-text-search.js index 108db10..709a3b3 100644 --- a/assets/js/full-text-search.js +++ b/assets/js/full-text-search.js @@ -35,7 +35,7 @@ }) registerHandlers((e) => { - term = e.target.value + const term = e.target.value const searchResults = contentIndex.search(term, [ { field: "content", diff --git a/assets/js/graph.js b/assets/js/graph.js index c89877b..2e05b5c 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -113,7 +113,7 @@ async function drawGraph(baseUrl, isHome, pathColors, graphConfig) { .append("svg") .attr("width", width) .attr("height", height) - .attr('viewBox', [-width / 2 * 1 / scale, -height / 2 * 1 / scale, width * 1 / scale, height * 1 / scale]) + .attr('viewBox', [-width / 2 / scale, -height / 2 / scale, width / scale, height / scale]) if (enableLegend) { const legend = [{ Current: "var(--g-node-active)" }, { Note: "var(--g-node)" }, ...pathColors] diff --git a/assets/js/popover.js b/assets/js/popover.js index ca13f9a..554291a 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -12,7 +12,7 @@ function initPopover(baseURL, useContextualBacklinks) { links .filter(li => li.dataset.src || (li.dataset.idx && useContextualBacklinks)) .forEach(li => { - var el + let el if (li.dataset.ctx) { const linkDest = content[li.dataset.src] const popoverElement = `