conventionalcommits.org/js/anchorli.js

30 lines
867 B
JavaScript
Raw Normal View History

document.onreadystatechange = function () {
if (this.readyState === "complete") {
var createAnchorLink = function (id) {
var anchor = document.createElement("a");
anchor.className = "anchor-link";
anchor.href = "#" + id;
return anchor;
};
// Add IDs to all spec li elements
var specItems = document.querySelectorAll("#spec ol")[1]
.querySelectorAll('li');
for (var i = 0; i < specItems.length; i++)
{
var li = specItems[i];
li.id = 'spec-item-' + (i + 1);
}
2018-03-06 23:27:26 +01:00
// Add anchor link to all elements with an ID in the spec
var headers = document.querySelectorAll('#spec [id]');
for (var i = 0; i < headers.length; i++)
{
var element = headers[i];
var anchorLink = createAnchorLink(element.id);
element.insertBefore(anchorLink, element.firstChild)
}
}
};