theme.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Keyboard navigation
  13. document.addEventListener("keydown", function(e) {
  14. var key = e.which || e.keyCode || window.event && window.event.keyCode;
  15. var page;
  16. switch (key) {
  17. case 78: // n
  18. page = $('[role="navigation"] a:contains(Next):first').prop('href');
  19. break;
  20. case 80: // p
  21. page = $('[role="navigation"] a:contains(Previous):first').prop('href');
  22. break;
  23. case 13: // enter
  24. if (e.target === document.getElementById('mkdocs-search-query')) {
  25. e.preventDefault();
  26. }
  27. break;
  28. default: break;
  29. }
  30. if ($(e.target).is(':input')) {
  31. return true;
  32. } else if (page) {
  33. window.location.href = page;
  34. }
  35. });
  36. $(document).on('click', "[data-toggle='rst-current-version']", function() {
  37. $("[data-toggle='rst-versions']").toggleClass("shift-up");
  38. });
  39. // Make tables responsive
  40. $("table.docutils:not(.field-list)").wrap("<div class='wy-table-responsive'></div>");
  41. $('table').addClass('docutils');
  42. });
  43. window.SphinxRtdTheme = (function (jquery) {
  44. var stickyNav = (function () {
  45. var navBar,
  46. win,
  47. stickyNavCssClass = 'stickynav',
  48. applyStickNav = function () {
  49. if (navBar.height() <= win.height()) {
  50. navBar.addClass(stickyNavCssClass);
  51. } else {
  52. navBar.removeClass(stickyNavCssClass);
  53. }
  54. },
  55. enable = function () {
  56. applyStickNav();
  57. win.on('resize', applyStickNav);
  58. },
  59. init = function () {
  60. navBar = jquery('nav.wy-nav-side:first');
  61. win = jquery(window);
  62. };
  63. jquery(init);
  64. return {
  65. enable : enable
  66. };
  67. }());
  68. return {
  69. StickyNav : stickyNav
  70. };
  71. }($));
  72. // The code below is a copy of @seanmadsen code posted Jan 10, 2017 on issue 803.
  73. // https://github.com/mkdocs/mkdocs/issues/803
  74. // This just incorporates the auto scroll into the theme itself without
  75. // the need for additional custom.js file.
  76. //
  77. $(function() {
  78. $.fn.isFullyWithinViewport = function(){
  79. var viewport = {};
  80. viewport.top = $(window).scrollTop();
  81. viewport.bottom = viewport.top + $(window).height();
  82. var bounds = {};
  83. bounds.top = this.offset().top;
  84. bounds.bottom = bounds.top + this.outerHeight();
  85. return ( ! (
  86. (bounds.top <= viewport.top) ||
  87. (bounds.bottom >= viewport.bottom)
  88. ) );
  89. };
  90. if( $('li.toctree-l1.current').length && !$('li.toctree-l1.current').isFullyWithinViewport() ) {
  91. $('.wy-nav-side')
  92. .scrollTop(
  93. $('li.toctree-l1.current').offset().top -
  94. $('.wy-nav-side').offset().top -
  95. 60
  96. );
  97. }
  98. });