theme.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. function toggleCurrent (elem) {
  2. var parent_li = elem.closest('li');
  3. parent_li.siblings('li.current').removeClass('current');
  4. parent_li.siblings().find('li.current').removeClass('current');
  5. parent_li.find('> ul li.current').removeClass('current');
  6. parent_li.toggleClass('current');
  7. }
  8. $(document).ready(function() {
  9. // Shift nav in mobile when clicking the menu.
  10. $(document).on('click', "[data-toggle='wy-nav-top']", function() {
  11. $("[data-toggle='wy-nav-shift']").toggleClass("shift");
  12. $("[data-toggle='rst-versions']").toggleClass("shift");
  13. });
  14. // Nav menu link click operations
  15. $(document).on('click', ".wy-menu-vertical .current ul li a", function() {
  16. var target = $(this);
  17. // Close menu when you click a link.
  18. $("[data-toggle='wy-nav-shift']").removeClass("shift");
  19. $("[data-toggle='rst-versions']").toggleClass("shift");
  20. // Handle dynamic display of l3 and l4 nav lists
  21. toggleCurrent(target);
  22. if (typeof(window.SphinxRtdTheme) != 'undefined') {
  23. window.SphinxRtdTheme.StickyNav.hashChange();
  24. }
  25. });
  26. $(document).on('click', "[data-toggle='rst-current-version']", function() {
  27. $("[data-toggle='rst-versions']").toggleClass("shift-up");
  28. });
  29. // Make tables responsive
  30. $("table.docutils:not(.field-list)").wrap("<div class='wy-table-responsive'></div>");
  31. // Add expand links to all parents of nested ul
  32. $('.wy-menu-vertical ul').siblings('a').each(function () {
  33. var link = $(this);
  34. expand = $('<span class="toctree-expand"></span>');
  35. expand.on('click', function (ev) {
  36. toggleCurrent(link);
  37. ev.stopPropagation();
  38. return false;
  39. });
  40. link.prepend(expand);
  41. });
  42. });
  43. // Sphinx theme state
  44. window.SphinxRtdTheme = (function (jquery) {
  45. var stickyNav = (function () {
  46. var navBar,
  47. win,
  48. winScroll = false,
  49. linkScroll = false,
  50. winPosition = 0,
  51. enable = function () {
  52. init();
  53. reset();
  54. win.on('hashchange', reset);
  55. // Set scrolling
  56. win.on('scroll', function () {
  57. if (!linkScroll) {
  58. winScroll = true;
  59. }
  60. });
  61. setInterval(function () {
  62. if (winScroll) {
  63. winScroll = false;
  64. var newWinPosition = win.scrollTop(),
  65. navPosition = navBar.scrollTop(),
  66. newNavPosition = navPosition + (newWinPosition - winPosition);
  67. navBar.scrollTop(newNavPosition);
  68. winPosition = newWinPosition;
  69. }
  70. }, 25);
  71. },
  72. init = function () {
  73. navBar = jquery('nav.wy-nav-side:first');
  74. win = jquery(window);
  75. },
  76. reset = function () {
  77. // Get anchor from URL and open up nested nav
  78. var anchor = encodeURI(window.location.hash);
  79. if (anchor) {
  80. try {
  81. var link = $('.wy-menu-vertical')
  82. .find('[href="' + anchor + '"]');
  83. $('.wy-menu-vertical li.toctree-l1 li.current')
  84. .removeClass('current');
  85. link.closest('li.toctree-l2').addClass('current');
  86. link.closest('li.toctree-l3').addClass('current');
  87. link.closest('li.toctree-l4').addClass('current');
  88. }
  89. catch (err) {
  90. console.log("Error expanding nav for anchor", err);
  91. }
  92. }
  93. },
  94. hashChange = function () {
  95. linkScroll = true;
  96. win.one('hashchange', function () {
  97. linkScroll = false;
  98. });
  99. };
  100. jquery(init);
  101. return {
  102. enable: enable,
  103. hashChange: hashChange
  104. };
  105. }());
  106. return {
  107. StickyNav: stickyNav
  108. };
  109. }($));