oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// The work pages (Tasks, a task, Projects, a project, Needs you) follow
2// the same stream as the sidebar: on a task, step, activity or card
3// event the page is rendered again and each live region (an element
4// with data-work-region and an id) is swapped in place. Open folds keep
5// their state; a timeline line that is new rises in. The task page's
6// thread is not a region: chat-stream.js follows it.
7(function () {
8 "use strict";
9 // equipoPulse(root): a stage track's working pulse (equipo.css) keeps
10 // one phase on every page and across swaps. Each ring and light under
11 // root is timed from the document's start, so a track swapped in or
12 // marked working carries on in step, never from the top.
13 window.equipoPulse = function (root) {
14 if (!root || !root.getAnimations) return;
15 root.getAnimations({ subtree: true }).forEach(function (a) {
16 if (a.animationName === "equipo-tl-ring" || a.animationName === "equipo-tl-flow") a.startTime = 0;
17 });
18 };
19 window.equipoPulse(document.body);
20 if (!document.querySelector("[data-work-live]") || !window.fetch) return;
21 var inflight = null, again = false, timer = 0;
22 function busy() {
23 // Never swap a menu or a filter out from under the person.
24 return !!document.querySelector("[data-work-region] [equipo-menu][open], [data-work-region] [equipo-filter][open]") ||
25 !!(document.activeElement && document.activeElement.closest && document.activeElement.closest("[data-work-region] form"));
26 }
27 function load() {
28 return fetch(location.href, { credentials: "same-origin", headers: { "Accept": "text/html" } })
29 .then(function (r) { if (!r.ok) throw new Error("page"); return r.text(); })
30 .then(function (body) {
31 var doc = new DOMParser().parseFromString(body, "text/html");
32 document.querySelectorAll("[data-work-region][id]").forEach(function (old) {
33 var next = doc.getElementById(old.id);
34 if (!next) return;
35 var open = {};
36 old.querySelectorAll("details[id]").forEach(function (d) { open[d.id] = d.open; });
37 var had = old.querySelectorAll("[equipo-tl] > li").length;
38 var focus = document.activeElement && old.contains(document.activeElement) ? document.activeElement.getAttribute("href") : null;
39 old.replaceWith(next);
40 window.equipoPulse(next);
41 Object.keys(open).forEach(function (id) { var d = document.getElementById(id); if (d) d.open = open[id]; });
42 var items = next.querySelectorAll("[equipo-tl] > li");
43 for (var i = had; had > 0 && i < items.length; i++) items[i].setAttribute("data-new", "");
44 if (focus) { var f = next.querySelector('a[href="' + CSS.escape(focus) + '"]'); if (f) f.focus(); }
45 });
46 if (window.equipoAges) window.equipoAges();
47 var title = doc.querySelector("title");
48 if (title) document.title = title.textContent;
49 });
50 }
51 function refresh() {
52 if (inflight) { again = true; return; }
53 if (busy()) { clearTimeout(timer); timer = setTimeout(refresh, 1000); return; }
54 inflight = load().catch(function () {}).finally(function () {
55 inflight = null;
56 if (again) { again = false; refresh(); }
57 });
58 }
59 document.addEventListener("equipo:work", function () {
60 clearTimeout(timer);
61 timer = setTimeout(refresh, 200);
62 });
63})();
64