Mercurial > hg > index.fcgi > www > www-1
view life_calendar/tooltip.js @ 84:03c6971ed023
thule_fit_kits/fitkits_Thule.txt: latest update
author | paulo |
---|---|
date | Sat, 23 Jul 2016 15:25:44 -0600 |
parents | |
children | a0fdf2cf1d53 |
line source
1 // Based on http://matthias-schuetz.js.org/tooltip.js/
3 var _tt_options = {
4 tooltipId: "tooltip",
5 offsetDefault: 15
6 };
8 function getTooltipElm() {
9 return document.querySelector("#" + _tt_options.tooltipId);
10 }
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;
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);
22 tooltipElm.style.top = tooltipTop + "px";
23 tooltipElm.style.left = tooltipLeft + "px";
25 setTooltipText(tooltipElm, title, text);
26 }
28 function removeTooltip() {
29 document.querySelector("body").removeChild(getTooltipElm());
30 }
32 function createTooltip(evt, title, text) {
33 var tooltipElm = getTooltipElm();
35 if (!tooltipElm) {
36 tooltipElm = document.createElement("div");
37 tooltipElm.appendChild(document.createElement("h1"));
38 tooltipElm.appendChild(document.createElement("h2"));
40 tooltipElm.style.position = "absolute";
41 tooltipElm.setAttribute("id", _tt_options.tooltipId);
43 document.querySelector("body").appendChild(tooltipElm);
44 }
46 adjustTooltip(evt, tooltipElm, title, text);
47 }
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 }