Skip to content
Snippets Groups Projects
Commit 62827d68 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[doc toc script] More accurate active link highlighting

parent 765d3a96
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ document.createElement("section");
document.createElement("article");
(function() {
if (!window.addEventListener) return;
var pending = false, prevVal = null;
function updateSoon() {
......@@ -41,8 +42,16 @@ document.createElement("article");
}
}
if (window.addEventListener) {
window.addEventListener("scroll", updateSoon);
window.addEventListener("load", updateSoon);
}
window.addEventListener("scroll", updateSoon);
window.addEventListener("load", updateSoon);
window.addEventListener("hashchange", function() {
setTimeout(function() {
var hash = document.location.hash, found = null, m;
var marks = document.getElementById("nav").getElementsByTagName("a");
for (var i = 0; i < marks.length; i++)
if ((m = marks[i].href.match(/(#.*)/)) && m[1] == hash) { found = i; break; }
if (found != null) for (var i = 0; i < marks.length; i++)
marks[i].className = i == found ? "active" : "";
}, 300);
});
})();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment