docs.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. // attached handler on click
  42. // Do not attach to first element or last (intro, faq) so that
  43. // first and last link directly instead of accordian
  44. $('.sidebar > ul > li > a').not(':last').not(':first').click(function(){
  45. var index = $.inArray(this.href, openmenus)
  46. if (index > -1) {
  47. console.log(index);
  48. openmenus.splice(index, 1);
  49. $(this).parent().children('ul').slideUp(200, function() {
  50. $(this).parent().removeClass('open'); // toggle after effect
  51. });
  52. }
  53. else {
  54. openmenus.push(this.href);
  55. var current = $(this);
  56. setTimeout(function() {
  57. // $('.sidebar > ul > li').removeClass('current');
  58. current.parent().addClass('current').addClass('open'); // toggle before effect
  59. current.parent().children('ul').hide();
  60. current.parent().children('ul').slideDown(200);
  61. }, 100);
  62. }
  63. return false;
  64. });
  65. // add class to all those which have children
  66. $('.sidebar > ul > li').not(':last').not(':first').addClass('has-children');
  67. if (doc_version == "") {
  68. $('.version-flyer ul').html('<li class="alternative active-slug"><a href="" title="Switch to local">Local</a></li>');
  69. }
  70. if (doc_version == "latest") {
  71. $('.version-flyer .version-note').hide();
  72. }
  73. // mark the active documentation in the version widget
  74. $(".version-flyer a:contains('" + doc_version + "')").parent().addClass('active-slug').setAttribute("title", "Current version");
  75. });