-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
169 lines (165 loc) · 3.88 KB
/
file.js
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
var tipTimer = null;
var tipX = null;
var tipY = null;
var tipHtml = null;
var tipAnchor = null;
function showTip(e, sHtml, bHideSelects, sAnchorType) {
hideTip(e);
// find anchor element
var el = e.target || e.srcElement;
while (el.tagName != sAnchorType)
el = el.parentNode;
// remember attributes
tipX = e.clientX;
tipY = e.clientY;
tipAnchor = el;
tipHtml = sHtml;
tipHandler.hideSelects = Boolean(bHideSelects);
// set timer
tipTimer = setTimeout("showTip2()", 400);
}
function showTip2() {
// is there already a tooltip? If so, remove it
if (tipAnchor._tip)
tipHandler.hideTip(tipAnchor);
// create element and insert last into the body
tipHandler.createTip(tipAnchor, tipHtml);
// position tooltip
tipHandler.positionToolTip(tipX, tipY);
// add a listener to the blur event.
// When blurred remove tooltip and restore anchor
tipAnchor.onblur = tipHandler.anchorBlur;
tipAnchor.onkeydown = tipHandler.anchorKeyDown;
if ( navigator.userAgent.indexOf('MSIE') < 0 ) // timeout to hide tooltip
tipTimer = setTimeout("tipHandler.hideTip(tipAnchor)", 15000);
}
function hideTip(e) {
if (tipTimer) {
clearTimeout(tipTimer);
tipTimer = null;
}
// find anchor element
var el = e.target || e.srcElement;
tipHandler.hideTip(el);
}
var tipHandler = {
hideSelects: false,
tip: null,
showSelects: function (bVisible) {
if (!this.hideSelects) return;
// only IE actually do something in here
var selects = [];
if (document.all)
selects = document.all.tags("SELECT");
var l = selects.length;
for (var i = 0; i < l; i++)
selects[i].runtimeStyle.visibility = bVisible ? "" : "hidden";
},
create: function () {
var d = document.createElement("DIV");
d.className = "tooltip";
d.onmousedown = this.tipMouseDown;
d.onmouseup = this.tipMouseUp;
document.body.appendChild(d);
this.tip = d;
},
createTip: function (el, sHtml) {
if (this.tip == null) {
this.create();
}
var d = this.tip;
d.innerHTML = sHtml;
d._boundAnchor = el;
el._tip = d;
return d;
},
tipMouseDown: function (e) {
var d = this;
var el = d._boundAnchor;
if (!e) e = event;
var t = e.target || e.srcElement;
while (t.tagName != "A" && t != d)
t = t.parentNode;
if (t == d) return;
el._onblur = el.onblur;
el.onblur = null;
},
tipMouseUp: function () {
var d = this;
var el = d._boundAnchor;
el.onblur = el._onblur;
el._onblur = null;
el.focus();
},
anchorBlur: function (e) {
var el = this;
tipHandler.hideTip(el);
},
anchorKeyDown: function (e) {
if (!e) e = window.event
if (e.keyCode == 27) {
tipHandler.hideTip(this);
}
},
removeTip: function (d) {
d._boundAnchor = null;
d.style.filter = "none";
d.innerHTML = "";
d.onmousedown = null;
d.onmouseup = null;
d.parentNode.removeChild(d);
},
hideTip: function (el) {
var d = el._tip;
if (d != null) {
d.style.visibility = "hidden";
el.onblur = null;
el._onblur = null;
el._tip = null;
el.onkeydown = null;
this.showSelects(true);
}
},
positionToolTip: function (clientX, clientY) {
this.showSelects(false);
var scroll = this.getScroll();
var d = this.tip;
// width
if (d.offsetWidth >= scroll.width)
d.style.width = scroll.width - 10 + "px";
else
d.style.width = "";
// left
if (clientX > scroll.width - d.offsetWidth)
d.style.left = scroll.width - d.offsetWidth + scroll.left + "px";
else
d.style.left = clientX - 2 + scroll.left + "px";
// top
if (clientY + d.offsetHeight + 18 < scroll.height)
d.style.top = clientY + 18 + scroll.top + "px";
else if (clientY - d.offsetHeight > 0)
d.style.top = clientY + scroll.top - d.offsetHeight + "px";
else
d.style.top = scroll.top + 5 + "px";
d.style.visibility = "visible";
},
getScroll: function () {
if (document.all && typeof document.body.scrollTop != "undefined") {
var ieBox = document.compatMode != "CSS1Compat";
var cont = ieBox ? document.body : document.documentElement;
return {
left: cont.scrollLeft,
top: cont.scrollTop,
width: cont.clientWidth,
height: cont.clientHeight
};
} else {
return {
left: window.pageXOffset,
top: window.pageYOffset,
width: window.innerWidth,
height: window.innerHeight
};
}
}
};