rancher-docs.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $(document).ready(function(){
  2. var $menu = $("#menu");
  3. $menu.slicknav({
  4. label: "Navigation",
  5. duration: 250,
  6. appendTo: "header"
  7. });
  8. // Expand the tree to the current URL
  9. var found = false;
  10. $menu.find("a").each(function(idx, link) {
  11. if ( link.href === window.location.href) {
  12. expand(link);
  13. $(link).addClass('active');
  14. found = true;
  15. }
  16. });
  17. // Expand items when clicking on the tree
  18. $menu.on("click", "li a", function(event) {
  19. var open = isExpanded(this);
  20. collapseAll();
  21. if ( !open ) {
  22. expand(this);
  23. }
  24. // Don't change the URL for links that are just an anchor like "#hosts"
  25. if ( $(this).attr('href').substr(0,1) === '#' ) {
  26. event.preventDefault();
  27. event.stopPropagation();
  28. }
  29. });
  30. $('.content-container').on('mouseenter', 'h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]', function(e) {
  31. $(e.target).append($('<a />').addClass('header-anchor').attr('href', '#' + e.target.id).html('<i class="fa fa-link " aria-hidden="true"></i>'));
  32. });
  33. $('.content-container').on('mouseleave', 'h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]', function(e) {
  34. $(e.target).parent().find('.header-anchor').remove();
  35. });
  36. });
  37. function isExpanded(link) {
  38. return $(link).closest("li").hasClass("active");
  39. }
  40. function expand(link) {
  41. $(link).parentsUntil("#menu","li").addClass("active");
  42. }
  43. function collapseAll() {
  44. $('#menu .active').removeClass('active');
  45. }