|
| 1 | +{{- if not (.Param "hideFooter") }} |
| 2 | +<footer class="footer"> |
| 3 | + {{- if site.Copyright }} |
| 4 | + <span>{{ site.Copyright | markdownify }}</span> |
| 5 | + {{- else }} |
| 6 | + <span>© {{ now.Year }} <a href="{{ "" | absLangURL }}">{{ site.Title }}</a></span> |
| 7 | + {{- end }} |
| 8 | +</footer> |
| 9 | +{{- end }} |
| 10 | + |
| 11 | +{{- if (not site.Params.disableScrollToTop) }} |
| 12 | +<a href="#top" aria-label="go to top" title="Go to Top (Alt + G)" class="top-link" id="top-link" accesskey="g"> |
| 13 | + <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentColor"> |
| 14 | + <path d="M12 6H0l6-6z" /> |
| 15 | + </svg> |
| 16 | +</a> |
| 17 | +{{- end }} |
| 18 | + |
| 19 | +{{- partial "extend_footer.html" . }} |
| 20 | + |
| 21 | +<script> |
| 22 | + let menu = document.getElementById('menu') |
| 23 | + if (menu) { |
| 24 | + menu.scrollLeft = localStorage.getItem("menu-scroll-position"); |
| 25 | + menu.onscroll = function () { |
| 26 | + localStorage.setItem("menu-scroll-position", menu.scrollLeft); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + document.querySelectorAll('a[href^="#"]').forEach(anchor => { |
| 31 | + anchor.addEventListener("click", function (e) { |
| 32 | + e.preventDefault(); |
| 33 | + var id = this.getAttribute("href").substr(1); |
| 34 | + if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) { |
| 35 | + document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ |
| 36 | + behavior: "smooth" |
| 37 | + }); |
| 38 | + } else { |
| 39 | + document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView(); |
| 40 | + } |
| 41 | + if (id === "top") { |
| 42 | + history.replaceState(null, null, " "); |
| 43 | + } else { |
| 44 | + history.pushState(null, null, `#${id}`); |
| 45 | + } |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | +</script> |
| 50 | + |
| 51 | +{{- if (not site.Params.disableScrollToTop) }} |
| 52 | +<script> |
| 53 | + var mybutton = document.getElementById("top-link"); |
| 54 | + window.onscroll = function () { |
| 55 | + if (document.body.scrollTop > 800 || document.documentElement.scrollTop > 800) { |
| 56 | + mybutton.style.visibility = "visible"; |
| 57 | + mybutton.style.opacity = "1"; |
| 58 | + } else { |
| 59 | + mybutton.style.visibility = "hidden"; |
| 60 | + mybutton.style.opacity = "0"; |
| 61 | + } |
| 62 | + }; |
| 63 | + |
| 64 | +</script> |
| 65 | +{{- end }} |
| 66 | + |
| 67 | +{{- if (not site.Params.disableThemeToggle) }} |
| 68 | +<script> |
| 69 | + document.getElementById("theme-toggle").addEventListener("click", () => { |
| 70 | + if (document.body.className.includes("dark")) { |
| 71 | + document.body.classList.remove('dark'); |
| 72 | + localStorage.setItem("pref-theme", 'light'); |
| 73 | + } else { |
| 74 | + document.body.classList.add('dark'); |
| 75 | + localStorage.setItem("pref-theme", 'dark'); |
| 76 | + } |
| 77 | + }) |
| 78 | + |
| 79 | +</script> |
| 80 | +{{- end }} |
| 81 | + |
| 82 | +{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (.Param "ShowCodeCopyButtons")) }} |
| 83 | +<script> |
| 84 | + document.querySelectorAll('pre > code').forEach((codeblock) => { |
| 85 | + const container = codeblock.parentNode.parentNode; |
| 86 | + |
| 87 | + const copybutton = document.createElement('button'); |
| 88 | + copybutton.classList.add('copy-code'); |
| 89 | + copybutton.innerHTML = '{{- i18n "code_copy" | default "copy" }}'; |
| 90 | + |
| 91 | + function copyingDone() { |
| 92 | + copybutton.innerHTML = '{{- i18n "code_copied" | default "copied!" }}'; |
| 93 | + setTimeout(() => { |
| 94 | + copybutton.innerHTML = '{{- i18n "code_copy" | default "copy" }}'; |
| 95 | + }, 2000); |
| 96 | + } |
| 97 | + |
| 98 | + copybutton.addEventListener('click', (cb) => { |
| 99 | + if ('clipboard' in navigator) { |
| 100 | + navigator.clipboard.writeText(codeblock.textContent); |
| 101 | + copyingDone(); |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + const range = document.createRange(); |
| 106 | + range.selectNodeContents(codeblock); |
| 107 | + const selection = window.getSelection(); |
| 108 | + selection.removeAllRanges(); |
| 109 | + selection.addRange(range); |
| 110 | + try { |
| 111 | + document.execCommand('copy'); |
| 112 | + copyingDone(); |
| 113 | + } catch (e) { }; |
| 114 | + selection.removeRange(range); |
| 115 | + }); |
| 116 | + |
| 117 | + if (container.classList.contains("highlight")) { |
| 118 | + container.appendChild(copybutton); |
| 119 | + } else if (container.parentNode.firstChild == container) { |
| 120 | + // td containing LineNos |
| 121 | + } else if (codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE") { |
| 122 | + // table containing LineNos and code |
| 123 | + codeblock.parentNode.parentNode.parentNode.parentNode.parentNode.appendChild(copybutton); |
| 124 | + } else { |
| 125 | + // code blocks not having highlight as parent class |
| 126 | + codeblock.parentNode.appendChild(copybutton); |
| 127 | + } |
| 128 | + }); |
| 129 | +</script> |
| 130 | +{{- end }} |
0 commit comments