oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1// The composer, on the conversation and a task's thread. A click anywhere
2// in the compose box (the pill's padding, the dock around it) puts the
3// cursor in the message; the box's controls keep their own clicks. With
4// script, the send arrow shows only when there is something to send
5// (words, or an attachment that is not refused), and the message grows to
6// about six lines, then scrolls.
7(function () {
8 "use strict";
9 document.addEventListener("click", function (event) {
10 var box = event.target.closest && event.target.closest("#chat-composer");
11 if (!box || event.target.closest("button, a, select, input, textarea, summary, label, [contenteditable], [equipo-chips], [equipo-add-menu]")) return;
12 var input = box.querySelector("textarea");
13 if (input && document.activeElement !== input) input.focus({ preventScroll: true });
14 });
15 var form = document.querySelector("#composer[equipo-composer]");
16 if (!form) return;
17 var input = form.querySelector("textarea");
18 // Script decides what can go: words, attachments or both.
19 input.required = false;
20 // The first hiding of the arrow is instant: no fade on page load.
21 form.setAttribute("data-instant", "");
22 form.setAttribute("data-enhanced", "");
23 requestAnimationFrame(function () { requestAnimationFrame(function () { form.removeAttribute("data-instant"); }); });
24 var sized = window.CSS && CSS.supports && CSS.supports("field-sizing", "content");
25 function grow() {
26 if (sized) return;
27 var cs = getComputedStyle(input);
28 var pad = parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom);
29 input.style.height = "auto";
30 input.style.height = Math.min(input.scrollHeight - pad, parseFloat(cs.maxHeight) || Infinity) + "px";
31 }
32 function state() {
33 var files = form.querySelectorAll("[equipo-chip]:not([data-state='error'])").length;
34 form.toggleAttribute("data-has-content", /\S/.test(input.value) || files > 0);
35 grow();
36 }
37 input.addEventListener("input", state);
38 form.addEventListener("equipo:changed", state);
39 form.addEventListener("equipo:sent", state);
40 state();
41})();
42
43// Card composers use the main composer's pill and send affordance.
44(function () {
45 "use strict";
46 document.addEventListener("input", function (event) {
47 var form=event.target.closest("[equipo-mini-composer]");if(!form)return;
48 form.toggleAttribute("data-has-content", /\S/.test(event.target.value));
49 });
50 document.addEventListener("toggle", function (event) {
51 if(event.target.matches("[data-direction-thread], [data-report-thread]") && event.target.open) {if(event.target.hasAttribute("data-restored")){delete event.target.dataset.restored;return;}var input=event.target.querySelector("textarea");if(input)input.focus({preventScroll:true});}
52 },true);
53})();
54(function () {
55 "use strict";
56 document.addEventListener("keydown", function(e) {
57 var form=e.target.closest("[equipo-mini-composer]");
58 if(!form || e.target.tagName!=="TEXTAREA" || e.key!=="Enter" || e.shiftKey || e.isComposing || e.keyCode===229)return;
59 e.preventDefault();var send=form.querySelector("[data-thread-send]");if(send && !send.disabled)form.requestSubmit(send);
60 });
61})();
62
63// The empty conversation's starters fill the composer with their opening
64// words and put the cursor after them; they never send. Words the person
65// typed stay theirs: a starter replaces only an empty composer or another
66// starter's words. Without script each is a GET that opens the page so.
67(function () {
68 "use strict";
69 document.addEventListener("click", function (event) {
70 var button = event.target.closest && event.target.closest("[equipo-starters] button[data-draft]");
71 var input = document.querySelector("#composer textarea");
72 if (!button || !input) return;
73 event.preventDefault();
74 var drafts = [].map.call(button.form.querySelectorAll("button[data-draft]"), function (b) { return b.dataset.draft; });
75 if (!/\S/.test(input.value) || drafts.indexOf(input.value) >= 0) {
76 input.value = button.dataset.draft;
77 input.dispatchEvent(new Event("input", { bubbles: true }));
78 }
79 input.focus({ preventScroll: true });
80 input.setSelectionRange(input.value.length, input.value.length);
81 });
82})();
83