theme.js 4.7 KB

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