gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbb2ebc67bb2ebc67log: #64 live, #53 mergedmrebb2ebc67/login.js

2.7 KB

  1. // login.js — the small bridge between ident's <ident-selector> and the tracker shell (components/main.hl; the same
  2. // as calendar's/gitoria's login.js — copied unchanged, creator: "login.js is correct, as thats for externals in
  3. // general"). Plain JS because hl:web cannot listen to a custom DOM event: `ident-login`
  4. // (event.detail.code, the one-time code) goes into the hidden input #identcode, whose `change` the shell handles
  5. // (→ face trackerLogin, server-side exchange). The shell keeps the selector element's class at `in` / `out`; it is
  6. // mirrored here into the selector's `loggedIn` (false = back to "choose ident").
  7. // BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL (project.hl safePath).
  8. // RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the
  9. // selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each
  10. // time, and a one-time code is handed to the shell at most once.
  11. (() => {
  12. if (window.__trackerLogin) { window.__trackerLogin.sync(); return; }
  13. const sync = () => {
  14. const sel = document.getElementById('selector');
  15. // not upgraded yet: a property set now would shadow the element's own accessor
  16. if (!sel || !window.customElements || !customElements.get('ident-selector')) return;
  17. const want = sel.classList.contains('in');
  18. if (sel.loggedIn !== want) sel.loggedIn = want;
  19. };
  20. new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });
  21. if (window.customElements) customElements.whenDefined('ident-selector').then(sync);
  22. const handed = new Set();
  23. document.addEventListener('ident-login', (e) => {
  24. const code = e.detail && e.detail.code;
  25. const input = document.getElementById('identcode');
  26. if (!input || !code || handed.has(code)) return; // a one-time code is exchanged once
  27. handed.add(code);
  28. input.value = code;
  29. input.dispatchEvent(new Event('change', { bubbles: true }));
  30. });
  31. const withNext = (a) => {
  32. try {
  33. const u = new URL(a.href);
  34. const ret = new URL(u.searchParams.get('return'));
  35. const here = location.pathname + location.search;
  36. ret.search = '';
  37. if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);
  38. u.searchParams.set('return', ret.href);
  39. a.href = u.href;
  40. } catch (err) { /* keep the server's href: the login still works, it returns to / */ }
  41. };
  42. const onButton = (e) => {
  43. const a = e.target && e.target.closest && e.target.closest('#loginbutton');
  44. if (a) withNext(a);
  45. };
  46. for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);
  47. window.__trackerLogin = { sync };
  48. })();

Branches

Latest commits

  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre
  • 5831e0e0log: HM64 donemre
  • 4042b923Flatten catalog membership rows into paired slotsmre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre