resize.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function initResizable()
  2. {
  3. var cookie_namespace = 'doxygen';
  4. var sidenav,navtree,content,header,collapsed,collapsedWidth=0,barWidth=6,desktop_vp=768,titleHeight;
  5. function readCookie(cookie)
  6. {
  7. var myCookie = cookie_namespace+"_"+cookie+"=";
  8. if (document.cookie) {
  9. var index = document.cookie.indexOf(myCookie);
  10. if (index != -1) {
  11. var valStart = index + myCookie.length;
  12. var valEnd = document.cookie.indexOf(";", valStart);
  13. if (valEnd == -1) {
  14. valEnd = document.cookie.length;
  15. }
  16. var val = document.cookie.substring(valStart, valEnd);
  17. return val;
  18. }
  19. }
  20. return 0;
  21. }
  22. function writeCookie(cookie, val, expiration)
  23. {
  24. if (val==undefined) return;
  25. if (expiration == null) {
  26. var date = new Date();
  27. date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
  28. expiration = date.toGMTString();
  29. }
  30. document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/";
  31. }
  32. function resizeWidth()
  33. {
  34. var windowWidth = $(window).width() + "px";
  35. var sidenavWidth = $(sidenav).outerWidth();
  36. content.css({marginLeft:parseInt(sidenavWidth)+"px"});
  37. writeCookie('width',sidenavWidth-barWidth, null);
  38. }
  39. function restoreWidth(navWidth)
  40. {
  41. var windowWidth = $(window).width() + "px";
  42. content.css({marginLeft:parseInt(navWidth)+barWidth+"px"});
  43. sidenav.css({width:navWidth + "px"});
  44. }
  45. function resizeHeight()
  46. {
  47. var headerHeight = header.outerHeight();
  48. var footerHeight = footer.outerHeight();
  49. var windowHeight = $(window).height() - headerHeight - footerHeight;
  50. content.css({height:windowHeight + "px"});
  51. navtree.css({height:windowHeight + "px"});
  52. sidenav.css({height:windowHeight + "px"});
  53. var width=$(window).width();
  54. if (width!=collapsedWidth) {
  55. if (width<desktop_vp && collapsedWidth>=desktop_vp) {
  56. if (!collapsed) {
  57. collapseExpand();
  58. }
  59. } else if (width>desktop_vp && collapsedWidth<desktop_vp) {
  60. if (collapsed) {
  61. collapseExpand();
  62. }
  63. }
  64. collapsedWidth=width;
  65. }
  66. }
  67. function collapseExpand()
  68. {
  69. if (sidenav.width()>0) {
  70. restoreWidth(0);
  71. collapsed=true;
  72. }
  73. else {
  74. var width = readCookie('width');
  75. if (width>200 && width<$(window).width()) { restoreWidth(width); } else { restoreWidth(200); }
  76. collapsed=false;
  77. }
  78. }
  79. header = $("#top");
  80. sidenav = $("#side-nav");
  81. content = $("#doc-content");
  82. navtree = $("#nav-tree");
  83. footer = $("#nav-path");
  84. $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } });
  85. $(sidenav).resizable({ minWidth: 0 });
  86. $(window).resize(function() { resizeHeight(); });
  87. var device = navigator.userAgent.toLowerCase();
  88. var touch_device = device.match(/(iphone|ipod|ipad|android)/);
  89. if (touch_device) { /* wider split bar for touch only devices */
  90. $(sidenav).css({ paddingRight:'20px' });
  91. $('.ui-resizable-e').css({ width:'20px' });
  92. $('#nav-sync').css({ right:'34px' });
  93. barWidth=20;
  94. }
  95. var width = readCookie('width');
  96. if (width) { restoreWidth(width); } else { resizeWidth(); }
  97. resizeHeight();
  98. var url = location.href;
  99. var i=url.indexOf("#");
  100. if (i>=0) window.location.hash=url.substr(i);
  101. var _preventDefault = function(evt) { evt.preventDefault(); };
  102. $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
  103. $(".ui-resizable-handle").dblclick(collapseExpand);
  104. $(window).load(resizeHeight);
  105. }