mirror of
https://github.com/mcuadros/ascode
synced 2024-11-26 06:01:08 +01:00
8 lines
2.8 KiB
JavaScript
8 lines
2.8 KiB
JavaScript
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 anchorForId=function(id){var anchor=document.createElement("a");anchor.className="header-link";anchor.href="#"+id;anchor.innerHTML='<svg class="fill-current o-60 hover-accent-color-light" height="22px" viewBox="0 0 24 24" width="22px" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>';return anchor;};var linkifyAnchors=function(level,containingElement){var headers=containingElement.getElementsByTagName("h"+level);for(var h=0;h<headers.length;h++){var header=headers[h];if(typeof header.id!=="undefined"&&header.id!==""){console.log(header.id);header.appendChild(anchorForId(header.id));}}};document.onreadystatechange=function(){if(this.readyState==="complete"){var contentBlock=document.getElementsByClassName("content")[0]
|
|
if(!contentBlock){return;}
|
|
for(var level=3;level<=4;level++){linkifyAnchors(level,contentBlock);}}};var content=document.querySelector('.content.anchor-link-enabled')
|
|
if(content){addHeaderAnchors(content);}
|
|
function addHeaderAnchors(content){var headers=content.querySelectorAll('h1, h2, h3, h4');var linkSvg=' <svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"></path><path d="M6.188 8.719c.439-.439.926-.801 1.444-1.087 2.887-1.591 6.589-.745 8.445 2.069l-2.246 2.245c-.644-1.469-2.243-2.305-3.834-1.949-.599.134-1.168.433-1.633.898l-4.304 4.306c-1.307 1.307-1.307 3.433 0 4.74 1.307 1.307 3.433 1.307 4.74 0l1.327-1.327c1.207.479 2.501.67 3.779.575l-2.929 2.929c-2.511 2.511-6.582 2.511-9.093 0s-2.511-6.582 0-9.093l4.304-4.306zm6.836-6.836l-2.929 2.929c1.277-.096 2.572.096 3.779.574l1.326-1.326c1.307-1.307 3.433-1.307 4.74 0 1.307 1.307 1.307 3.433 0 4.74l-4.305 4.305c-1.311 1.311-3.44 1.3-4.74 0-.303-.303-.564-.68-.727-1.051l-2.246 2.245c.236.358.481.667.796.982.812.812 1.846 1.417 3.036 1.704 1.542.371 3.194.166 4.613-.617.518-.286 1.005-.648 1.444-1.087l4.304-4.305c2.512-2.511 2.512-6.582.001-9.093-2.511-2.51-6.581-2.51-9.092 0z"/></svg>';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));}}} |