base.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. $(document).ready(function ()
  2. {
  3. prettyPrint();
  4. // Resizing
  5. resizeMenuDropdown();
  6. // checkToScrollTOC();
  7. $(window).resize(function() {
  8. if(this.resizeTO)
  9. {
  10. clearTimeout(this.resizeTO);
  11. }
  12. this.resizeTO = setTimeout(function ()
  13. {
  14. resizeMenuDropdown();
  15. // checkToScrollTOC();
  16. }, 500);
  17. });
  18. /* Follow TOC links (ScrollSpy) */
  19. $('body').scrollspy({
  20. target: '#toc_table',
  21. });
  22. /* Prevent disabled link clicks */
  23. $("li.disabled a").click(function ()
  24. {
  25. event.preventDefault();
  26. });
  27. // Submenu ensured drop-down functionality for desktops & mobiles
  28. $('.dd_menu').on({
  29. click: function ()
  30. {
  31. $(this).toggleClass('dd_on_hover');
  32. },
  33. mouseenter: function ()
  34. {
  35. $(this).addClass('dd_on_hover');
  36. },
  37. mouseleave: function ()
  38. {
  39. $(this).removeClass('dd_on_hover');
  40. },
  41. });
  42. function getURLP(name)
  43. {
  44. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20')) || null;
  45. }
  46. if (getURLP("q")) {
  47. // Tipue Search activation
  48. $('#tipue_search_input').tipuesearch({
  49. 'mode': 'json',
  50. 'contentLocation': '/search_content.json.gz'
  51. });
  52. }
  53. });
  54. function resizeMenuDropdown ()
  55. {
  56. $('.dd_menu > .dd_submenu').css("max-height", ($('body').height() - 160) + 'px');
  57. }
  58. // https://github.com/bigspotteddog/ScrollToFixed
  59. function checkToScrollTOC ()
  60. {
  61. if ( $(window).width() >= 768 )
  62. {
  63. // If TOC is hidden, expand.
  64. $('#toc_table > #toc_navigation').css("display", "block");
  65. // Then attach or detach fixed-scroll
  66. if ( ($('#toc_table').height() + 100) >= $(window).height() )
  67. {
  68. $('#toc_table').trigger('detach.ScrollToFixed');
  69. $('#toc_navigation > li.active').removeClass('active');
  70. }
  71. else
  72. {
  73. $('#toc_table').scrollToFixed({
  74. marginTop: $('#nav_menu').height(),
  75. limit: function () { return $('#footer').offset().top - 450; },
  76. zIndex: 1,
  77. minWidth: 768,
  78. removeOffsets: true,
  79. });
  80. }
  81. }
  82. }
  83. function getCookie(cname) {
  84. var name = cname + "=";
  85. var ca = document.cookie.split(';');
  86. for(var i=0; i<ca.length; i++) {
  87. var c = ca[i].trim();
  88. if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  89. }
  90. return "";
  91. }