1
0
mirror of synced 2024-11-26 23:06:02 +03:00
select2/docs/vendor/js/anchor.min.js
Florian Kissling df2122c00f Add anchor.js for pages using the default layout.
* adds styles for anchor.js (similar to the official Bootstrap docs)
 * currently results some of the generated links to have a suffix (e. g. examples.html#templating-1) added due to sections having the same ID as the headline copy that we want to link to
2015-04-09 20:27:45 +02:00

6 lines
1007 B
JavaScript

/*!
* AnchorJS - v0.3.1 - 2015-03-06
* https://github.com/bryanbraun/anchorjs
* Copyright (c) 2015 Bryan Braun; Licensed MIT
*/
function addAnchors(e){"use strict";if(e){if("string"!=typeof e)throw new Error("AnchorJS accepts only strings; you used a "+typeof e)}else e="h1, h2, h3, h4, h5, h6";var t=document.querySelectorAll(e);if(0===t.length)return!1;for(var r=document.querySelectorAll("[id]"),n=[].map.call(r,function(e){return e.id}),i=0;i<t.length;i++){var s;if(t[i].hasAttribute("id"))s=t[i].getAttribute("id");else{var o,a=document.body.textContent?"textContent":"innerText",c=t[i][a],l=c.replace(/[^\w\s-]/gi,"").replace(/\s+/g,"-").toLowerCase().substring(0,32),h=0,d=l;do void 0!==o&&(d=l+"-"+h),o=n.indexOf(d),h+=1;while(-1!==o);o=void 0,n.push(d),t[i].setAttribute("id",d),s=d}var u=s.replace(/-/g," "),p='<a class="anchorjs-link" href="#'+s+'"><span class="anchorjs-description">Anchor link for: '+u+'</span><span class="anchorjs-icon" aria-hidden="true"></span></a>';t[i].innerHTML+=p}}