🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

  1. /*
  2. Internal link topbar offest adjust Javascript
  3. Code provided by @makshh on GitHub
  4. Bug report on material-mkdocs
  5. https://github.com/squidfunk/mkdocs-material/issues/791
  6. */
  7. // Offset top helper
  8. function offsetY(elem) {
  9. if(!elem) elem = this;
  10. var y = elem.offsetTop;
  11. while (elem = elem.offsetParent) {
  12. y += elem.offsetTop;
  13. }
  14. return y;
  15. }
  16. // If a link on the same page is clicked, calculate the
  17. // correct offset and scroll to that part of the page.
  18. //
  19. var links = document.getElementsByTagName('a');
  20. for(var i = 0; i < links.length; i++) {
  21. links[i].onclick = function (event) {
  22. if (this.pathname == window.location.pathname &&
  23. this.protocol == window.location.protocol &&
  24. this.host == window.location.host) {
  25. event.preventDefault();
  26. if(this.hash.substr(1)){
  27. var o = document.getElementById(this.hash.substr(1));
  28. var sT = offsetY(o) - document.getElementsByClassName('md-header')[0].clientHeight;
  29. window.location.hash = this.hash;
  30. window.scrollTo(0, sT);
  31. }
  32. }
  33. }
  34. }
  35. // Slugify supplied text
  36. function slugify(text){
  37. text = text.toLowerCase();
  38. text = text.replace(" ", "-");
  39. return text;
  40. }
  41. // If there is a hash in the url, slugify it
  42. // and replace
  43. if(window.location.hash) {
  44. // Fragment exists
  45. slug = slugify(window.location.hash);
  46. history.replaceState(undefined, undefined, slug)
  47. //window.location.hash = slug;
  48. document.location.replace(window.location.href);
  49. }