theme.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. $( document ).ready(function() {
  2. // Shift nav in mobile when clicking the menu.
  3. $(document).on('click', "[data-toggle='wy-nav-top']", function() {
  4. $("[data-toggle='wy-nav-shift']").toggleClass("shift");
  5. $("[data-toggle='rst-versions']").toggleClass("shift");
  6. });
  7. // Close menu when you click a link.
  8. $(document).on('click', ".wy-menu-vertical .current ul li a", function() {
  9. $("[data-toggle='wy-nav-shift']").removeClass("shift");
  10. $("[data-toggle='rst-versions']").toggleClass("shift");
  11. });
  12. $(document).on('click', "[data-toggle='rst-current-version']", function() {
  13. $("[data-toggle='rst-versions']").toggleClass("shift-up");
  14. });
  15. // Make tables responsive
  16. $("table.docutils:not(.field-list)").wrap("<div class='wy-table-responsive'></div>");
  17. hljs.initHighlightingOnLoad();
  18. $('table').addClass('docutils');
  19. });
  20. window.SphinxRtdTheme = (function (jquery) {
  21. var stickyNav = (function () {
  22. var navBar,
  23. win,
  24. stickyNavCssClass = 'stickynav',
  25. applyStickNav = function () {
  26. if (navBar.height() <= win.height()) {
  27. navBar.addClass(stickyNavCssClass);
  28. } else {
  29. navBar.removeClass(stickyNavCssClass);
  30. }
  31. },
  32. enable = function () {
  33. applyStickNav();
  34. win.on('resize', applyStickNav);
  35. },
  36. init = function () {
  37. navBar = jquery('nav.wy-nav-side:first');
  38. win = jquery(window);
  39. };
  40. jquery(init);
  41. return {
  42. enable : enable
  43. };
  44. }());
  45. return {
  46. StickyNav : stickyNav
  47. };
  48. }($));
  49. // The code below is a copy of @seanmadsen code posted Jan 10, 2017 on issue 803.
  50. // https://github.com/mkdocs/mkdocs/issues/803
  51. // This just incorporates the auto scroll into the theme itself without
  52. // the need for additional custom.js file.
  53. //
  54. $(function() {
  55. $.fn.isFullyWithinViewport = function(){
  56. var viewport = {};
  57. viewport.top = $(window).scrollTop();
  58. viewport.bottom = viewport.top + $(window).height();
  59. var bounds = {};
  60. bounds.top = this.offset().top;
  61. bounds.bottom = bounds.top + this.outerHeight();
  62. return ( ! (
  63. (bounds.top <= viewport.top) ||
  64. (bounds.bottom >= viewport.bottom)
  65. ) );
  66. };
  67. if( $('li.toctree-l1.current').length && !$('li.toctree-l1.current').isFullyWithinViewport() ) {
  68. $('.wy-nav-side')
  69. .scrollTop(
  70. $('li.toctree-l1.current').offset().top -
  71. $('.wy-nav-side').offset().top -
  72. 60
  73. );
  74. }
  75. });