BlueGit

timfa bluegit

Files

bluegit / internal / server / static / float.js

float.js

float.js 10.4 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.setAttribute("title", text);
163 tip.classList.toggle("heat", el.classList.contains("sq"));
164 openLayer(tip);
165 track(tip, el, "above-center");
166 }
167
168 document.addEventListener("pointerover", function (ev) {
169 var el = ev.target.closest("[data-tip], .sq[title], .sq[data-native-title]");
170 if (el) {
171 showTip(el);
172 }
173 });
174 document.addEventListener("pointerout", function (ev) {
175 if (!tipAnchor) {
176 return;
177 }
178 if (ev.target === tipAnchor || tipAnchor.contains(ev.target)) {
179 if (!tipAnchor.contains(ev.relatedTarget)) {
180 hideTip();
181 }
182 }
183 });
184 document.addEventListener("focusin", function (ev) {
185 var el = ev.target.closest("[data-tip], .sq[title], .sq[data-native-title]");
186 if (el) {
187 showTip(el);
188 }
189 });
190 document.addEventListener("focusout", function (ev) {
191 if (tipAnchor && (ev.target === tipAnchor || tipAnchor.contains(ev.target))) {
192 hideTip();
193 }
194 });
195
196 function popOf(stage) {
197 return stage.querySelector(".stage-pop") || stage._pop || null;
198 }
199
200 function closeStages() {
201 document.querySelectorAll(".stage.open").forEach(function (stage) {
202 stage.classList.remove("open");
203 var pop = popOf(stage);
204 closeLayer(pop);
205 untrack(pop);
206 });
207 }
208
209 document.addEventListener("click", function (ev) {
210 var btn = ev.target.closest("button.stage-dot[data-tip]");
211 if (btn) {
212 ev.stopPropagation();
213 var stage = btn.parentElement;
214 var pop = popOf(stage);
215 if (pop) {
216 stage._pop = pop;
217 }
218 var was = stage.classList.contains("open");
219 hideTip();
220 closeStages();
221 if (!was && pop) {
222 stage.classList.add("open");
223 openLayer(pop);
224 track(pop, btn, "below-start");
225 }
226 return;
227 }
228 if (ev.target.closest(".stage-pop")) {
229 return;
230 }
231 closeStages();
232 });
233 document.addEventListener("keydown", function (ev) {
234 if (ev.key === "Escape") {
235 hideTip();
236 closeStages();
237 }
238 });
239
240 document.querySelectorAll("details").forEach(function (det) {
241 var panel = det.querySelector(":scope > .menu-panel, :scope > form");
242 if (!panel) {
243 return;
244 }
245 if (!panel.classList.contains("menu-panel") && !det.classList.contains("showid")) {
246 return;
247 }
248 panel.setAttribute("popover", "manual");
249 det.addEventListener("toggle", function () {
250 var summary = det.querySelector("summary");
251 if (det.open && summary) {
252 // A popover nested in <details> stays display:none in the top layer
253 // until it leaves the details element. Park the panel on body first.
254 if (panel.classList.contains("menu-panel") && panel.parentNode !== document.body) {
255 panel._home = panel.parentNode;
256 document.body.appendChild(panel);
257 }
258 openLayer(panel);
259 track(panel, summary, "below-end");
260 } else {
261 closeLayer(panel);
262 untrack(panel);
263 }
264 });
265 });
266})();
267
268(function () {
269 function copyNow(value) {
270 var area = document.createElement("textarea");
271 area.value = value;
272 area.setAttribute("readonly", "");
273 area.style.position = "fixed";
274 area.style.top = "0";
275 area.style.left = "0";
276 area.style.opacity = "0";
277 document.body.appendChild(area);
278 area.focus();
279 area.select();
280 var ok = false;
281 try {
282 ok = document.execCommand("copy");
283 } catch (e) {
284 ok = false;
285 }
286 document.body.removeChild(area);
287 return ok;
288 }
289 document.querySelectorAll("[data-copy]").forEach(function (btn) {
290 btn.addEventListener("click", function () {
291 var value = btn.getAttribute("data-copy") || "";
292 var shown = false;
293 function mark() {
294 if (shown) {
295 return;
296 }
297 shown = true;
298 var copied = document.body.getAttribute("data-copied") || "Copied";
299 var hasIcon = btn.querySelector("svg");
300 if (hasIcon) {
301 var prevLabel = btn.getAttribute("aria-label");
302 var prevTitle = btn.getAttribute("title");
303 btn.classList.add("copied");
304 btn.setAttribute("aria-label", copied);
305 btn.setAttribute("title", copied);
306 setTimeout(function () {
307 btn.classList.remove("copied");
308 if (prevLabel) { btn.setAttribute("aria-label", prevLabel); } else { btn.removeAttribute("aria-label"); }
309 if (prevTitle) { btn.setAttribute("title", prevTitle); } else { btn.removeAttribute("title"); }
310 }, 2500);
311 return;
312 }
313 var old = btn.textContent;
314 btn.textContent = copied;
315 setTimeout(function () { btn.textContent = old; }, 2500);
316 }
317 if (copyNow(value)) {
318 mark();
319 }
320 if (navigator.clipboard && window.isSecureContext) {
321 navigator.clipboard.writeText(value).then(mark).catch(function () {});
322 }
323 });
324 });
325})();
326
327// Obsolete-statussen krijgen hun uitleg als tooltip (data-tip) en
328// aria-label, ook als pipeline.js de klasse live wijzigt.
329(function () {
330 var tips = {
331 obsolete: document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref",
332 waiting_for_job: document.body.getAttribute("data-waitjob-tip") || "waiting for a non-interruptible job in an older pipeline on the same ref",
333 blocked: document.body.getAttribute("data-blocked-tip") || "only manual jobs are left; start one to continue"
334 };
335 function tag() {
336 Object.keys(tips).forEach(function (cls) { tagOne(cls, tips[cls]); });
337 }
338 function tagOne(cls, tip) {
339 var list = document.querySelectorAll(".status." + cls);
340 Array.prototype.forEach.call(list, function (el) {
341 if (el.getAttribute("data-tip") !== tip) {
342 el.setAttribute("data-tip", tip);
343 var label = (el.textContent || "").trim();
344 el.setAttribute("aria-label", label ? label + ": " + tip : tip);
345 }
346 });
347 }
348 function untag(el) {
349 if (!el.classList || !el.classList.contains("status")) {
350 return;
351 }
352 var t = el.getAttribute("data-tip");
353 var stale = Object.keys(tips).some(function (cls) { return t === tips[cls] && !el.classList.contains(cls); });
354 if (stale) {
355 el.removeAttribute("data-tip");
356 el.removeAttribute("aria-label");
357 }
358 }
359 tag();
360 new MutationObserver(function (muts) {
361 muts.forEach(function (m) {
362 if (m.type === "attributes") {
363 untag(m.target);
364 }
365 });
366 tag();
367 }).observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
368})();