base.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. $(document).ready(function ()
  2. {
  3. // Detect if the device is "touch" capable
  4. var isTouchDevice = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
  5. // Tipue Search activation
  6. $('#tipue_search_input').tipuesearch({
  7. 'mode': 'json',
  8. 'contentLocation': '/search_content.json'
  9. });
  10. prettyPrint();
  11. // Resizing
  12. resizeMenuDropdown();
  13. checkToScrollTOC();
  14. $(window).resize(function() {
  15. if(this.resizeTO)
  16. {
  17. clearTimeout(this.resizeTO);
  18. }
  19. this.resizeTO = setTimeout(function ()
  20. {
  21. resizeMenuDropdown();
  22. checkToScrollTOC();
  23. }, 500);
  24. });
  25. /* Auto scroll */
  26. $('#nav_menu').scrollToFixed({
  27. dontSetWidth: true,
  28. });
  29. /* Toggle TOC view for Mobile */
  30. $('#toc_table > h2').on('click', function ()
  31. {
  32. if ( $(window).width() <= 991 )
  33. {
  34. $('#toc_table > #toc_navigation').slideToggle();
  35. }
  36. });
  37. // Submenu ensured drop-down functionality for desktops & mobiles
  38. $('.dd_menu').on({
  39. click: function ()
  40. {
  41. if (isTouchDevice)
  42. {
  43. $(this).toggleClass('dd_on_hover');
  44. }
  45. },
  46. mouseenter: function ()
  47. {
  48. if (!isTouchDevice)
  49. {
  50. $(this).addClass('dd_on_hover');
  51. }
  52. },
  53. mouseleave: function ()
  54. {
  55. $(this).removeClass('dd_on_hover');
  56. },
  57. });
  58. /* Follow TOC links (ScrollSpy) */
  59. $('body').scrollspy({
  60. target: '#toc_table',
  61. });
  62. /* Prevent disabled link clicks */
  63. $("li.disabled a").click(function ()
  64. {
  65. event.preventDefault();
  66. });
  67. });
  68. function resizeMenuDropdown ()
  69. {
  70. $('.dd_menu > .dd_submenu').css("max-height", ($('body').height() - 160) + 'px');
  71. }
  72. // https://github.com/bigspotteddog/ScrollToFixed
  73. function checkToScrollTOC ()
  74. {
  75. if ( $(window).width() >= 768 )
  76. {
  77. // If TOC is hidden, expand.
  78. $('#toc_table > #toc_navigation').css("display", "block");
  79. // Then attach or detach fixed-scroll
  80. if ( ($('#toc_table').height() + 100) >= $(window).height() )
  81. {
  82. $('#toc_table').trigger('detach.ScrollToFixed');
  83. $('#toc_navigation > li.active').removeClass('active');
  84. }
  85. else
  86. {
  87. $('#toc_table').scrollToFixed({
  88. marginTop: $('#nav_menu').height() + 14,
  89. limit: function () { return $('#footer').offset().top - 450; },
  90. zIndex: 1,
  91. minWidth: 768,
  92. removeOffsets: true,
  93. });
  94. }
  95. }
  96. }