docs.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // This script should be included at the END of the document.
  2. // For the fastest loading it does not inlude $(document).ready()
  3. // This Document contains a few helper functions for the documentation to display the current version,
  4. // collapse and expand the menu etc.
  5. // Function to make the sticky header possible
  6. function shiftWindow() {
  7. scrollBy(0, -70);
  8. console.log("window shifted")
  9. }
  10. window.addEventListener("hashchange", shiftWindow);
  11. function loadShift() {
  12. if (window.location.hash) {
  13. console.log("window has hash");
  14. shiftWindow();
  15. }
  16. }
  17. $(window).load(function() {
  18. loadShift();
  19. });
  20. $(function(){
  21. // sidebar accordian-ing
  22. // don't apply on last object (it should be the FAQ) or the first (it should be introduction)
  23. // define an array to which all opened items should be added
  24. var openmenus = [];
  25. var elements = $('.toctree-l2');
  26. // for (var i = 0; i < elements.length; i += 1) { var current = $(elements[i]); current.children('ul').hide();}
  27. // set initial collapsed state
  28. var elements = $('.toctree-l1');
  29. for (var i = 0; i < elements.length; i += 1) {
  30. var current = $(elements[i]);
  31. if (current.hasClass('current')) {
  32. current.addClass('open');
  33. currentlink = current.children('a')[0].href;
  34. openmenus.push(currentlink);
  35. // do nothing
  36. } else {
  37. // collapse children
  38. current.children('ul').hide();
  39. }
  40. }
  41. if (doc_version == "") {
  42. $('.version-flyer ul').html('<li class="alternative active-slug"><a href="" title="Switch to local">Local</a></li>');
  43. }
  44. // mark the active documentation in the version widget
  45. $(".version-flyer a:contains('" + doc_version + "')").parent().addClass('active-slug');
  46. // attached handler on click
  47. // Do not attach to first element or last (intro, faq) so that
  48. // first and last link directly instead of accordian
  49. $('.sidebar > ul > li > a').not(':last').not(':first').click(function(){
  50. var index = $.inArray(this.href, openmenus)
  51. if (index > -1) {
  52. console.log(index);
  53. openmenus.splice(index, 1);
  54. $(this).parent().children('ul').slideUp(200, function() {
  55. $(this).parent().removeClass('open'); // toggle after effect
  56. });
  57. }
  58. else {
  59. openmenus.push(this.href);
  60. var current = $(this);
  61. setTimeout(function() {
  62. // $('.sidebar > ul > li').removeClass('current');
  63. current.parent().addClass('current').addClass('open'); // toggle before effect
  64. current.parent().children('ul').hide();
  65. current.parent().children('ul').slideDown(200);
  66. }, 100);
  67. }
  68. return false;
  69. });
  70. // add class to all those which have children
  71. $('.sidebar > ul > li').not(':last').not(':first').addClass('has-children');
  72. });