-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam Scarr
committed
Aug 1, 2018
1 parent
6b53238
commit 64ef057
Showing
4 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var anchorForId = function (id) { | ||
var anchor = document.createElement("a"); | ||
anchor.className = "anchor-link"; | ||
anchor.href = "#" + id; | ||
anchor.innerHTML = ' <svg class="anchor-icon" height="22px" viewBox="0 0 24 24" width="17px" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>'; | ||
return anchor; | ||
}; | ||
|
||
var linkifyAnchors = function (level, containingElement) { | ||
var headers = containingElement.getElementsByTagName("h" + level); | ||
for (var h = 0; h < headers.length; h++) { | ||
var header = headers[h]; | ||
|
||
if (typeof header.id !== "undefined" && header.id !== "") { | ||
header.appendChild(anchorForId(header.id)); | ||
|
||
} | ||
} | ||
}; | ||
|
||
|
||
document.onreadystatechange = function () { | ||
if (this.readyState === "complete") { | ||
var contentBlock = document.getElementsByTagName("body")[0] | ||
if (!contentBlock) { | ||
return; | ||
} | ||
for (var level = 2; level <= 4; level++) { | ||
linkifyAnchors(level, contentBlock); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters