resize.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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).outerWidth();
  38. content.css({marginLeft:parseInt(sidenavWidth)+"px"});
  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.outerHeight();
  50. var footerHeight = footer.outerHeight();
  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. var device = navigator.userAgent.toLowerCase();
  75. var ios = device.match(/(iphone|ipod|ipad)/);
  76. if (ios) {
  77. try {
  78. var target = e.target;
  79. while (target) {
  80. if ($(target).css('-webkit-overflow-scrolling')=='touch') return;
  81. target = target.parentNode;
  82. }
  83. e.preventDefault();
  84. } catch(err) {
  85. e.preventDefault();
  86. }
  87. }
  88. });
  89. }