- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.html
More file actions
Latest commit
179 lines (140 loc) · 5.31 KB
/
Copy pathjavascript.html
File metadata and controls
179 lines (140 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<script>
functionfocus(ttPosition,ttType,ttText,ttRect,divid,halfoffsetwidth)
{
if(ttPosition=="bottom"||ttPosition=="top"||ttPosition=="left"||ttPosition=="right")
{
vartoolTipPosition=ttPosition
vartoolTipType=ttType
vartootTipText=ttText
varrect=ttRect
vardivId=divid
varhalfOffsetWidth=halfoffsetwidth
}
try{varatr=this.getAttribute("data-tooltipposition")}
catch(e){varatr=null}
if(atr)
{
this.style.backgroundColor="rgba(0, 0, 0, .1)";
vartoolTipPosition=this.getAttribute("data-tooltipposition");
vartoolTipType=this.getAttribute("data-tooltiptype");
vartootTipText=this.getAttribute("data-toolTipText");
varrect=this.getBoundingClientRect();
vardivId=this.id+"tt";
varhalfOffsetWidth=this.offsetWidth/2;
}
// help for positioning
//console.log(rect.top + " " + rect.right+ " " + rect.bottom+ " " + rect.left);
// The lenght of our tooltip to put it in the middle of
// the div it is refering to. Create a dummy first
vartempDiv=document.createElement('div');
document.body.appendChild(tempDiv);
tempDiv.style.fontSize="10px";// this should be the same as your style
tempDiv.style.position="absolute";
tempDiv.style.left=-1000;
tempDiv.style.top=-1000;
tempDiv.innerHTML=tootTipText;
varwidth=(tempDiv.clientWidth+22);// add margins
varheight=(tempDiv.clientHeight+12);// add margins
document.body.removeChild(tempDiv);
tempDiv=null;
vardiv=document.createElement('div');
div.id=divId
div.style.position="absolute";
varclassName="";
/* where to place the tooltip */
if(toolTipPosition=="top")
{
className=className+"tooltip_top";
vartop=rect.top-height-(height/2)
varleft=rect.left+halfOffsetWidth*1-(width/2)
div.style.top=top+"px";
div.style.left=left+"px";
}
if(toolTipPosition=="left")
{
className=className+"tooltip_left";
vartop=rect.top-(height/2)
varleft=rect.left-width-(20)
div.style.top=top+"px";
div.style.left=left+"px";
}
if(toolTipPosition=="right")
{
className=className+"tooltip_right";
vartop=rect.top-(height/2)
varleft=rect.right+6
div.style.top=top+"px";
div.style.left=left+"px";
}
if(toolTipPosition=="bottom")
{
className=className+"tooltip_bottom";
varleft=rect.left+halfOffsetWidth*1-(width/2)
// dont need top the margin itselve will do.
div.style.top=rect.bottom+"px";
div.style.left=left+"px";
}
/* Assign the aspect the tooltip should have */
/* don't remove the space in front of the class */
if(toolTipType=="normal")
{
className=className+" tooltipnormal";//black
}
if(toolTipType=="warning")
{
className=className+" tooltipwarning";//red
}
if(toolTipType=="info")
{
className=className+" tooltipinfo";//blue
}
div.className=className
div.innerHTML=tootTipText;/* add the text to the tooltip */
document.body.appendChild(div);
}
functionnoFocus()
{
this.style.backgroundColor="transparent";
document.getElementById(this.id+"tt").parentNode.removeChild(document.getElementById(this.id+"tt"))
}
functionbindTooltip()
{
vartoolTipPosition=this.getAttribute("data-tooltipposition")
vartoolTipType=this.getAttribute("data-tooltiptype")
varrect=this.getBoundingClientRect()
vardivid=this.id+"tt"
varhalfOffSetWith=this.offsetWidth/2
google.script.run.withSuccessHandler(tooltipJS)
.withFailureHandler(showError)
.tooltipGS(toolTipPosition,toolTipType,rect,divid,halfOffSetWith);
}
functiontooltipJS(toolTipArray)
{
vartoolTipPosition=toolTipArray[0]
vartoolTipType=toolTipArray[1]
vartootTipText=toolTipArray[2]
varrect=toolTipArray[3]
vardivid=toolTipArray[4]
varhalfoffsetwidth=toolTipArray[5]
focus(toolTipPosition,toolTipType,tootTipText,rect,divid,halfoffsetwidth)
}
/* bind the elements mouseover event to the focus function */
document.getElementById("title").addEventListener('mouseover',focus,false);
document.getElementById("wtop").addEventListener('mouseover',focus,false);
document.getElementById("wleft").addEventListener('mouseover',focus,false);
document.getElementById("wright").addEventListener('mouseover',focus,false);
document.getElementById("wbottom").addEventListener('mouseover',focus,false);
document.getElementById("testgs").addEventListener('mouseover',bindTooltip,false);
/* bind the elements mouseout event to the focus function */
document.getElementById("title").addEventListener('mouseout',noFocus,false);
document.getElementById("wright").addEventListener('mouseout',noFocus,false);
document.getElementById("wtop").addEventListener('mouseout',noFocus,false);
document.getElementById("wleft").addEventListener('mouseout',noFocus,false);
document.getElementById("wbottom").addEventListener('mouseout',noFocus,false);
document.getElementById("testgs").addEventListener('mouseout',noFocus,false);
functionshowError(error)
{
console.log(error);
window.alert('An error has occurred, please try again.');
}
</script>