From b15ab4adb837e43409e5e3cf3a40a83ef4dbf62f Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sun, 8 Jan 2023 22:12:24 -0300 Subject: Initial commit --- themes/hugo-whisper-theme/assets/js/scripts.js | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 themes/hugo-whisper-theme/assets/js/scripts.js (limited to 'themes/hugo-whisper-theme/assets/js/scripts.js') diff --git a/themes/hugo-whisper-theme/assets/js/scripts.js b/themes/hugo-whisper-theme/assets/js/scripts.js new file mode 100644 index 0000000..0c697d0 --- /dev/null +++ b/themes/hugo-whisper-theme/assets/js/scripts.js @@ -0,0 +1,35 @@ +var body = document.querySelector('body') +var menuTrigger = document.querySelector('#toggle-main-menu-mobile'); +var menuContainer = document.querySelector('#main-menu-mobile'); + +menuTrigger.onclick = function() { + menuContainer.classList.toggle('open'); + menuTrigger.classList.toggle('is-active') + body.classList.toggle('lock-scroll') +} + +var content = document.querySelector('.content.anchor-link-enabled') +if (content) { + addHeaderAnchors(content); +} + +function addHeaderAnchors(content) { + var headers = content.querySelectorAll('h1, h2, h3, h4'); + // SVG data from https://iconmonstr.com/link-1-svg/ + var linkSvg = ' '; + var anchorForId = function (id) { + var anchor = document.createElement('a'); + anchor.classList.add('header-anchor'); + anchor.href = "#" + id; + anchor.innerHTML = linkSvg; + return anchor; + }; + + for (var h = 0; h < headers.length; h++) { + var header = headers[h]; + + if (typeof header.id !== "undefined" && header.id !== "") { + header.appendChild(anchorForId(header.id)); + } + } +} -- cgit v1.2.3