|
/** |
|
* Highlight navigation by subheading and update navbar/page url with section hash |
|
* |
|
* NOTE: Taken raw from Docker docs. |
|
* TODO: Refactor to vanilla JS and ES6 |
|
*/ |
|
function highlightRightNav(heading) { |
|
if (document.location.pathname.indexOf("/glossary/")<0){ |
|
console.log("highlightRightNav called on",document.location.pathname) |
|
if (heading == "title") |
|
{ |
|
history.replaceState({},"Top of page on " + document.location.pathname,document.location.protocol +"//"+ document.location.hostname + (location.port ? ':'+location.port: '') + document.location.pathname); |
|
$("#my_toc a").each(function(){ |
|
$(this).removeClass("active"); |
|
}); |
|
$("#sidebar-wrapper").animate({ |
|
scrollTop: 0 |
|
},800); |
|
} else { |
|
var targetAnchorHREF = document.location.protocol +"//"+ document.location.hostname + (location.port ? ':'+location.port: '') + document.location.pathname + "#" + heading; |
|
// make sure we aren't filtering out that heading level |
|
var noFilterFound = false; |
|
$("#my_toc a").each(function(){ |
|
if (this.href==targetAnchorHREF) { |
|
noFilterFound = true; |
|
} |
|
}); |
|
// now, highlight that heading |
|
if (noFilterFound) |
|
{ |
|
$("#my_toc a").each(function(){ |
|
//console.log("right-nav",this.href); |
|
if (this.href==targetAnchorHREF) |
|
{ |
|
history.replaceState({},this.innerText,targetAnchorHREF); |
|
$(this).addClass("active"); |
|
var sidebarOffset = (sidebarBottom > 200) ? 200 : headerOffset - 20; |
|
$("#sidebar-wrapper").animate({ |
|
scrollTop: $("#sidebar-wrapper").scrollTop() + $(this).position().top - sidebarOffset |
|
},100); |
|
//document.getElementById("sidebar-wrapper").scrollTop = this.getBoundingClientRect().top - 200; |
|
} else { |
|
$(this).removeClass("active"); |
|
} |
|
}); |
|
} |
|
} |
|
} |
|
} |