1
0
mirror of synced 2024-11-30 08:36:03 +03:00
select2/docs/vendor/js/anchor.min.js

6 lines
1007 B
JavaScript
Raw Normal View History

/*!
* 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}}