1
1
mirror of https://github.com/primer/css.git synced 2024-12-01 20:53:06 +03:00
css/docs/js/anchor.min.js

2 lines
582 B
JavaScript

/*! AnchorJS - v0.1.0 - 2014-08-17 | https://github.com/bryanbraun/anchorjs | Copyright (c) 2014 Bryan Braun; Licensed MIT */function addAnchors(e){e=e||"h1, h2, h3, h4, h5, h6";var t=document.querySelectorAll(e);for(var n=0;n<t.length;n++){var r;if(t[n].hasAttribute("id")){r=t[n].getAttribute("id")}else{var i=document.body.textContent?"textContent":"innerText";var s=t[n][i];tidyText=s.replace(/\s+/g,"-").toLowerCase();t[n].setAttribute("id",tidyText);r=tidyText}var o='<a class="anchor-link" href="#'+r+'"><span class="icon-link"></span></a>';t[n].innerHTML=t[n].innerHTML+o}}