resize.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var cookie_namespace = 'doxygen';
  2. var sidenav,navtree,content,header;
  3. function readCookie(cookie)
  4. {
  5. var myCookie = cookie_namespace+"_"+cookie+"=";
  6. if (document.cookie)
  7. {
  8. var index = document.cookie.indexOf(myCookie);
  9. if (index != -1)
  10. {
  11. var valStart = index + myCookie.length;
  12. var valEnd = document.cookie.indexOf(";", valStart);
  13. if (valEnd == -1)
  14. {
  15. valEnd = document.cookie.length;
  16. }
  17. var val = document.cookie.substring(valStart, valEnd);
  18. return val;
  19. }
  20. }
  21. return 0;
  22. }
  23. function writeCookie(cookie, val, expiration)
  24. {
  25. if (val==undefined) return;
  26. if (expiration == null)
  27. {
  28. var date = new Date();
  29. date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
  30. expiration = date.toGMTString();
  31. }
  32. document.cookie = cookie_namespace + "_" + cookie + "=" + val + "; expires=" + expiration+"; path=/";
  33. }
  34. function resizeWidth()
  35. {
  36. var windowWidth = $(window).width() + "px";
  37. var sidenavWidth = $(sidenav).width();
  38. content.css({marginLeft:parseInt(sidenavWidth)+6+"px"}); //account for 6px-wide handle-bar
  39. writeCookie('width',sidenavWidth, null);
  40. }
  41. function restoreWidth(navWidth)
  42. {
  43. var windowWidth = $(window).width() + "px";
  44. content.css({marginLeft:parseInt(navWidth)+6+"px"});
  45. sidenav.css({width:navWidth + "px"});
  46. }
  47. function resizeHeight()
  48. {
  49. var headerHeight = header.height();
  50. var footerHeight = footer.height();
  51. var windowHeight = $(window).height() - headerHeight - footerHeight;
  52. content.css({height:windowHeight + "px"});
  53. navtree.css({height:windowHeight + "px"});
  54. sidenav.css({height:windowHeight + "px",top: headerHeight+"px"});
  55. }
  56. function initResizable()
  57. {
  58. header = $("#top");
  59. sidenav = $("#side-nav");
  60. content = $("#doc-content");
  61. navtree = $("#nav-tree");
  62. footer = $("#nav-path");
  63. $(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(); } });
  64. $(window).resize(function() { resizeHeight(); });
  65. var width = readCookie('width');
  66. if (width) { restoreWidth(width); } else { resizeWidth(); }
  67. resizeHeight();
  68. var url = location.href;
  69. var i=url.indexOf("#");
  70. if (i>=0) window.location.hash=url.substr(i);
  71. var _preventDefault = function(evt) { evt.preventDefault(); };
  72. $("#splitbar").bind("dragstart", _preventDefault).bind("selectstart", _preventDefault);
  73. $(document).bind('touchmove',function(e){
  74. try {
  75. var target = e.target;
  76. while (target) {
  77. if ($(target).css('-webkit-overflow-scrolling')=='touch') return;
  78. target = target.parentNode;
  79. }
  80. e.preventDefault();
  81. } catch(err) {
  82. e.preventDefault();
  83. }
  84. });
  85. }