tabs.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2014
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. function obj(sName) {
  11. return document.getElementById(sName);
  12. }
  13. var g_oTabWindow = document.getElementById('tabWindow');
  14. var g_oTabs = document.getElementById('tabs');
  15. var g_oBody = document.getElementsByTagName('body')[0];
  16. var g_sDirection = "";
  17. var oInterval = null;
  18. var g_bEndScroll = false;
  19. var g_iIncrument = null;
  20. var g_iDefualtIncrument = 5;
  21. var g_scrollDisabled = false;
  22. function tabControlMouseOver(obj) {
  23. if (obj.className != 'tabScrollButtonDisabled') {
  24. obj.className = 'tabScrollButtonOver';
  25. }
  26. }
  27. function tabControlMouseOut(obj) {
  28. if (obj.className != 'tabScrollButtonDisabled') {
  29. obj.className = 'tabScrollButton';
  30. }
  31. }
  32. function tabControlDisable() {
  33. obj('tabControlRight').src = g_sImageRoot + "action_scroll_right_disabled.gif";
  34. obj('tabControlRightContainer').className = 'tabScrollButtonDisabled';
  35. obj('tabControlLeft').src = g_sImageRoot + "action_scroll_left_disabled.gif";
  36. obj('tabControlLeftContainer').className = 'tabScrollButtonDisabled';
  37. g_scrollDisabled = true;
  38. }
  39. function tabControlEnable() {
  40. obj('tabControlRight').src = g_sImageRoot + "action_scroll_right.gif";
  41. obj('tabControlRightContainer').className = 'tabScrollButton';
  42. obj('tabControlLeft').src = g_sImageRoot + "action_scroll_left.gif";
  43. obj('tabControlLeftContainer').className = 'tabScrollButton';
  44. g_scrollDisabled = false;
  45. }
  46. function tabControlDBLClick(sDirection, evt) {
  47. var e = (evt) ? evt : (event) ? event : null;
  48. if (g_scrollDisabled) {
  49. return;
  50. }
  51. window.clearInterval(oInterval);
  52. oInterval = "";
  53. var inc = (e.shiftKey) ? (g_iDefualtIncrument * 2) : g_iDefualtIncrument;
  54. scrollTab(sDirection, inc, e.ctrlKey);
  55. }
  56. function tabControlPress(sDirection, evt) {
  57. var e = (evt) ? evt : (event) ? event : null;
  58. if (g_scrollDisabled || e === null) {
  59. return;
  60. }
  61. g_sDirection = sDirection;
  62. g_bEndScroll = e.ctrlKey;
  63. g_iIncrument = (e.shiftKey) ? (g_iDefualtIncrument * 2) : g_iDefualtIncrument;
  64. oInterval = window.setInterval("scrollTab(g_sDirection,g_iIncrument,g_bEndScroll);", 10);
  65. return true;
  66. }
  67. function tabControlRelease() {
  68. window.clearInterval(oInterval);
  69. oInterval = "";
  70. }
  71. function scrollTab(sDirection, iIncrument, bEnd) {
  72. var iMaxScroll = g_oTabs.clientWidth - g_oTabWindow.clientWidth;
  73. if (iMaxScroll < 0) {
  74. iMaxScroll = 0;
  75. }
  76. var iScrollIncrument = (iIncrument > 0) ? iIncrument : g_iDefualtIncrument;
  77. if (bEnd) {
  78. iScrollIncrument = iMaxScroll;
  79. }
  80. var iScrollWidth = 0;
  81. var iAvailableScroll;
  82. if (sDirection == 'right') {
  83. iAvailableScroll = iMaxScroll - g_oTabWindow.scrollLeft;
  84. if (iAvailableScroll <= iScrollIncrument) {
  85. iScrollWidth = iAvailableScroll;
  86. } else {
  87. iScrollWidth = iScrollIncrument;
  88. }
  89. } else {
  90. iAvailableScroll = g_oTabWindow.scrollLeft;
  91. if (iAvailableScroll <= iScrollIncrument) {
  92. iScrollWidth = iAvailableScroll;
  93. } else {
  94. iScrollWidth = iScrollIncrument;
  95. }
  96. iScrollWidth = -(iScrollWidth);
  97. }
  98. g_oTabWindow.scrollLeft = g_oTabWindow.scrollLeft + iScrollWidth;
  99. }
  100. function tabEvalScroll() {
  101. var bodySize = g_oBody.offsetWidth -48;
  102. var style = "overflow:hidden;width:" + bodySize + "px";
  103. g_oTabWindow.setAttribute("style",style);
  104. var iMaxScroll = g_oTabs.clientWidth - g_oTabWindow.clientWidth;
  105. if (iMaxScroll > 0) {
  106. tabControlEnable();
  107. } else {
  108. tabControlDisable();
  109. }
  110. }
  111. function tabControlInitialize() {
  112. g_oBody.setAttribute("onresize","tabEvalScroll()");
  113. var oSelectedTab = document.getElementById('selectedTab');
  114. tabEvalScroll();
  115. if (oSelectedTab) {
  116. // Scroll to the selected tab
  117. var iSTWidth = oSelectedTab.offsetWidth;
  118. var iSTLeft = oSelectedTab.offsetLeft;
  119. var iTWWidth = g_oTabWindow.offsetWidth;
  120. var iLeftScrollOffset = (iTWWidth - iSTWidth) / 2;
  121. var iScroll = iSTLeft - iLeftScrollOffset;
  122. if ((iSTWidth + iSTLeft) > iTWWidth) {
  123. scrollTab('right', iScroll, false);
  124. }
  125. }
  126. }
  127. function tabControlResize() {}