resize.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. @licstart The following is the entire license notice for the
  3. JavaScript code in this file.
  4. Copyright (C) 1997-2017 by Dimitri van Heesch
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. @licend The above is the entire license notice
  17. 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. (document.getElementById(location.hash.slice(1))||document.body).scrollIntoView();
  85. }
  86. function collapseExpand()
  87. {
  88. if (sidenav.width()>0) {
  89. restoreWidth(0);
  90. collapsed=true;
  91. }
  92. else {
  93. var width = readCookie('width');
  94. if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); }
  95. collapsed=false;
  96. }
  97. }
  98. header = $("#top");
  99. sidenav = $("#side-nav");
  100. content = $("#doc-content");
  101. navtree = $("#nav-tree");
  102. footer = $("#nav-path");
  103. $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } });
  104. $(sidenav).resizable({ minWidth: 0 });
  105. $(window).resize(function() { resizeHeight(); });
  106. var device = navigator.userAgent.toLowerCase();
  107. var touch_device = device.match(/(iphone|ipod|ipad|android)/);
  108. if (touch_device) { /* wider split bar for touch only devices */
  109. $(sidenav).css({ paddingRight:'20px' });
  110. $('.ui-resizable-e').css({ width:'20px' });
  111. $('#nav-sync').css({ right:'34px' });
  112. barWidth=20;
  113. }
  114. var width = readCookie('width');
  115. if (width) { restoreWidth(width); } else { resizeWidth(); }
  116. resizeHeight();
  117. var url = location.href;
  118. var i=url.indexOf("#");
  119. if (i>=0) window.location.hash=url.substr(i);
  120. var _preventDefault = function(evt) { evt.preventDefault(); };
  121. $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
  122. $(".ui-resizable-handle").dblclick(collapseExpand);
  123. $(window).on('load',resizeHeight);
  124. }
  125. /* @license-end */