Tooltip.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2010
  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. //----------------------------------------------------------
  13. com.cognos.admin.ObjectFactory("com.cognos.admin.widget");
  14. com.cognos.admin.widget.Tooltip = function (tag,e,param) {
  15. this.tag = tag;
  16. this.tools = com.cognos.admin.util.Tools;
  17. this.event = new xEvent(e);
  18. this.tooltip;
  19. this.timeoutId;
  20. this.param = param;
  21. this.interval = this.param.interval || 30;
  22. this.fadePace = this.param.fadePace || 20;
  23. this.timeout = this.param.timeout || 200;
  24. };
  25. com.cognos.admin.widget.Tooltip.VERSION = "0.1.0";
  26. com.cognos.admin.widget.Tooltip.prototype = {
  27. /*
  28. *
  29. */
  30. create : function (){
  31. //id for the tooltip container
  32. var tooltipId = this.tag.id + "_tooltip";
  33. //id for the basic content container
  34. var basicDivId = tooltipId + "_basic";
  35. var self = this;
  36. if ($(tooltipId))
  37. xParent($(tooltipId),true).removeChild($(tooltipId));
  38. var div = document.createElement("div");
  39. div.id = tooltipId;
  40. div.className = "popup-tooltip";
  41. document.body.appendChild(div);
  42. this.tooltip = div;
  43. xAddEventListener(div,"mouseover",_F_Document.associate(div,this,"_evt_mouseOver"),false);
  44. xAddEventListener(div,"mouseout",_F_Document.associate(div,this,"_evt_mouseOut"),false);
  45. var basicDiv = document.createElement("div");
  46. basicDiv.id = basicDivId;
  47. this.tooltip.appendChild(basicDiv);
  48. this.setContent(this.param);
  49. this.tooltip.style.display = "none";
  50. },
  51. setContent : function (param){
  52. this.tools.parseContent(param,this.tooltip.id+"_basic");
  53. if (param.extension){
  54. this.setExtendContent (param.extension);
  55. } else {
  56. this.setOffset();
  57. }
  58. },
  59. setExtendContent : function (param){
  60. //id of the extend content container
  61. var extensionDivId = this.tooltip.id+"_extension";
  62. var promptDivId = this.tooltip.id+"_prompt";
  63. var extendHTML = "<span id=\""+promptDivId+"\" style=\"align:right;\">" +
  64. "<a href=\"#\" onclick=\"Javascript:$('"+extensionDivId+"').style.display='';$('"+promptDivId+"').style.display='none';\">" +param.prompt + ":</a>" +
  65. "</span>" +
  66. "<span id=\""+extensionDivId+"\" style=\"display:'';\"></span>";
  67. var extensionDiv = document.createElement("div");
  68. extensionDiv.innerHTML = extendHTML;
  69. this.tooltip.appendChild(extensionDiv);
  70. this.tools.parseContent(param,this.tooltip.id+"_extension");
  71. this.setOffset();
  72. $(extensionDivId).style.display = "none";
  73. },
  74. _evt_mouseOver : function (e,tag){
  75. clearTimeout(this.timeoutId);
  76. this.tooltip.style.display = "block";
  77. _F_log("D","mouseOver:"+tag.id);
  78. },
  79. _evt_mouseOut : function (e,tag) {
  80. this.hide(e,tag);
  81. _F_log("D","mouseOut:"+tag.id);
  82. },
  83. show : function (){
  84. var self = this;
  85. clearTimeout(this.timeoutId);
  86. if (!this.tooltip)
  87. this.create();
  88. this.timeoutId = setTimeout(function (){
  89. //self.tooltip.style.display = "block";
  90. self.fade(true);
  91. },this.timeout);
  92. },
  93. fade : function (isFadeIn){
  94. var objId = this.tooltip.id;
  95. for (var i = 0; i <= 100; i += this.fadePace){
  96. var fadeTime = (isFadeIn) ? ((this.interval*i)/this.fadePace) : ((this.interval*(100-i))/this.fadePace);
  97. setTimeout("com.cognos.admin.util.Tools.dspOpacity('"+objId+"',"+i+","+isFadeIn+")",fadeTime);
  98. }
  99. },
  100. hide : function (){
  101. var self = this;
  102. clearTimeout(this.timeoutId);
  103. this.timeoutId = setTimeout(function (){
  104. //self.tooltip.style.display = "none";
  105. self.fade(false);
  106. },this.timeout);
  107. //setTimeout(self.destroy,0);
  108. //this.destroy();
  109. },
  110. destroy : function (){
  111. var tooltip = this.tooltip;
  112. xRemoveEventListener (tooltip,"mouseover",_F_Document.associate(tooltip,this,"_evt_mouseOver"),false);
  113. xRemoveEventListener (tooltip,"mouseout",_F_Document.associate(tooltip,this,"_evt_mouseOut"),false);
  114. if (this.tooltip)
  115. document.body.removeChild(this.tooltip);
  116. this.tooltip = null;
  117. },
  118. setOffset : function (){
  119. xDisplay(this.tooltip,"block");
  120. xVisibility(this.tooltip,"hidden");
  121. var widthTooltip = xWidth(this.tooltip);
  122. var heightTooltip = xHeight(this.tooltip);
  123. var x = (this.event.pageX != undefined) ? this.event.pageX : (this.tools.getAbsolutePosition(this.tag).left + this.tag.clientWidth);
  124. var y = (this.event.pageY != undefined) ? this.event.pageY : (this.tools.getAbsolutePosition(this.tag).top + this.tag.clientHeight);
  125. if (document.body.dir == "rtl")
  126. {
  127. var windowLeft =0;
  128. if (typeof window.pageXOffset != "undefined"){
  129. windowLeft = window.pageXOffset;
  130. }else if (typeof document.documentElement.scrollLeft != "undefined" ){
  131. windowLeft = document.documentElement.scrollLeft;
  132. }else if (typeof document.body.scrollLeft != "undefined"){
  133. windowLeft = document.body.scrollLeft;
  134. }
  135. if((x - widthTooltip)> windowLeft){
  136. x = x - widthTooltip;
  137. }
  138. // test for the existence of left scroll
  139. if (xWidth(document.body) > document.body.clientWidth)
  140. x = x- (xWidth(document.body) - document.body.clientWidth);
  141. }
  142. if ((x + widthTooltip) > xWidth(document.body)) {
  143. x = xClientWidth() - widthTooltip;
  144. }
  145. if ((y + heightTooltip) > xHeight(document.body)) {
  146. y = xHeight(document.body) - heightTooltip - xScrollTop();
  147. } else {
  148. y += 10;
  149. }
  150. xLeft(this.tooltip,x);
  151. xTop(this.tooltip,y);
  152. xDisplay(this.tooltip,"none");
  153. xVisibility(this.tooltip,"visible");
  154. }
  155. };