pkgdown.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. $(function() {
  2. $("#sidebar").stick_in_parent({offset_top: 40});
  3. $('body').scrollspy({
  4. target: '#sidebar',
  5. offset: 60
  6. });
  7. var cur_path = paths(location.pathname);
  8. $("#navbar ul li a").each(function(index, value) {
  9. if (value.text == "Home")
  10. return;
  11. if (value.getAttribute("href") === "#")
  12. return;
  13. var path = paths(value.pathname);
  14. if (is_prefix(cur_path, path)) {
  15. // Add class to parent <li>, and enclosing <li> if in dropdown
  16. var menu_anchor = $(value);
  17. menu_anchor.parent().addClass("active");
  18. menu_anchor.closest("li.dropdown").addClass("active");
  19. }
  20. });
  21. });
  22. function paths(pathname) {
  23. var pieces = pathname.split("/");
  24. pieces.shift(); // always starts with /
  25. var end = pieces[pieces.length - 1];
  26. if (end === "index.html" || end === "")
  27. pieces.pop();
  28. return(pieces);
  29. }
  30. function is_prefix(needle, haystack) {
  31. if (needle.length > haystack.lengh)
  32. return(false);
  33. for (var i = 0; i < haystack.length; i++) {
  34. if (needle[i] != haystack[i])
  35. return(false);
  36. }
  37. return(true);
  38. }