theme.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // ---
  18. // START DOC MODIFICATION BY RUFNEX
  19. // v1.0 04.02.2015
  20. // Add ToogleButton to get FullWidth-View by Johannes Gamperl codeigniter.de
  21. $('#openToc').click(function () {
  22. $('#nav').slideToggle();
  23. });
  24. $('#closeMe').toggle(
  25. function ()
  26. {
  27. setCookie('ciNav', 'yes', 365);
  28. $('#nav2').show();
  29. $('#topMenu').remove();
  30. $('body').css({background: 'none'});
  31. $('.wy-nav-content-wrap').css({background: 'none', 'margin-left': 0});
  32. $('.wy-breadcrumbs').append('<div style="float:right;"><div style="float:left;" id="topMenu">' + $('.wy-form').parent().html() + '</div></div>');
  33. $('.wy-nav-side').toggle();
  34. },
  35. function ()
  36. {
  37. setCookie('ciNav', 'no', 365);
  38. $('#topMenu').remove();
  39. $('#nav').hide();
  40. $('#nav2').hide();
  41. $('body').css({background: '#edf0f2;'});
  42. $('.wy-nav-content-wrap').css({background: 'none repeat scroll 0 0 #fcfcfc;', 'margin-left': '300px'});
  43. $('.wy-nav-side').show();
  44. }
  45. );
  46. if (getCookie('ciNav') == 'yes')
  47. {
  48. $('#closeMe').trigger('click');
  49. //$('#nav').slideToggle();
  50. }
  51. // END MODIFICATION ---
  52. });
  53. // Rufnex Cookie functions
  54. function setCookie(cname, cvalue, exdays) {
  55. // expire the old cookie if existed to avoid multiple cookies with the same name
  56. if (getCookie(cname)) {
  57. document.cookie = cname + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
  58. }
  59. var d = new Date();
  60. d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  61. var expires = "expires=" + d.toGMTString();
  62. document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
  63. }
  64. function getCookie(cname) {
  65. var name = cname + "=";
  66. var ca = document.cookie.split(';');
  67. for (var i = 0; i < ca.length; i++) {
  68. var c = ca[i];
  69. while (c.charAt(0) == ' ')
  70. c = c.substring(1);
  71. if (c.indexOf(name) == 0) {
  72. return c.substring(name.length, c.length);
  73. }
  74. }
  75. return '';
  76. }
  77. // End
  78. // resize window
  79. $(window).on('resize', function(){
  80. // show side nav on small screens when pulldown is enabled
  81. if (getCookie('ciNav') == 'yes' && $(window).width() <= 768) { // 768px is the tablet size defined by the theme
  82. $('.wy-nav-side').show();
  83. }
  84. // changing css with jquery seems to override the default css media query
  85. // change margin
  86. else if (getCookie('ciNav') == 'no' && $(window).width() <= 768) {
  87. $('.wy-nav-content-wrap').css({'margin-left': 0});
  88. }
  89. // hide side nav on large screens when pulldown is enabled
  90. else if (getCookie('ciNav') == 'yes' && $(window).width() > 768) {
  91. $('.wy-nav-side').hide();
  92. }
  93. // change margin
  94. else if (getCookie('ciNav') == 'no' && $(window).width() > 768) {
  95. $('.wy-nav-content-wrap').css({'margin-left': '300px'});
  96. }
  97. });
  98. window.SphinxRtdTheme = (function (jquery) {
  99. var stickyNav = (function () {
  100. var navBar,
  101. win,
  102. stickyNavCssClass = 'stickynav',
  103. applyStickNav = function () {
  104. if (navBar.height() <= win.height()) {
  105. navBar.addClass(stickyNavCssClass);
  106. } else {
  107. navBar.removeClass(stickyNavCssClass);
  108. }
  109. },
  110. enable = function () {
  111. applyStickNav();
  112. win.on('resize', applyStickNav);
  113. },
  114. init = function () {
  115. navBar = jquery('nav.wy-nav-side:first');
  116. win = jquery(window);
  117. };
  118. jquery(init);
  119. return {
  120. enable: enable
  121. };
  122. }());
  123. return {
  124. StickyNav: stickyNav
  125. };
  126. }($));