Changeset 6215
- Timestamp:
- 08/20/08 23:58:12 (3 months ago)
- Files:
-
- 1 modified
-
trunk/centreon/www/lib/wz_tooltip/wz_tooltip.js (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/centreon/www/lib/wz_tooltip/wz_tooltip.js
r5725 r6215 2 2 Copyright (c) 2002-2008 Walter Zorn. All rights reserved. 3 3 4 wz_tooltip.js v. 5. 134 wz_tooltip.js v. 5.20 5 5 6 6 The latest version is available at … … 10 10 11 11 Created 1.12.2002 by Walter Zorn (Web: http://www.walterzorn.com ) 12 Last modified: 1 3.6.200812 Last modified: 1.8.2008 13 13 14 14 Easy-to-use cross-browser tooltips. 15 15 Just include the script at the beginning of the <body> section, and invoke 16 Tip('Tooltip text') to show and UnTip() to hide the tooltip, from the desired 16 Tip('Tooltip text') to show and UnTip() to hide the tooltip, from the desired 17 17 HTML eventhandlers. Example: 18 18 <a onmouseover="Tip('Some text')" onmouseout="UnTip()" href="index.htm">My home page</a> … … 74 74 config. FadeOut = 0 75 75 config. FadeInterval = 30 // Duration of each fade step in ms (recommended: 30) - shorter is smoother but causes more CPU-load 76 config. Fix = null // Fixated position - x- an y-oordinates in brackets, e.g. [210, 480], or null for no fixation76 config. Fix = null // Fixated position, two modes. Mode 1: x- an y-coordinates in brackets, e.g. [210, 480]. Mode 2: Show tooltip at a position related to an HTML element: [ID of HTML element, x-offset, y-offset from HTML element], e.g. ['SomeID', 10, 30]. Value null (default) for no fixated positioning. 77 77 config. FollowMouse = true // false or true - tooltip follows the mouse 78 78 config. FontColor = '#000044' … … 135 135 tt_aV = new Array(), // Caches and enumerates config data for currently active tooltip 136 136 tt_sContent, // Inner tooltip text or HTML 137 tt_t2t, tt_t2tDad, // Tag converted to tip, and its DOM parent element 137 138 tt_scrlX = 0, tt_scrlY = 0, 138 139 tt_musX, tt_musY, … … 205 206 tt_RemEvtFnc(document, "mouseup", tt_OnLClick); 206 207 tt_ExtCallFncs(0, "Kill"); 207 // In case of a TagToTip t ooltip, hide converted DOM node and208 // re-insert it into document208 // In case of a TagToTip tip, hide converted DOM node and 209 // re-insert it into DOM 209 210 if(tt_t2t && !tt_aV[COPYCONTENT]) 210 { 211 tt_t2t.style.display = "none"; 212 tt_MovDomNode(tt_t2t, tt_aElt[6], tt_t2tDad); 213 } 211 tt_UnEl2Tip(); 214 212 tt_iState = 0; 215 213 tt_over = null; … … 243 241 function tt_GetClientW() 244 242 { 245 return(document.body && (typeof(document.body.clientWidth) != tt_u) ? document.body.clientWidth 246 : (typeof(window.innerWidth) != tt_u) ? window.innerWidth 247 : tt_db ? (tt_db.clientWidth || 0) 248 : 0); 243 var de = document.documentElement; 244 return((de && de.clientWidth) ? de.clientWidth : (document.body.clientWidth || window.innerWidth || 0)); 249 245 } 250 246 function tt_GetClientH() 251 247 { 252 // Exactly this order seems to yield correct values in all major browsers 253 return(document.body && (typeof(document.body.clientHeight) != tt_u) ? document.body.clientHeight 254 : (typeof(window.innerHeight) != tt_u) ? window.innerHeight 255 : tt_db ? (tt_db.clientHeight || 0) 256 : 0); 248 var de = document.documentElement; 249 return((de && de.clientHeight) ? de.clientHeight : (document.body.clientHeight || window.innerHeight || 0)); 257 250 } 258 251 function tt_GetEvtX(e) … … 283 276 el.detachEvent("on" + sEvt, PFnc); 284 277 } 278 } 279 function tt_GetDad(el) 280 { 281 return(el.parentNode || el.parentElement || el.offsetParent); 282 } 283 function tt_MovDomNode(el, dadFrom, dadTo) 284 { 285 if(dadFrom) 286 dadFrom.removeChild(el); 287 if(dadTo) 288 dadTo.appendChild(el); 285 289 } 286 290 … … 296 300 tt_opa, // Currently applied opacity 297 301 tt_bJmpVert, tt_bJmpHorz,// Tip temporarily on other side of mouse 298 tt_t2t, tt_t2tDad, // Tag converted to tip, and its parent element in the document299 302 tt_elDeHref, // The tag from which we've removed the href attribute 300 303 // Timer … … 311 314 if(!tt_Browser() || !tt_MkMainDiv()) 312 315 return; 313 // Levy 06/11/2008: Important! IE doesn't fire an onscroll when a page 316 // Levy 06/11/2008: Important! IE doesn't fire an onscroll when a page 314 317 // refresh is made, so we need to recalc page positions on init. 315 318 tt_OnScrl(); … … 670 673 // Convert DOM node to tip 671 674 if(tt_t2t && !tt_aV[COPYCONTENT]) 672 { 673 // Store the tag's parent element so we can restore that DOM branch 674 // once the tooltip is hidden 675 tt_t2tDad = tt_t2t.parentNode || tt_t2t.parentElement || tt_t2t.offsetParent || null; 676 if(tt_t2tDad) 677 { 678 tt_MovDomNode(tt_t2t, tt_t2tDad, tt_aElt[6]); 679 tt_t2t.style.display = "block"; 680 } 681 } 675 tt_El2Tip(); 682 676 tt_ExtCallFncs(0, "SubDivsCreated"); 683 677 } … … 693 687 var css, w, h, pad = tt_aV[PADDING], padT, wBrd = tt_aV[BORDERWIDTH], 694 688 iOffY, iOffSh, iAdd = (pad + wBrd) << 1; 695 689 696 690 //--------- Title DIV ---------- 697 691 if(tt_aV[TITLE].length) … … 770 764 css.fontSize = tt_aV[FONTSIZE]; 771 765 css.fontWeight = tt_aV[FONTWEIGHT]; 772 css.background = "";773 766 css.textAlign = tt_aV[TEXTALIGN]; 774 767 if(tt_aV[WIDTH] > 0) … … 887 880 while(el) 888 881 { 889 if(el.hasAttribute ("href"))882 if(el.hasAttribute && el.hasAttribute("href")) 890 883 { 891 884 el.t_href = el.getAttribute("href"); … … 898 891 break; 899 892 } 900 el = el.parentElement;893 el = tt_GetDad(el); 901 894 } 902 895 } … … 910 903 tt_elDeHref = null; 911 904 } 905 } 906 function tt_El2Tip() 907 { 908 var css = tt_t2t.style; 909 910 // Store previous positioning 911 tt_t2t.t_cp = css.position; 912 tt_t2t.t_cl = css.left; 913 tt_t2t.t_ct = css.top; 914 tt_t2t.t_cd = css.display; 915 // Store the tag's parent element so we can restore that DOM branch 916 // when the tooltip is being hidden 917 tt_t2tDad = tt_GetDad(tt_t2t); 918 tt_MovDomNode(tt_t2t, tt_t2tDad, tt_aElt[6]); 919 css.display = "block"; 920 css.position = "static"; 921 css.left = css.top = css.marginLeft = css.marginTop = "0px"; 922 } 923 function tt_UnEl2Tip() 924 { 925 // Restore positioning and display 926 var css = tt_t2t.style; 927 928 css.display = tt_t2t.t_cd; 929 tt_MovDomNode(tt_t2t, tt_GetDad(tt_t2t), tt_t2tDad); 930 css.position = tt_t2t.t_cp; 931 css.left = tt_t2t.t_cl; 932 css.top = tt_t2t.t_ct; 933 tt_t2tDad = null; 912 934 } 913 935 function tt_OverInit() … … 978 1000 if(tt_aV[FIX]) 979 1001 { 980 var iY = tt_aV[FIX][1];981 // For a fixed tip to be positioned above the mouse, use the982 // bottom edge as anchor983 // (recommended by Christophe Rebeschini, 31.1.2008)984 if(tt_aV[ABOVE])985 iY -= tt_h;986 1002 tt_iState &= ~0x4; 987 tt_ SetTipPos(tt_aV[FIX][0], tt_aV[FIX][1]);1003 tt_PosFix(); 988 1004 } 989 1005 else if(!tt_ExtCallFncs(e, "MoveBefore")) … … 994 1010 function tt_Pos(iDim) 995 1011 { 996 var iX, bJmpMod e, cmdAlt, cmdOff, cx, iMax, iScrl, iMus, bJmp;1012 var iX, bJmpMod, cmdAlt, cmdOff, cx, iMax, iScrl, iMus, bJmp; 997 1013 998 1014 // Map values according to dimension to calculate 999 1015 if(iDim) 1000 1016 { 1001 bJmpMod e= tt_aV[JUMPVERT];1017 bJmpMod = tt_aV[JUMPVERT]; 1002 1018 cmdAlt = ABOVE; 1003 1019 cmdOff = OFFSETY; … … 1010 1026 else 1011 1027 { 1012 bJmpMod e= tt_aV[JUMPHORZ];1028 bJmpMod = tt_aV[JUMPHORZ]; 1013 1029 cmdAlt = LEFT; 1014 1030 cmdOff = OFFSETX; … … 1019 1035 bJmp = tt_bJmpHorz; 1020 1036 } 1021 if(bJmpMod e)1037 if(bJmpMod) 1022 1038 { 1023 1039 if(tt_aV[cmdAlt] && (!bJmp || tt_CalcPosAlt(iDim) >= iScrl + 16)) … … 1038 1054 // Prevent tip from extending past clientarea boundary 1039 1055 if(iX > iMax) 1040 iX = bJmpMod e? tt_PosAlt(iDim) : iMax;1056 iX = bJmpMod ? tt_PosAlt(iDim) : iMax; 1041 1057 // In case of insufficient space on both sides, ensure the left/upper part 1042 1058 // of the tip be visible 1043 1059 if(iX < iScrl) 1044 iX = bJmpMod e? tt_PosDef(iDim) : iScrl;1060 iX = bJmpMod ? tt_PosDef(iDim) : iScrl; 1045 1061 return iX; 1046 1062 } … … 1073 1089 return((iDim ? (tt_musY - tt_h) : (tt_musX - tt_w)) - dx); 1074 1090 } 1091 function tt_PosFix() 1092 { 1093 var iX, iY; 1094 1095 if(typeof(tt_aV[FIX][0]) == "number") 1096 { 1097 iX = tt_aV[FIX][0]; 1098 iY = tt_aV[FIX][1]; 1099 } 1100 else 1101 { 1102 if(typeof(tt_aV[FIX][0]) == "string") 1103 el = tt_GetElt(tt_aV[FIX][0]); 1104 // First slot in array is direct reference to HTML element 1105 else 1106 el = tt_aV[FIX][0]; 1107 iX = tt_aV[FIX][1]; 1108 iY = tt_aV[FIX][2]; 1109 // By default, vert pos is related to bottom edge of HTML element 1110 if(!tt_aV[ABOVE] && el) 1111 iY += tt_GetDivH(el); 1112 for(; el; el = el.offsetParent) 1113 { 1114 iX += el.offsetLeft || 0; 1115 iY += el.offsetTop || 0; 1116 } 1117 } 1118 // For a fixed tip positioned above the mouse, use the bottom edge as anchor 1119 // (recommended by Christophe Rebeschini, 31.1.2008) 1120 if(tt_aV[ABOVE]) 1121 iY -= tt_h; 1122 tt_SetTipPos(iX, iY); 1123 } 1075 1124 function tt_Fade(a, now, z, n) 1076 1125 { … … 1081 1130 now = z; 1082 1131 else 1083 tt_tFade.Timer("tt_Fade(" 1084 + a + "," + now + "," + z + "," + (n - 1) 1085 + ")", 1086 tt_aV[FADEINTERVAL], 1087 true); 1132 tt_tFade.Timer( 1133 "tt_Fade(" 1134 + a + "," + now + "," + z + "," + (n - 1) 1135 + ")", 1136 tt_aV[FADEINTERVAL], 1137 true 1138 ); 1088 1139 } 1089 1140 now ? tt_SetTipOpa(now) : tt_Hide(); … … 1197 1248 } 1198 1249 } 1199 function tt_MovDomNode(el, dadFrom, dadTo)1200 {1201 if(dadFrom)1202 dadFrom.removeChild(el);1203 if(dadTo)1204 dadTo.appendChild(el);1205 }1206 1250 function tt_Err(sErr, bIfDebug) 1207 1251 {
