BlueGit

timfa bluegit

Files

bluegit / internal / server / static / float.js

float.js

fix: zet de clone-knop terug in de werkbalk
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
f0b666cc History
float.js 6.8 KiB Download Raw
1(function () {
2 var GAP = 8;
3 var tracked = [];
4
5 function layer(el) {
6 return el && typeof el.showPopover === "function";
7 }
8
9 function openLayer(el) {
10 if (!el) {
11 return;
12 }
13 if (layer(el)) {
14 if (!el.hasAttribute("popover")) {
15 el.setAttribute("popover", "manual");
16 }
17 if (!el.matches(":popover-open")) {
18 el.showPopover();
19 }
20 return;
21 }
22 if (el.parentNode !== document.body) {
23 el._home = el.parentNode;
24 document.body.appendChild(el);
25 }
26 el.hidden = false;
27 }
28
29 function closeLayer(el) {
30 if (!el) {
31 return;
32 }
33 if (layer(el) && el.hasAttribute("popover")) {
34 if (el.matches(":popover-open")) {
35 el.hidePopover();
36 }
37 return;
38 }
39 el.hidden = true;
40 }
41
42 function isOpen(el) {
43 if (!el) {
44 return false;
45 }
46 if (el.hasAttribute("popover")) {
47 return el.matches(":popover-open");
48 }
49 return !el.hidden;
50 }
51
52 function place(el, anchor, mode) {
53 var rect = anchor.getBoundingClientRect();
54 el.style.left = "0px";
55 el.style.top = "0px";
56 var w = el.offsetWidth;
57 var h = el.offsetHeight;
58 var vw = document.documentElement.clientWidth;
59 var vh = document.documentElement.clientHeight;
60 var left;
61 var top;
62 if (mode === "above-center") {
63 left = rect.left + (rect.width - w) / 2;
64 top = rect.top - GAP - h;
65 if (top < GAP) {
66 top = rect.bottom + GAP;
67 }
68 } else if (mode === "below-end") {
69 left = rect.right - w;
70 top = rect.bottom + GAP;
71 if (top + h > vh - GAP && rect.top - GAP - h >= GAP) {
72 top = rect.top - GAP - h;
73 }
74 } else {
75 left = rect.left;
76 top = rect.bottom + GAP;
77 if (top + h > vh - GAP && rect.top - GAP - h >= GAP) {
78 top = rect.top - GAP - h;
79 }
80 }
81 if (left + w > vw - GAP) {
82 left = vw - GAP - w;
83 }
84 if (left < GAP) {
85 left = GAP;
86 }
87 if (top + h > vh - GAP) {
88 top = Math.max(GAP, vh - GAP - h);
89 }
90 if (top < GAP) {
91 top = GAP;
92 }
93 el.style.left = Math.round(left) + "px";
94 el.style.top = Math.round(top) + "px";
95 }
96
97 function track(el, anchor, mode) {
98 tracked = tracked.filter(function (item) { return item.el !== el; });
99 tracked.push({ el: el, anchor: anchor, mode: mode });
100 place(el, anchor, mode);
101 }
102
103 function untrack(el) {
104 tracked = tracked.filter(function (item) { return item.el !== el; });
105 }
106
107 function reposition() {
108 tracked.forEach(function (item) {
109 if (isOpen(item.el)) {
110 place(item.el, item.anchor, item.mode);
111 }
112 });
113 }
114 window.addEventListener("scroll", reposition, true);
115 window.addEventListener("resize", reposition);
116
117 var tip = document.createElement("div");
118 tip.className = "float-tip";
119 tip.setAttribute("role", "tooltip");
120 tip.setAttribute("popover", "manual");
121 document.body.appendChild(tip);
122 var tipAnchor = null;
123
124 function restoreTitle(el) {
125 if (el && el.hasAttribute("data-native-title")) {
126 el.setAttribute("title", el.getAttribute("data-native-title"));
127 el.removeAttribute("data-native-title");
128 }
129 }
130
131 function hideTip() {
132 restoreTitle(tipAnchor);
133 tipAnchor = null;
134 closeLayer(tip);
135 untrack(tip);
136 }
137
138 function showTip(el) {
139 if (!el || el.closest(".stage-pop, .float-tip")) {
140 return;
141 }
142 var stage = el.closest(".stage");
143 if (stage && stage.classList.contains("open") && el.matches(".stage-dot")) {
144 return;
145 }
146 var text = el.getAttribute("data-tip") || "";
147 if (!text && (el.hasAttribute("title") || el.hasAttribute("data-native-title"))) {
148 text = el.getAttribute("data-native-title") || el.getAttribute("title") || "";
149 if (el.hasAttribute("title")) {
150 el.setAttribute("data-native-title", text);
151 el.removeAttribute("title");
152 }
153 }
154 if (!text) {
155 return;
156 }
157 if (tipAnchor && tipAnchor !== el) {
158 restoreTitle(tipAnchor);
159 }
160 tipAnchor = el;
161 tip.textContent = text;
162 tip.classList.toggle("heat", el.classList.contains("sq"));
163 openLayer(tip);
164 track(tip, el, "above-center");
165 }
166
167 document.addEventListener("pointerover", function (ev) {
168 var el = ev.target.closest("[data-tip], .sq[title], .sq[data-native-title]");
169 if (el) {
170 showTip(el);
171 }
172 });
173 document.addEventListener("pointerout", function (ev) {
174 if (!tipAnchor) {
175 return;
176 }
177 if (ev.target === tipAnchor || tipAnchor.contains(ev.target)) {
178 if (!tipAnchor.contains(ev.relatedTarget)) {
179 hideTip();
180 }
181 }
182 });
183 document.addEventListener("focusin", function (ev) {
184 var el = ev.target.closest("[data-tip], .sq[title], .sq[data-native-title]");
185 if (el) {
186 showTip(el);
187 }
188 });
189 document.addEventListener("focusout", function (ev) {
190 if (tipAnchor && (ev.target === tipAnchor || tipAnchor.contains(ev.target))) {
191 hideTip();
192 }
193 });
194
195 function popOf(stage) {
196 return stage.querySelector(".stage-pop") || stage._pop || null;
197 }
198
199 function closeStages() {
200 document.querySelectorAll(".stage.open").forEach(function (stage) {
201 stage.classList.remove("open");
202 var pop = popOf(stage);
203 closeLayer(pop);
204 untrack(pop);
205 });
206 }
207
208 document.addEventListener("click", function (ev) {
209 var btn = ev.target.closest("button.stage-dot[data-tip]");
210 if (btn) {
211 ev.stopPropagation();
212 var stage = btn.parentElement;
213 var pop = popOf(stage);
214 if (pop) {
215 stage._pop = pop;
216 }
217 var was = stage.classList.contains("open");
218 hideTip();
219 closeStages();
220 if (!was && pop) {
221 stage.classList.add("open");
222 openLayer(pop);
223 track(pop, btn, "below-start");
224 }
225 return;
226 }
227 if (ev.target.closest(".stage-pop")) {
228 return;
229 }
230 closeStages();
231 });
232 document.addEventListener("keydown", function (ev) {
233 if (ev.key === "Escape") {
234 hideTip();
235 closeStages();
236 }
237 });
238
239 document.querySelectorAll("details").forEach(function (det) {
240 var panel = det.querySelector(":scope > .menu-panel, :scope > form");
241 if (!panel) {
242 return;
243 }
244 if (!panel.classList.contains("menu-panel") && !det.classList.contains("showid")) {
245 return;
246 }
247 panel.setAttribute("popover", "manual");
248 det.addEventListener("toggle", function () {
249 var summary = det.querySelector("summary");
250 if (det.open && summary) {
251 // A popover nested in <details> stays display:none in the top layer
252 // until it leaves the details element. Park the panel on body first.
253 if (panel.classList.contains("menu-panel") && panel.parentNode !== document.body) {
254 panel._home = panel.parentNode;
255 document.body.appendChild(panel);
256 }
257 openLayer(panel);
258 track(panel, summary, "below-end");
259 } else {
260 closeLayer(panel);
261 untrack(panel);
262 }
263 });
264 });
265})();