Plugin UnivBristol by Frederic Francois
[myslice.git] / plugins / univbristopo / static / js / tooltip.topology.js
1 var tooltip=function(){
2  var id = 'tt';
3  var top = 800; //3
4  var left = 3; //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                    //console.log(tt);
15
16                    if(tt == null){
17                             tt = document.createElement('div');
18                             tt.setAttribute('id',id);
19                             //tt.setAttribute('style',"display: table; display: inline-block;");
20                             t = document.createElement('div');
21                             t.setAttribute('id',id + 'top');
22                             c = document.createElement('div');
23                             c.setAttribute('id',id + 'cont');
24                             b = document.createElement('div');
25                             b.setAttribute('id',id + 'bot');
26                             tt.appendChild(t);
27                             tt.appendChild(c);
28                             tt.appendChild(b);
29                           
30                             //document.body.appendChild(tt);
31                             var objTo = document.getElementById('topo_plugin')
32                             objTo.appendChild(tt);
33                             tt.style.position='absolute';
34                            // tt.style.display='inline-block';
35                             tt.style.opacity = 0;
36                             //tt.style.filter = 'alpha(opacity=0)';
37                             objTo.onmousemove = this.pos;
38                    }//end of if tt==null
39
40                    tt.style.display = 'block';
41                    c.innerHTML = v;
42
43                    //console.log("///////////////tooltip/////////",c);
44                    tt.style.width = w ? w + 'px' : 'auto';
45
46                    if(!w && ie){
47                             t.style.display = 'none';
48                             b.style.display = 'none';
49                             tt.style.width = tt.offsetWidth;
50                             t.style.display = 'block';
51                             b.style.display = 'block';
52                    } //end of if(!w && ie)
53
54                   h=0;
55
56                   if(tt.offsetWidth > maxw){
57                         tt.style.width = maxw + 'px';
58                   }
59
60                    h = parseInt(tt.offsetHeight) + top;
61                    clearInterval(tt.timer);
62                    tt.timer = setInterval(function(){tooltip.fade(1)},timer);
63
64                 //console.log("//////////////h:",h);
65                    
66                   },
67
68
69                   pos:function(e){
70                            //console.log(ie);
71                            //var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
72                            //var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
73                            var u=e.clientY;
74                            var l=e.clientX;
75
76                           // if ((u-h)<0){
77                         //      tt.style.top =0 + 'px';
78                           // }
79                           // else{
80                         //      tt.style.top =(u-h) + 'px';
81                          //  }
82                            tt.style.top = e.clientY +'px';
83                            //console.log("top:",tt.style.top);
84                           // console.log("clientY:",e.clientY);
85                            tt.style.left = (e.clientX-300) + 'px';
86
87                   },
88
89                   fade:function(d){
90                            var a = alpha;
91                            if((a != endalpha && d == 1) || (a != 0 && d == -1)){
92                                    var i = speed;
93                                    if(endalpha - a < speed && d == 1){
94                                         i = endalpha - a;
95                                    }else if(alpha < speed && d == -1){
96                                      i = a;
97                                    }
98                                    alpha = a + (i * d);
99                                    tt.style.opacity = alpha * .01;
100                                    //tt.style.filter = 'alpha(opacity=' + alpha + ')';
101                           }else{
102                                    clearInterval(tt.timer);
103                                    if(d == -1){
104                                         tt.style.display = 'none'
105                                    }
106                           }
107                    },
108
109
110                  hide:function(){
111                    clearInterval(tt.timer);
112                    tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
113                   }
114
115          }; //end of show function
116   }();// end of return
117
118