a865217f700dd91e9366c8c83f645f0b9da4f804
[jalview.git] / examples / testdata / phyre2results / 56da5616b4559c93 / css / skinnytip.js
1 /////////////////////////////////////////////////////////////////////
2 //SkinnyTip 2.00 - Elliott Brueggeman - April 19, 2007
3 //JavaScript Popup Tooltip Library 
4 //Project Homepage: http://www.ebrueggeman.com/skinnytip
5 //Documentation available on project homepage
6 ////////////////////////////////////////////////////////////////////
7 //Rights: Free for personal use and corporate use if sites
8 //include a link to the project homepage
9 //////////////////////////////////////////////////////////////////////
10
11
12 //Call mouse capture handler function on page load
13 captureMouse();
14
15 //CUSTOM VARS - Initialized below
16 var v_divname;
17 var v_text;
18 var v_title;
19 var v_xoffset;
20 var v_yoffset;
21 var v_backcolor;
22 var v_bordercolor;
23 var v_textcolor;
24 var v_titletextcolor;
25 var v_width;
26 var v_border;
27 var v_title_padding;
28 var v_content_padding;
29 var v_fontface;
30 var v_fontsize;
31 var v_titlefontsize;
32
33 //INTERNAL VARIABLES
34 var v_xcoordinate = 0;
35 var v_ycoordinate = 0;
36 var v_visible = 0;
37 var v_havemouse = 0;
38 var v_layer = null;
39
40 function tooltip(displaytext, title, commands) {
41         //Reset variables for this tool tip
42         init_tooltip();
43         
44         //Title and Text
45         v_title=title;
46         v_text=displaytext;
47         
48         //Parse commands if any
49         parseCommands(commands);
50         
51         
52         if (v_layer) { 
53                 v_layer=getLayer(v_divname); 
54         }
55         
56         if (!(v_layer=createDivContainer())) { 
57                 return false;
58         }
59
60         mainMethod();
61 }
62
63 function init_tooltip() {
64         
65         v_divname = 'tiplayer';
66         v_text = 'Default Text';
67         v_title = '';
68         
69         //UI Variables
70         v_xoffset = 15;
71         v_yoffset = 15;
72         v_backcolor = '#f6f5ee';
73         v_bordercolor = '#88344b';
74         v_textcolor = '#000000';
75         v_titletextcolor = '#000000';
76         v_width = 300;
77         
78         v_border = 2;
79         v_title_padding = '1px';
80         v_content_padding = '1px 3px';
81         
82         v_fontface = 'Arial, Helvetica, Sans-Serif';
83         v_fontsize = 14;
84         v_titlefontsize = 14;
85         
86         //SYSTEM VARIABLES
87         v_visible = 0;
88         v_layer = null;
89 }
90
91 function parseCommands(commands) {
92         if (commands != null) {
93                 var comArray = commands.split(',');
94                 for (var i = 0; i < comArray.length; i++) {
95                         var args = comArray[i].split(':');
96                         eval('v_' + trimWhitespace(args[0]) + '="' + trimWhitespace(args[1]) + '"');
97                 }
98         }
99 }
100
101 // Clears popups if appropriate
102 function hideTip() {
103         if (v_visible == 1) {
104                 if (v_layer != null) {
105                         v_layer.style.visibility = 'hidden';
106                         v_visible = 0;
107                 }
108         }
109         return true;
110 }
111
112 function mainMethod() { 
113         v_visible = 0;
114         
115         var html = makeHTML(v_text, v_title);   
116         createPopup(html);
117         
118         //if we have mouse coordinates, position layer and make visible
119         if (v_havemouse == 1) { 
120                 positionLayer();
121                 v_visible = 1;
122                 v_layer.style.visibility = 'visible';
123         }
124 }
125
126 function makeHTML(text, title) {
127         
128         var container_style = 'width:' + v_width + 'px;';
129         container_style += 'border:' + v_border + 'px solid ' + v_bordercolor + ';';
130         container_style += 'background-color:' + v_backcolor + ';';
131         container_style += 'font-family:' + v_fontface + ';';
132         container_style += 'font-size:' + v_fontsize + 'px;';
133         
134         var title_style = 'background-color:' + v_bordercolor + ';';
135         title_style += 'padding:' + v_title_padding + ';';
136         title_style += 'color:' + v_titletextcolor + ';';
137         
138         var content_style = 'padding:' + v_content_padding + ';';
139         content_style += 'color:' + v_textcolor + ';';
140         
141         var txt = '<div id="skinnytip_container" style="' + container_style + '">';
142         if (title!=null && title.length>0) {
143                 txt += '<div id="skinnytip_title" style="' + title_style + '">' + title + '</div>';
144         }
145         txt += '<div id="skinnytip_content" style="' + content_style + '">' + text + '</div>';
146         txt += '</div>';
147         
148         return txt;
149 }
150
151 //Positions popup according to mouse input
152 function positionLayer() {
153         
154         var placeX = 300;
155         var placeY = 300;
156         
157         //get final placement
158         placeX = horizontalPlacement();
159         placeY = verticalPlacement();
160         
161         //Move the object
162         v_layer.style.left = placeX + 'px';
163         v_layer.style.top = placeY + 'px';
164 }
165
166 //called when the mouse moves
167 //sets mouse related variables
168 function mouseMoveHandler(e) {
169         if (!e) {
170                 e = event;
171         }
172         if (e.clientX) {
173          //if there is an x pos property
174          //GET MOUSE LOCATION
175                 v_xcoordinate = mouseX(e);
176                 v_ycoordinate = mouseY(e);      
177                 v_havemouse = 1;
178         }
179         if (v_visible == 1) { 
180                 positionLayer();        
181         }
182 }
183
184 //get mouse x coordinate
185 function mouseX(evt) {
186         if (evt.pageX) return evt.pageX;
187         else if (evt.clientX) {
188            return evt.clientX + (document.documentElement.scrollLeft ?
189            document.documentElement.scrollLeft :
190            document.body.scrollLeft);
191         }
192         else {
193                 return null;
194         }
195 }
196
197 //get mouse y coordinate
198 function mouseY(evt) {
199         if (evt.pageY) { 
200                 return evt.pageY; 
201         }
202         else if (evt.clientY) {
203            return evt.clientY + (document.documentElement.scrollTop ?
204            document.documentElement.scrollTop :
205            document.body.scrollTop);
206         }
207         else { 
208                 return null;
209         }
210 }
211
212 //Set mouse handler
213 function captureMouse() {
214         document.onmousemove = mouseMoveHandler;
215 }
216
217 //Creates the popup
218 function createPopup(input) {
219
220         var popupwidth = v_width;
221         var text;
222         var zindex;
223         
224         text =  createBackLayer(popupwidth,zindex++);
225         text += '<div style="position: absolute; top: 0; left: 0; width: ' + popupwidth + 'px; z-index: ' + zindex + ';">' + input + '</div>';
226         
227         if (typeof v_layer.innerHTML != 'undefined') {
228                 v_layer.innerHTML = text;
229         } 
230         
231         //After writing html measure height of backlayer to set height of iframe
232         var backlayer=self.document.getElementById("backdrop");
233         var container=self.document.getElementById("skinnytip_container");
234         backlayer.height = container.offsetHeight;
235 }
236
237 //Back layer prevents forms from showing through popups
238 function createBackLayer(width, Z) {
239         //Create backdrop with 0 height
240         return '<iframe id="backdrop" frameborder="0" scrolling="no" width="' + width + '" height="0" style="z-index: ' + Z + '; filter: Beta(Style=0,Opacity=0);"><p></iframe>';
241 }
242
243 //get horizontal box placement
244 function horizontalPlacement() {
245         placeX = v_xcoordinate + v_xoffset;
246         return placeX;
247 }
248
249 //get vertical box placement
250 function verticalPlacement() {
251         return v_ycoordinate + v_yoffset;
252 }
253
254 // create the div container for popup content if it doesn't exist
255 function createDivContainer() {
256         var divContainer = self.document.getElementById(v_divname);
257         return divContainer;
258 }
259
260 function trimWhitespace(str) {  
261         while(str.charAt(0) == (" ") ) {  
262                 str = str.substring(1);
263         }
264         while(str.charAt(str.length-1) == " " ) {  
265                 str = str.substring(0,str.length-1);
266         }
267         return str;
268 }