/** * * Some generic tooltip functionality... * */ // BUGFIX: #10 // TODO: clean up the code please! var Utils = Utils || {}; Utils.Tooltip = function(text,color,width,duration){ if (this instanceof Array) { var self = t(this[0]); var evt = this[0]; var tgt = this[1]; var lockout = true; } else { var self = t(this); var evt = this; var tgt = document.body; var lockout = false; } if (!text) return; var sett = Utils.Tooltip.params; if (sett.tooltip_caller) { sett.tooltip_caller.className = (' ' + sett.tooltip_caller.className + ' ').replace(' tooltip_caller ', ''); if (sett.timer) clearTimeout(sett.timer); } sett.tooltip_caller = tgt || self; sett.tooltip_caller.className +=' tooltip_caller'; var color = color || 'fff'; var width = width || 'auto'; var duration = duration || 0; color = '#'+color.replace(/#+/,''); duration *= 1000; if (!isNaN(width)) width += 'px'; //clog(self,arguments,Utils.Tooltip.params); sett.tooltip_obj.innerHTML = text; sett.tooltip_obj.style.width = width; var ewidth = sett.tooltip_obj.offsetWidth;//_gcs(self,'width').replace(/[^\d]+$/g,''); var eheight = sett.tooltip_obj.offsetHeight; //_gcs(set.tooltip_obj,'height').replace(/[^\d]+$/g,''); sett.ewidth = ewidth; sett.eheight = eheight; //sett.etop = _getTop(self); //sett.eleft = _getLeft(self); _css(sett.tooltip_obj,{ 'background-color' : color, //'top' : (sett.etop*1-eheight*1-sett.offset_y*1)+'px', // Hovered Element Top - Tooltip Height - Offset //'left' : (sett.eleft*1+sett.offset_x*1)+'px', // Hovered Element Right + Offset 'visibility' : 'visible' }); Utils.Tooltip.params.move(evt); //tooltip_mover var stoper = function(e){ //if (t(e)!=sett.tooltip_caller) return true; // Prevent the mouseover on element, set event on parent with mouseover, sett.tooltip_caller.className = (' '+sett.tooltip_caller.className+' ').replace(' tooltip_caller ','').trim(); _css(sett.tooltip_obj,{ top : '-1000px', left : '-1000px', visibility : 'hidden' }); uset_evt(sett.tooltip_caller,'mouseover',stopEvt); uset_evt(sett.tooltip_obj,'mouseover',stopEvt); uset_evt(document.body,'mouseover',stoper); } if (duration) { sett.timer = setTimeout(stoper, duration); } else { if (!lockout) return; set_evt(document.body,'mouseover',stoper); // NISHTYAK ;) set_evt(sett.tooltip_caller,'mouseover',stopEvt); set_evt(sett.tooltip_obj,'mouseover',stopEvt); } } //mm_init = function(){} $.ready(function tooltip_init(){ if (isIE){ var real_body = (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body var page_getX = function(e){ return event.x+real_body.scrollLeft; } var page_getY = function(e){ return event.y+real_body.scrollTop; } } else { var real_body = document.body; var page_getX = function(e){ return e.pageX; } var page_getY = function(e){ return e.pageY; } } var tooltip_mover = function(e){ //if (!Utils.Tooltip.params.tooltip_obj.tagName) return true; Utils.Tooltip.params.move_evt = e; var ct = t(e); var pn = false; while (ct.parentNode){ //clog(ct.className); if (/ tooltip_caller /.test(' '+ct.className+' ')) var pn = ct; var ct = ct.parentNode; } if (!pn) return true; if (Utils.Tooltip.params.tooltip_obj.style.visibility!='visible') return false; var xa=0,ya=0; if (isIE && Utils.Tooltip.params.tooltip_caller.style.position=='relative'){ // Add element width xa = _getLeft(pn);//Utils.Tooltip.params.eleft;//-20; ya = _getTop(pn);//Utils.Tooltip.params.etop;//+40; } //clog('move',ct,pn); //d('navigator').innerHTML= (['Y: '+(Utils.Tooltip.params.getY(e)+ya-Utils.Tooltip.params.eheight),'X: '+(Utils.Tooltip.params.getX(e)+xa),'RL:'+real_body.scrollLeft, 'RT:'+real_body.scrollTop].join(', ')); var top_point = Utils.Tooltip.params.getY(e)*1+ya*1-Utils.Tooltip.params.offset_y*1-Utils.Tooltip.params.eheight; var left_point = Utils.Tooltip.params.getX(e)*1+xa*1+Utils.Tooltip.params.offset_x*1; var rightedge= Utils.Tooltip.params.body_el.clientWidth - left_point; //var bottomedge=Utils.Tooltip.params.body_el.clientHeight - window.scrollY- top_point; //console.log(window.scrollY,top_point,bottomedge); if (rightedge top_point){ top_point = Utils.Tooltip.params.getY(e) + Utils.Tooltip.params.offset_y; } _css(Utils.Tooltip.params.tooltip_obj,{ 'position' :'absolute', 'z-index' :'2000', 'top' : top_point+'px', // MouseY - Offset - Tooltip Height 'left' : left_point+'px' // MouseX + Offset }); }; Utils.Tooltip.params = { offset_x: 10, offset_y: 8, enable: false, tooltip_obj: d('dhtmltooltip'), body_el: real_body, getX: page_getX, getY: page_getY, move: tooltip_mover, move_evt: false }; set_evt(real_body,'mousemove',Utils.Tooltip.params.move); }); function positiontip(e){return} function ddrivetip(thetext, thecolor, thewidth){ Utils.Tooltip.call(Utils.Tooltip.params.move_evt, thetext, thecolor, thewidth, 0); } function hideddrivetip(){ _css(Utils.Tooltip.params.tooltip_obj,{ top : '-1000px', left : '-1000px', visibility : 'hidden' }); } /*********************************************** * Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code ***********************************************/ /* var offsetxpoint=10 //Customize x offset of tooltip var offsetypoint=8 //Customize y offset of tooltip var ie=document.all var ns6=document.getElementById && !document.all var enabletip=false if (ie||ns6) var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" function ietruebody(){ return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body } function ddrivetip(thetext, thecolor, thewidth){ if (ns6||ie){ if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor tipobj.innerHTML=thetext enabletip=true positiontip return false } } function positiontip(ett){ if (enabletip){ var curX=(ns6)?ett.pageX : event.x+ietruebody().scrollLeft; var curY=(ns6)?ett.pageY : event.y+ietruebody().scrollTop; //Find out how close the mouse is to the corner of the window var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-ett.clientX-offsetxpoint-20 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-ett.clientY-offsetypoint-20 var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000 //alert('x=' + curX + ' ofw=' + tipobj.offsetWidth); //if the horizontal distance isn't enough to accomodate the width of the context menu if (rightedge