layoutUtilities.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. //Converts value to integer
  13. //checks value to make sure its an int before conversion.
  14. function _LU_isMozilla()
  15. {
  16. var userAgent = navigator.userAgent.toLowerCase();
  17. if (((userAgent.indexOf('mozilla') > -1) && (userAgent.indexOf('msie') < 0)) || (userAgent.indexOf('firefox') > -1))
  18. {
  19. return true;
  20. }
  21. else
  22. {
  23. return false;
  24. }
  25. }
  26. function _LU_toInt(value, defaultValue){
  27. var nValue = parseInt(value);
  28. if (isNaN(nValue)){
  29. if (defaultValue){
  30. return defaultValue;
  31. }
  32. return 0;
  33. }
  34. return nValue;
  35. }
  36. function _LU_getStyle(obj){
  37. try {
  38. if (document.defaultView && xGetComputedStyle(document.defaultView)){
  39. return xGetComputedStyle(obj);
  40. }
  41. else if (obj.currentStyle){
  42. return obj.currentStyle;
  43. }
  44. } catch (e){}
  45. return obj.style;
  46. }
  47. function _LU_getTop(obj) {
  48. var curtop = 0;
  49. try {
  50. if (xParent(obj)) {
  51. while (xParent(obj)) {
  52. curtop += xOffsetTop(obj)
  53. obj = xParent(obj);
  54. }
  55. }
  56. else if (xPageY(obj)) {
  57. curtop += xPageY(obj);
  58. }
  59. }catch (e) {}
  60. return curtop;
  61. }
  62. function getWindowHeight(){
  63. if( typeof( window.innerHeight ) == 'number' ) {
  64. return window.innerHeight;
  65. } else if( document.documentElement && document.documentElement.clientHeight ) {
  66. return document.documentElement.clientHeight;
  67. } else if( document.body && document.body.clientHeight ) {
  68. return document.body.clientHeight;
  69. }
  70. }
  71. function _LU_getLastSiblingPositionedBelow(obj) {
  72. var lastValidSibling = null;
  73. var sibling = obj.nextSibling;
  74. while (sibling != null ) {
  75. if (sibling.tagName != null){
  76. var siblingStyle = _LU_getStyle(sibling);
  77. var isVisible = siblingStyle.display.toLowerCase() != "none" ;
  78. var isRelative = siblingStyle.position.toLowerCase() != "absolute" ;
  79. if (sibling.offsetHeight != null && isVisible && isRelative){
  80. var isSiblingPlacedBelow = _LU_getTop(obj) + obj.offsetHeight <= _LU_getTop(sibling);
  81. if (isSiblingPlacedBelow){
  82. obj = sibling;
  83. lastValidSibling = sibling;
  84. }
  85. }
  86. }
  87. sibling = sibling.nextSibling;
  88. }
  89. return lastValidSibling;
  90. }
  91. function _LU_getExtraBottomContent(obj) {
  92. var extraContentHeight;
  93. var lastSibling = _LU_getLastSiblingPositionedBelow(obj);
  94. if (lastSibling != null){
  95. var distance = _LU_getTop(lastSibling) - _LU_getTop(obj) - obj.offsetHeight;
  96. extraContentHeight = distance +
  97. _LU_toInt(_LU_getStyle(lastSibling).marginTop) +
  98. lastSibling.offsetHeight +
  99. _LU_toInt(_LU_getStyle(lastSibling).marginBottom)
  100. }
  101. else{
  102. extraContentHeight = _LU_toInt(_LU_getStyle(obj).marginBottom);
  103. }
  104. var parent =xParent(obj, true);
  105. var offsetParent = xParent(obj);
  106. if (parent && obj != document.body) {
  107. var parentStyle = _LU_getStyle(parent);
  108. if (parent != null && offsetParent != null && parent.rowIndex != null && offsetParent.cellSpacing != null && offsetParent.rows != null){
  109. var cellspacing = _LU_toInt(offsetParent.cellSpacing, 2) * (offsetParent.rows.length - parent.rowIndex );
  110. extraContentHeight += cellspacing;
  111. }
  112. extraContentHeight += _LU_toInt(parentStyle.paddingBottom) + _LU_toInt(parentStyle.borderBottomWidth);
  113. extraContentHeight += _LU_getExtraBottomContent(parent);
  114. }
  115. return extraContentHeight;
  116. }
  117. var _LU_minHeight = 100;
  118. function _LU_getNewHeight(id) {
  119. try {
  120. var eDiv= xGetElementById(id);
  121. if (eDiv != null) {
  122. var extraBottomContent = _LU_getExtraBottomContent(eDiv);
  123. var newHeight = xClientHeight() - _LU_getTop(eDiv) - extraBottomContent;
  124. if (newHeight < _LU_minHeight){
  125. newHeight = _LU_minHeight;
  126. }
  127. if (_LU_isMozilla())
  128. {
  129. var runtimeStyle = _LU_getStyle(eDiv);
  130. if (runtimeStyle){
  131. if (runtimeStyle.borderTopWidth){
  132. newHeight -= _LU_toInt(runtimeStyle.borderTopWidth);
  133. }
  134. if (runtimeStyle.borderBottomWidth){
  135. newHeight -= _LU_toInt(runtimeStyle.borderBottomWidth);
  136. }
  137. }
  138. }
  139. return newHeight;
  140. }
  141. }catch(e){}
  142. }
  143. function _LU_setHeight(id, newHeight, refresh){
  144. var eDiv= xGetElementById(id);
  145. if (eDiv != null) {
  146. newHeight -= 2;
  147. xHeight(eDiv,newHeight);
  148. if (_LU_isMozilla())
  149. {
  150. if (refresh){
  151. var oldBorderColor = eDiv.style.borderColor;
  152. var oldBorderWidth = eDiv.style.borderWidth;
  153. eDiv.style.borderWidth="1";
  154. eDiv.style.borderColor="transparent";
  155. setTimeout("xGetElementById(\""+id+"\").style.borderWidth = \""+oldBorderWidth+"\"" ,1);
  156. setTimeout("xGetElementById(\""+id+"\").style.borderColor = \""+oldBorderColor+"\"" ,1);
  157. }
  158. }
  159. }
  160. }
  161. function _LU_resize_main(elemId) {
  162. var newHeight;
  163. newHeight = _LU_getNewHeight(elemId);
  164. _LU_setHeight(elemId, newHeight, true);
  165. }