Mercurial > hg > index.fcgi > www > www-1
comparison life_calendar/tooltip.js @ 81:256b8df1c686
add life_calendar
author | paulo |
---|---|
date | Fri, 17 Jun 2016 22:24:17 -0700 |
parents | |
children | a0fdf2cf1d53 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4b88785d1ddd |
---|---|
1 // Based on http://matthias-schuetz.js.org/tooltip.js/ | |
2 | |
3 var _tt_options = { | |
4 tooltipId: "tooltip", | |
5 offsetDefault: 15 | |
6 }; | |
7 | |
8 function getTooltipElm() { | |
9 return document.querySelector("#" + _tt_options.tooltipId); | |
10 } | |
11 | |
12 function adjustTooltip(evt, tooltipElm, title, text) { | |
13 var offset = _tt_options.offsetDefault; | |
14 var scrollY = window.scrollY || window.pageYOffset; | |
15 var scrollX = window.scrollX || window.pageXOffset; | |
16 var tooltipTop = evt.pageY + offset; | |
17 var tooltipLeft = evt.pageX + offset; | |
18 | |
19 tooltipTop = (tooltipTop - scrollY + tooltipElm.offsetHeight + 20 >= window.innerHeight ? (tooltipTop - tooltipElm.offsetHeight - 20) : tooltipTop); | |
20 tooltipLeft = (tooltipLeft - scrollX + tooltipElm.offsetWidth + 20 >= window.innerWidth ? (tooltipLeft - tooltipElm.offsetWidth - 20) : tooltipLeft); | |
21 | |
22 tooltipElm.style.top = tooltipTop + "px"; | |
23 tooltipElm.style.left = tooltipLeft + "px"; | |
24 | |
25 setTooltipText(tooltipElm, title, text); | |
26 } | |
27 | |
28 function removeTooltip() { | |
29 document.querySelector("body").removeChild(getTooltipElm()); | |
30 } | |
31 | |
32 function createTooltip(evt, title, text) { | |
33 var tooltipElm = getTooltipElm(); | |
34 | |
35 if (!tooltipElm) { | |
36 tooltipElm = document.createElement("div"); | |
37 tooltipElm.appendChild(document.createElement("h1")); | |
38 tooltipElm.appendChild(document.createElement("h2")); | |
39 | |
40 tooltipElm.style.position = "absolute"; | |
41 tooltipElm.setAttribute("id", _tt_options.tooltipId); | |
42 | |
43 document.querySelector("body").appendChild(tooltipElm); | |
44 } | |
45 | |
46 adjustTooltip(evt, tooltipElm, title, text); | |
47 } | |
48 | |
49 function setTooltipText(tooltipElm, title, text) { | |
50 var eTitle = tooltipElm.children[0]; | |
51 var eText = tooltipElm.children[1]; | |
52 if (eTitle && title) { | |
53 eTitle.textContent = title; | |
54 } | |
55 if (eText && text) { | |
56 eText.textContent = text; | |
57 } | |
58 } |