-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtooltip.js
83 lines (74 loc) · 1.73 KB
/
tooltip.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
"use strict";
const tooltip =
{
DOM: document.getElementById("idTooltip"),
active: false,
promptPalette: function(id, ifPixel, ifPrev)
{
const ele = (ifPrev) ? "palettePreview" : "paletteContainer";
const off = (ifPrev) ?
[0, -66] :
[id * 48 + 24 - (paletteContainer.scrollLeft / 2) + palette.getBoundingClientRect().x, -50];
if (ifPixel)
{
if (ifPrev)
{
this.prompt(ele, !(cfgDOM.pixelHex.checked) ?
`rgb(${pixel.toRGB(id)})` : "#" + id,
"down", off);
}
else
{
this.prompt(ele, !(cfgDOM.pixelHex.checked) ?
`rgb(${pixel.toRGB(tileset.list[id])})` : "#" + tileset.list[id],
"down", off);
}
}
else
{
this.prompt(ele,
`${tileset.name[id]} (${tileset.list[id]})\n${tileset.define[id]}`,
"down", off);
}
},
hide: function()
{
this.active = false;
this.DOM.classList.add("tooltipHide");
this.DOM.classList.remove("tooltipShow");
},
prompt: function(pos, text, dir, offset)
{
this.active = true;
this.DOM.classList.remove("tooltipHide");
this.DOM.classList.add("tooltipShow");
if (typeof pos !== "object")
{
const rect = window[pos].getBoundingClientRect();
pos = [];
pos[0] = rect.left// + rect.width / 8;
pos[1] = rect.top - rect.height;
}
switch (dir)
{
case "down":
pos[1] -= 2;
break;
}
if (offset !== undefined)
{
pos[0] += offset[0];
pos[1] += offset[1];
}
tooltipT.textContent = text;
pos[0] -= this.DOM.getBoundingClientRect().width / 2;
pos[1] -= this.DOM.getBoundingClientRect().height / 2;
if (pos[0] < 4)
{
pos[0] = 4;
}
this.DOM.style.left = pos[0] + "px";
this.DOM.style.top = pos[1] + 100 + "px"; //change to bottom?
}
};
// lemocha - lemocha7.github.io