haxeflixel.com
haxeflixel.com copied to clipboard
Documentation: Add anchors to <h>-tags
That way, you can link to an invidual section.
Meh. It seems like this might not work with javascript and has to be done at compile time with .eco.
Here's what I came up with:
function generateAnchors()
{
var docs = document.getElementsByClassName("doc-content")[0];
addAnchorsToTag(docs, "h1");
addAnchorsToTag(docs, "h2");
addAnchorsToTag(docs, "h3");
addAnchorsToTag(docs, "h4");
}
function addAnchorsToTag(docs, tag)
{
var tags = docs.getElementsByTagName(tag);
for (var i = 0; i < tags.length; i++)
{
var tag = tags[i];
var anchorName = tag.innerHTML;
tag.id = anchorName;
$(tag).wrap("<a class='inSiteAnchor' href='#" + anchorName + "'></a>");
}
}
The links and everything are working fine, but when loading a site with an anchor, it does not work, probably because the anchors don't exist right away (they are generated with <body onload="generateAnchors();">
.
@impaler Any ideas?
Best handled in a docpad plugin that way there is no clientside js.
I'm guessing this ticket is closed as well since we've ruled out adding logic to the client-side?
This issue is still open.
Ah okay, so someone needs to make a docpad plugin with this functionality. I don't know how easy it is to create a docpad plugin but I feel like it might be easier to create a custom npm package. I might look into this.