resizeScrollarea.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cpscrn
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2011
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. function adjustScrollSection(formName,top,middle,bottom,layoutCorrection) {
  13. var bottomSection = document.getElementById(bottom);
  14. // Get the bottom section of the pane and add 8 pixels to the size
  15. // to account for the bottom edge of the panel dipping below the browser.
  16. var staticBottomHeight = bottomSection ? bottomSection.offsetHeight + 8 : 0;
  17. var formObj = document.getElementById(formName);
  18. // Ensure there is a scrollable section to resize.
  19. if(formObj)
  20. {
  21. // Get the middle section of the pane
  22. var scrollSection = document.getElementById(middle);
  23. if( scrollSection != null )
  24. {
  25. // Acquire the height of viewable area of the browser.
  26. var viewableHeight = 0;
  27. var db = (document.body) ? document.body : null;
  28. var dde = (document.documentElement) ? document.documentElement : null;
  29. if (dde && dde.clientHeight)
  30. {
  31. viewableHeight = dde.clientHeight;
  32. }
  33. else
  34. if (db && db.offsetHeight)
  35. {
  36. viewableHeight = db.offsetHeight;
  37. }
  38. // Calculate the height from the top of the middle section to the top of the viewable area.
  39. var staticTopHeight = scrollSection.offsetTop;
  40. var parentEle = scrollSection.offsetParent;
  41. while (parentEle != null)
  42. {
  43. staticTopHeight += parentEle.offsetTop - parentEle.scrollTop;
  44. parentEle = parentEle.offsetParent;
  45. }
  46. // Calculate the target height based on the difference between the viewable height
  47. // and the heights of the areas above and below the middle section.
  48. var targetHeight = (viewableHeight - (staticTopHeight + staticBottomHeight));
  49. // Must have a sizeable scroll section to work with.
  50. if (0 < targetHeight)
  51. {
  52. // Set up the scrollSection now.
  53. scrollSection.style.height = (targetHeight) + "px";
  54. if( typeof(layoutCorrection)!='undefined' && layoutCorrection.indexOf('HIDE_XSCROLL') > -1)
  55. {
  56. // This is required for browsers that require special processing to hide unnecessary horizontal scrollbar.
  57. scrollSection.style.overflowY = "auto";
  58. if (scrollSection.clientWidth > 0)
  59. {
  60. var barWidth = scrollSection.offsetWidth - scrollSection.clientWidth;
  61. if(0 < barWidth && barWidth < 20)
  62. {
  63. scrollSection.style.paddingRight = barWidth + "px";
  64. scrollSection.style.overflowX = "hidden";
  65. }
  66. else
  67. {
  68. scrollSection.style.overflowX = "auto";
  69. }
  70. }
  71. }
  72. else
  73. {
  74. scrollSection.style.overflow = "auto";
  75. }
  76. if( typeof(layoutCorrection)!='undefined' && layoutCorrection.indexOf('POSN_YSCROLL') > -1)
  77. {
  78. // This is required for browsers that require special processing to effectively display vertical scrollbars.
  79. if( 0 < (scrollSection.offsetWidth - scrollSection.clientWidth))
  80. scrollSection.style.marginRight = (scrollSection.offsetWidth - scrollSection.clientWidth) + "px";
  81. }
  82. }
  83. else
  84. {
  85. scrollSection.style.height = "0px";
  86. scrollSection.style.overflow = "hidden";
  87. }
  88. }
  89. }
  90. }