view life_calendar/tooltip.js @ 138:3bc6b79919dc

myrss2: FEEDS: Add Rest Of World; update Quillete; remove old feeds
author paulo
date Thu, 23 Mar 2023 07:52:22 +0000
parents 256b8df1c686
children
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, subtext) {
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, subtext);
26 }
28 function removeTooltip() {
29 document.querySelector("body").removeChild(getTooltipElm());
30 }
32 function createTooltip(evt, title, text, subtext) {
33 var tooltipElm = getTooltipElm();
35 if (!tooltipElm) {
36 tooltipElm = document.createElement("div");
37 tooltipElm.appendChild(document.createElement("h1"));
38 tooltipElm.appendChild(document.createElement("h2"));
39 tooltipElm.appendChild(document.createElement("h3"));
41 tooltipElm.style.position = "absolute"; tooltipElm.setAttribute("id", _tt_options.tooltipId);
43 document.querySelector("body").appendChild(tooltipElm);
44 }
46 adjustTooltip(evt, tooltipElm, title, text, subtext);
47 }
49 function setTooltipText(tooltipElm, title, text, subtext) {
50 var eTitle = tooltipElm.children[0];
51 var eText = tooltipElm.children[1];
52 var eSubText = tooltipElm.children[2];
53 if (eTitle && title) {
54 eTitle.textContent = title;
55 }
56 if (eText && text) {
57 eText.textContent = text;
58 }
59 if (eSubText) {
60 eSubText.textContent = subtext;
61 }
62 }