home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / MediaCoder / MediaCoder2011-R8-5188.exe / htdocs / prefs / tooltip.js < prev    next >
Encoding:
JavaScript  |  2011-05-10  |  2.1 KB  |  74 lines

  1. var tooltip=function(){
  2.     var id = 'tt';
  3.     var top = 3;
  4.     var left = 3;
  5.     var maxw = 300;
  6.     var speed = 10;
  7.     var timer = 20;
  8.     var endalpha = 95;
  9.     var alpha = 0;
  10.     var tt,t,c,b,h;
  11.     var ie = document.all ? true : false;
  12.     return{
  13.         show:function(v,w){
  14.             if(tt == null){
  15.                 tt = document.createElement('div');
  16.                 tt.setAttribute('id',id);
  17.                 t = document.createElement('div');
  18.                 t.setAttribute('id',id + 'top');
  19.                 c = document.createElement('div');
  20.                 c.setAttribute('id',id + 'cont');
  21.                 b = document.createElement('div');
  22.                 b.setAttribute('id',id + 'bot');
  23.                 tt.appendChild(t);
  24.                 tt.appendChild(c);
  25.                 tt.appendChild(b);
  26.                 document.body.appendChild(tt);
  27.                 tt.style.opacity = 0;
  28.                 tt.style.filter = 'alpha(opacity=0)';
  29.                 document.onmousemove = this.pos;
  30.             }
  31.             tt.style.display = 'block';
  32.             c.innerHTML = v;
  33.             tt.style.width = w ? w + 'px' : 'auto';
  34.             if(!w && ie){
  35.                 t.style.display = 'none';
  36.                 b.style.display = 'none';
  37.                 tt.style.width = tt.offsetWidth;
  38.                 t.style.display = 'block';
  39.                 b.style.display = 'block';
  40.             }
  41.             if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
  42.             h = parseInt(tt.offsetHeight) + top;
  43.             clearInterval(tt.timer);
  44.             tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  45.         },
  46.         pos:function(e){
  47.             var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
  48.             var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
  49.             tt.style.top = (u - h) + 'px';
  50.             tt.style.left = (l + left) + 'px';
  51.         },
  52.         fade:function(d){
  53.             var a = alpha;
  54.             if((a != endalpha && d == 1) || (a != 0 && d == -1)){
  55.                 var i = speed;
  56.                 if(endalpha - a < speed && d == 1){
  57.                     i = endalpha - a;
  58.                 }else if(alpha < speed && d == -1){
  59.                     i = a;
  60.                 }
  61.                 alpha = a + (i * d);
  62.                 tt.style.opacity = alpha * .01;
  63.                 tt.style.filter = 'alpha(opacity=' + alpha + ')';
  64.             }else{
  65.                 clearInterval(tt.timer);
  66.                 if(d == -1){tt.style.display = 'none'}
  67.             }
  68.         },
  69.         hide:function(){
  70.             clearInterval(tt.timer);
  71.             tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
  72.         }
  73.     };
  74. }();