2
0

resize.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. @licstart The following is the entire license notice for the JavaScript code in this file.
  3. The MIT License (MIT)
  4. Copyright (C) 1997-2020 by Dimitri van Heesch
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  6. and associated documentation files (the "Software"), to deal in the Software without restriction,
  7. including without limitation the rights to use, copy, modify, merge, publish, distribute,
  8. sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all copies or
  11. substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  13. BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  15. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. @licend The above is the entire license notice for the JavaScript code in this file
  18. */
  19. function initResizable()
  20. {
  21. var cookie_namespace = 'doxygen';
  22. var sidenav,navtree,content,header,collapsed,collapsedWidth=0,barWidth=6,desktop_vp=768,titleHeight;
  23. function readCookie(cookie)
  24. {
  25. var myCookie = cookie_namespace+"_"+cookie+"=";
  26. if (document.cookie) {
  27. var index = document.cookie.indexOf(myCookie);
  28. if (index != -1) {
  29. var valStart = index + myCookie.length;
  30. var valEnd = document.cookie.indexOf(";", valStart);
  31. if (valEnd == -1) {
  32. valEnd = document.cookie.length;
  33. }
  34. var val = document.cookie.substring(valStart, valEnd);
  35. return val;
  36. }
  37. }
  38. return 0;
  39. }
  40. function writeCookie(cookie, val, expiration)
  41. {
  42. if (val==undefined) return;
  43. if (expiration == null) {
  44. var date = new Date();
  45. date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
  46. expiration = date.toGMTString();
  47. }
  48. document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/";
  49. }
  50. function resizeWidth()
  51. {
  52. var windowWidth = $(window).width() + "px";
  53. var sidenavWidth = $(sidenav).outerWidth();
  54. content.css({marginLeft:parseInt(sidenavWidth)+"px"});
  55. writeCookie('width',sidenavWidth-barWidth, null);
  56. }
  57. function restoreWidth(navWidth)
  58. {
  59. var windowWidth = $(window).width() + "px";
  60. content.css({marginLeft:parseInt(navWidth)+barWidth+"px"});
  61. sidenav.css({width:navWidth + "px"});
  62. }
  63. function resizeHeight()
  64. {
  65. var headerHeight = header.outerHeight();
  66. var footerHeight = footer.outerHeight();
  67. var windowHeight = $(window).height() - headerHeight - footerHeight;
  68. content.css({height:windowHeight + "px"});
  69. navtree.css({height:windowHeight + "px"});
  70. sidenav.css({height:windowHeight + "px"});
  71. var width=$(window).width();
  72. if (width!=collapsedWidth) {
  73. if (width<desktop_vp && collapsedWidth>=desktop_vp) {
  74. if (!collapsed) {
  75. collapseExpand();
  76. }
  77. } else if (width>desktop_vp && collapsedWidth<desktop_vp) {
  78. if (collapsed) {
  79. collapseExpand();
  80. }
  81. }
  82. collapsedWidth=width;
  83. }
  84. if (location.hash.slice(1)) {
  85. (document.getElementById(location.hash.slice(1))||document.body).scrollIntoView();
  86. }
  87. }
  88. function collapseExpand()
  89. {
  90. if (sidenav.width()>0) {
  91. restoreWidth(0);
  92. collapsed=true;
  93. }
  94. else {
  95. var width = readCookie('width');
  96. if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); }
  97. collapsed=false;
  98. }
  99. }
  100. header = $("#top");
  101. sidenav = $("#side-nav");
  102. content = $("#doc-content");
  103. navtree = $("#nav-tree");
  104. footer = $("#nav-path");
  105. $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } });
  106. $(sidenav).resizable({ minWidth: 0 });
  107. $(window).resize(function() { resizeHeight(); });
  108. var device = navigator.userAgent.toLowerCase();
  109. var touch_device = device.match(/(iphone|ipod|ipad|android)/);
  110. if (touch_device) { /* wider split bar for touch only devices */
  111. $(sidenav).css({ paddingRight:'20px' });
  112. $('.ui-resizable-e').css({ width:'20px' });
  113. $('#nav-sync').css({ right:'34px' });
  114. barWidth=20;
  115. }
  116. var width = readCookie('width');
  117. if (width) { restoreWidth(width); } else { resizeWidth(); }
  118. resizeHeight();
  119. var url = location.href;
  120. var i=url.indexOf("#");
  121. if (i>=0) window.location.hash=url.substr(i);
  122. var _preventDefault = function(evt) { evt.preventDefault(); };
  123. $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
  124. $(".ui-resizable-handle").dblclick(collapseExpand);
  125. $(window).on('load',resizeHeight);
  126. }
  127. /* @license-end */