Fossil SCM

Source Blame History 338 lines
2a34d86… dmestas 1 document.addEventListener('DOMContentLoaded', function () {
2a34d86… dmestas 2 (function () {
2a34d86… dmestas 3 'use strict';
2a34d86… dmestas 4
2a34d86… dmestas 5 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 6 1. isDark patch
2a34d86… dmestas 7 Fossil's C code hard-codes isDark:false for all custom skins,
2a34d86… dmestas 8 ignoring the skin-detail config key. Patch it here after Fossil's
2a34d86… dmestas 9 inline scripts have already run (guaranteed by defer).
2a34d86… dmestas 10 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 11 function patchIsDark() {
2a34d86… dmestas 12 /* Only for the dark variant: the light build of this skin embeds the
2a34d86… dmestas 13 same script, and its stylesheet declares color-scheme: light. */
2a34d86… dmestas 14 if (getComputedStyle(document.documentElement).colorScheme.indexOf('dark') < 0) return;
2a34d86… dmestas 15 if (window.fossil && window.fossil.config && window.fossil.config.skin) {
2a34d86… dmestas 16 window.fossil.config.skin.isDark = true;
2a34d86… dmestas 17 }
2a34d86… dmestas 18 document.body.classList.add('fossil-dark-style');
2a34d86… dmestas 19 }
2a34d86… dmestas 20
2a34d86… dmestas 21 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 22 2. Main landmark
2a34d86… dmestas 23 div.content is Fossil's primary content wrapper but has no landmark
2a34d86… dmestas 24 role. Adding role="main" lets screen reader users jump to content.
2a34d86… dmestas 25 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 26 function addMainLandmark() {
2a34d86… dmestas 27 var content = document.querySelector('div.content');
2a34d86… dmestas 28 if (content && !content.getAttribute('role')) {
2a34d86… dmestas 29 content.setAttribute('role', 'main');
2a34d86… dmestas 30 }
2a34d86… dmestas 31 }
2a34d86… dmestas 32
2a34d86… dmestas 33 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 34 3. Hamburger menu — the worst accessibility failure in the skin
2a34d86… dmestas 35 ----------------------------------------------------------------
2a34d86… dmestas 36 What Fossil gives us:
2a34d86… dmestas 37 <a id="hbbtn" href="/repo/sitemap" aria-label="Site Map">☰</a>
2a34d86… dmestas 38 <nav id="hbdrop" class="hbdrop" title="sitemap"></nav>
2a34d86… dmestas 39
2a34d86… dmestas 40 Problems:
2a34d86… dmestas 41 - No aria-expanded: screen readers can't tell if the menu is open
2a34d86… dmestas 42 - No aria-controls: no programmatic link between button and panel
2a34d86… dmestas 43 - hbdrop has no role or accessible name beyond an unhelpful title
2a34d86… dmestas 44 - When the menu opens, focus stays on hbbtn — user cannot reach
2a34d86… dmestas 45 the menu links by keyboard without realising the menu opened
2a34d86… dmestas 46 - Escape key does not close the menu
2a34d86… dmestas 47 - hbmenu.js controls visibility via style.display; we use
2a34d86… dmestas 48 MutationObserver to stay in sync rather than patching the JS
2a34d86… dmestas 49
2a34d86… dmestas 50 Fixes applied:
2a34d86… dmestas 51 - aria-expanded / aria-controls on hbbtn
2a34d86… dmestas 52 - role="navigation" + aria-label on hbdrop
2a34d86… dmestas 53 - MutationObserver: sync aria-expanded on every show/hide
2a34d86… dmestas 54 - On open: move focus to the first link in the dropdown
2a34d86… dmestas 55 - On Escape inside dropdown: close panel, return focus to hbbtn
2a34d86… dmestas 56 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 57 function fixHamburgerMenu() {
2a34d86… dmestas 58 var btn = document.getElementById('hbbtn');
2a34d86… dmestas 59 var drop = document.getElementById('hbdrop');
2a34d86… dmestas 60 if (!btn || !drop) return;
2a34d86… dmestas 61
2a34d86… dmestas 62 var nav = btn.closest('nav.mainmenu') || btn.parentNode;
2a34d86… dmestas 63 if (!nav) return;
2a34d86… dmestas 64
2a34d86… dmestas 65 /* Position the dropdown using position:fixed so it overlays content
2a34d86… dmestas 66 regardless of DOM structure. We set --nav-bottom as a CSS variable
2a34d86… dmestas 67 so the dropdown's top edge tracks the nav bar's bottom edge. */
2a34d86… dmestas 68 function setNavBottom() {
2a34d86… dmestas 69 var bottom = Math.max(0, nav.getBoundingClientRect().bottom);
2a34d86… dmestas 70 document.documentElement.style.setProperty('--nav-bottom', bottom + 'px');
2a34d86… dmestas 71 }
2a34d86… dmestas 72 setNavBottom();
2a34d86… dmestas 73 window.addEventListener('resize', setNavBottom);
2a34d86… dmestas 74 /* Measure again on every open (capture: before hbmenu.js shows the
2a34d86… dmestas 75 panel), so the menu opens under the nav bar wherever the page is. */
2a34d86… dmestas 76 btn.addEventListener('click', setNavBottom, true);
2a34d86… dmestas 77 /* Open by touch or mouse vs keyboard: only the keyboard gets focus moved */
2a34d86… dmestas 78 var openedByPointer = false;
2a34d86… dmestas 79 btn.addEventListener('pointerdown', function () { openedByPointer = true; });
2a34d86… dmestas 80 btn.addEventListener('keydown', function () { openedByPointer = false; });
2a34d86… dmestas 81
2a34d86… dmestas 82 /* Static button semantics (JS will keep aria-expanded in sync) */
2a34d86… dmestas 83 btn.setAttribute('aria-expanded', 'false');
2a34d86… dmestas 84 btn.setAttribute('aria-controls', 'hbdrop');
2a34d86… dmestas 85
2a34d86… dmestas 86 /* Panel semantics */
2a34d86… dmestas 87 drop.setAttribute('role', 'navigation');
2a34d86… dmestas 88 drop.setAttribute('aria-label', 'Site map');
2a34d86… dmestas 89
2a34d86… dmestas 90 /* Sync aria-expanded whenever hbmenu.js toggles panel visibility.
2a34d86… dmestas 91 hbmenu.js uses style.display to show/hide — observe that attribute. */
2a34d86… dmestas 92 var menuObserver = new MutationObserver(function () {
2a34d86… dmestas 93 var open = getComputedStyle(drop).display !== 'none';
2a34d86… dmestas 94 btn.setAttribute('aria-expanded', open ? 'true' : 'false');
2a34d86… dmestas 95
2a34d86… dmestas 96 /* Move focus into the panel when it opens so keyboard users
2a34d86… dmestas 97 can immediately navigate the links without guessing. */
2a34d86… dmestas 98 if (open) {
2a34d86… dmestas 99 /* The nav bar may now be stuck to the top (see the skin CSS) */
2a34d86… dmestas 100 requestAnimationFrame(setNavBottom);
2a34d86… dmestas 101 if (!openedByPointer) {
2a34d86… dmestas 102 var firstLink = drop.querySelector('a');
2a34d86… dmestas 103 if (firstLink) firstLink.focus({ preventScroll: true });
2a34d86… dmestas 104 }
2a34d86… dmestas 105 }
2a34d86… dmestas 106 });
2a34d86… dmestas 107 menuObserver.observe(drop, { attributes: true, attributeFilter: ['style'] });
2a34d86… dmestas 108
2a34d86… dmestas 109 /* Escape inside the dropdown: close the panel and return focus.
2a34d86… dmestas 110 We set display directly — this also triggers the MutationObserver
2a34d86… dmestas 111 which will update aria-expanded to 'false'. */
2a34d86… dmestas 112 drop.addEventListener('keydown', function (e) {
2a34d86… dmestas 113 if (e.key === 'Escape' || e.keyCode === 27) {
2a34d86… dmestas 114 drop.style.display = 'none';
2a34d86… dmestas 115 btn.focus();
2a34d86… dmestas 116 }
2a34d86… dmestas 117 });
2a34d86… dmestas 118 }
2a34d86… dmestas 119
2a34d86… dmestas 120 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 121 4. Timeline table
2a34d86… dmestas 122 ----------------------------------------------------------------
2a34d86… dmestas 123 Structure Fossil generates:
2a34d86… dmestas 124
2a34d86… dmestas 125 <table class="timelineTable">
2a34d86… dmestas 126 <tr class="timelineDateRow">
2a34d86… dmestas 127 <td><div class="timelineDate">2026-03-14</div></td>
2a34d86… dmestas 128 <td></td> <- empty filler for graph column
2a34d86… dmestas 129 <td></td> <- empty filler for comment column
2a34d86… dmestas 130 </tr>
2a34d86… dmestas 131 <tr>
2a34d86… dmestas 132 <td class="timelineTime">20:16</td>
2a34d86… dmestas 133 <td class="timelineGraph">
2a34d86… dmestas 134 <div class="tl-nodemark"></div> <- JS draws SVG here later
2a34d86… dmestas 135 </td>
2a34d86… dmestas 136 <td class="timelineModernCell" id="mc1">
2a34d86… dmestas 137 <span class="timelineModernComment">commit message</span>
2a34d86… dmestas 138 <span class="timelineModernDetail">...</span>
2a34d86… dmestas 139 </td>
2a34d86… dmestas 140 </tr>
2a34d86… dmestas 141 </table>
2a34d86… dmestas 142
2a34d86… dmestas 143 Fixes applied:
2a34d86… dmestas 144 - aria-label="Commit timeline" on each .timelineTable
2a34d86… dmestas 145 - aria-hidden="true" on all td.timelineGraph cells
2a34d86… dmestas 146 - aria-hidden="true" on filler cells in timelineDateRow rows
2a34d86… dmestas 147 - aria-label="Time: HH:MM" on timelineTime cells
2a34d86… dmestas 148
2a34d86… dmestas 149 Run at defer-time AND on window.load because Fossil's timeline JS
2a34d86… dmestas 150 inserts SVG canvas elements into the graph cells on window.load.
2a34d86… dmestas 151 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 152 function fixTimeline() {
2a34d86… dmestas 153 /* Label each timeline table */
2a34d86… dmestas 154 document.querySelectorAll('table.timelineTable').forEach(function (tbl) {
2a34d86… dmestas 155 if (!tbl.getAttribute('aria-label') && !tbl.querySelector('caption')) {
2a34d86… dmestas 156 tbl.setAttribute('aria-label', 'Commit timeline');
2a34d86… dmestas 157 }
2a34d86… dmestas 158 });
2a34d86… dmestas 159
2a34d86… dmestas 160 /* Hide the graph column — purely visual SVG/canvas drawn by Fossil JS */
2a34d86… dmestas 161 document.querySelectorAll('td.timelineGraph').forEach(function (td) {
2a34d86… dmestas 162 td.setAttribute('aria-hidden', 'true');
2a34d86… dmestas 163 });
2a34d86… dmestas 164
2a34d86… dmestas 165 /* Hide filler cells in date-separator rows */
2a34d86… dmestas 166 document.querySelectorAll('tr.timelineDateRow').forEach(function (tr) {
2a34d86… dmestas 167 tr.querySelectorAll('td + td').forEach(function (td) {
2a34d86… dmestas 168 td.setAttribute('aria-hidden', 'true');
2a34d86… dmestas 169 });
2a34d86… dmestas 170 });
2a34d86… dmestas 171
2a34d86… dmestas 172 /* Give bare time cells a descriptive label.
2a34d86… dmestas 173 Strip stray </a> text artefact Fossil emits in anonymous mode. */
2a34d86… dmestas 174 document.querySelectorAll('td.timelineTime').forEach(function (td) {
2a34d86… dmestas 175 var text = td.textContent.trim();
2a34d86… dmestas 176 if (text && !td.getAttribute('aria-label')) {
2a34d86… dmestas 177 td.setAttribute('aria-label', 'Time: ' + text);
2a34d86… dmestas 178 }
2a34d86… dmestas 179 });
2a34d86… dmestas 180 }
2a34d86… dmestas 181
2a34d86… dmestas 182 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 183 5. Sortable table headers — add scope="col"
2a34d86… dmestas 184 Fossil generates <th> elements in branch, tag, file, and ticket
2a34d86… dmestas 185 tables but never includes scope. Screen readers cannot correctly
2a34d86… dmestas 186 associate header text with the cells in each column.
2a34d86… dmestas 187 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 188 function fixTableHeaders() {
2a34d86… dmestas 189 var selector = [
2a34d86… dmestas 190 'table.sortable th',
2a34d86… dmestas 191 'table.filelistTable th',
2a34d86… dmestas 192 'table.branchlistTable th',
2a34d86… dmestas 193 'table.taglistTable th',
2a34d86… dmestas 194 'table.userlistTable th',
2a34d86… dmestas 195 'table.report th',
2a34d86… dmestas 196 ].join(', ');
2a34d86… dmestas 197 document.querySelectorAll(selector).forEach(function (th) {
2a34d86… dmestas 198 if (!th.getAttribute('scope')) {
2a34d86… dmestas 199 th.setAttribute('scope', 'col');
2a34d86… dmestas 200 }
2a34d86… dmestas 201 });
2a34d86… dmestas 202 }
2a34d86… dmestas 203
2a34d86… dmestas 204 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 205 6. Submenu select labels
2a34d86… dmestas 206 Fossil renders <select> controls in the page submenu with no
2a34d86… dmestas 207 associated <label>. We add aria-label from the preceding sibling
2a34d86… dmestas 208 label text, falling back to a class-name lookup table.
2a34d86… dmestas 209 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 210 var SELECT_LABELS = {
2a34d86… dmestas 211 'smc-ss': 'View style',
2a34d86… dmestas 212 'smc-ci': 'Check-in',
2a34d86… dmestas 213 'smc-v': 'Version',
2a34d86… dmestas 214 'smc-r': 'Repository',
2a34d86… dmestas 215 'smc-b': 'Branch',
2a34d86… dmestas 216 'smc-t': 'Tag',
2a34d86… dmestas 217 'smc-u': 'User',
2a34d86… dmestas 218 };
2a34d86… dmestas 219
2a34d86… dmestas 220 /* Charts Fossil draws as <svg width= height=> with no viewBox cannot be
2a34d86… dmestas 221 scaled by CSS. Give them one; the skin's "svg.fit" rule does the rest. */
2a34d86… dmestas 222 function fitCharts() {
2a34d86… dmestas 223 document.querySelectorAll('.content svg[width][height]:not([viewBox])').forEach(function (s) {
2a34d86… dmestas 224 var w = parseFloat(s.getAttribute('width')), h = parseFloat(s.getAttribute('height'));
2a34d86… dmestas 225 if (!(w > 0 && h > 0)) return;
2a34d86… dmestas 226 s.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
2a34d86… dmestas 227 s.classList.add('fit');
2a34d86… dmestas 228 });
2a34d86… dmestas 229 }
2a34d86… dmestas 230
2a34d86… dmestas 231 /* Sortable column headers respond to clicks only. Put them in the tab
2a34d86… dmestas 232 order and let Enter or Space do what a click does. */
2a34d86… dmestas 233 function fixSortableHeaders() {
2a34d86… dmestas 234 document.querySelectorAll('table.sortable th').forEach(function (th) {
2a34d86… dmestas 235 if (th.hasAttribute('tabindex')) return;
2a34d86… dmestas 236 th.setAttribute('tabindex', '0');
2a34d86… dmestas 237 th.addEventListener('keydown', function (e) {
2a34d86… dmestas 238 if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); th.click(); }
2a34d86… dmestas 239 });
2a34d86… dmestas 240 });
2a34d86… dmestas 241 }
2a34d86… dmestas 242
2a34d86… dmestas 243 /* The menu bar scrolls sideways on narrow screens. Bring the current
2a34d86… dmestas 244 page's entry into view, without moving the page itself. */
2a34d86… dmestas 245 function showActiveMenuItem() {
2a34d86… dmestas 246 var nav = document.querySelector('nav.mainmenu');
2a34d86… dmestas 247 var a = nav && nav.querySelector('a.active');
2a34d86… dmestas 248 var hb = document.getElementById('hbbtn');
2a34d86… dmestas 249 if (!a || a === hb || nav.scrollWidth <= nav.clientWidth) return;
2a34d86… dmestas 250 var left = a.offsetLeft - nav.offsetLeft, pinned = hb ? hb.offsetWidth : 0;
2a34d86… dmestas 251 if (left - pinned < nav.scrollLeft || left + a.offsetWidth > nav.scrollLeft + nav.clientWidth - 28) {
2a34d86… dmestas 252 nav.scrollLeft = Math.max(0, left - pinned - 12);
2a34d86… dmestas 253 }
2a34d86… dmestas 254 }
2a34d86… dmestas 255
2a34d86… dmestas 256 function fixSubmenuSelects() {
2a34d86… dmestas 257 document.querySelectorAll('div.submenu select, div.sectionmenu select').forEach(function (sel) {
2a34d86… dmestas 258 if (sel.getAttribute('aria-label') || sel.getAttribute('aria-labelledby')) return;
2a34d86… dmestas 259
2a34d86… dmestas 260 /* Walk backwards through siblings to find a .label text node */
2a34d86… dmestas 261 var prev = sel.previousElementSibling;
2a34d86… dmestas 262 while (prev) {
2a34d86… dmestas 263 if (prev.classList.contains('label') && prev.textContent.trim()) {
2a34d86… dmestas 264 sel.setAttribute('aria-label', prev.textContent.trim());
2a34d86… dmestas 265 return;
2a34d86… dmestas 266 }
2a34d86… dmestas 267 prev = prev.previousElementSibling;
2a34d86… dmestas 268 }
2a34d86… dmestas 269
2a34d86… dmestas 270 /* Class-name lookup */
2a34d86… dmestas 271 var classes = Array.from(sel.classList);
2a34d86… dmestas 272 for (var i = 0; i < classes.length; i++) {
2a34d86… dmestas 273 if (SELECT_LABELS[classes[i]]) {
2a34d86… dmestas 274 sel.setAttribute('aria-label', SELECT_LABELS[classes[i]]);
2a34d86… dmestas 275 return;
2a34d86… dmestas 276 }
2a34d86… dmestas 277 }
2a34d86… dmestas 278
2a34d86… dmestas 279 sel.setAttribute('aria-label', 'Filter');
2a34d86… dmestas 280 });
2a34d86… dmestas 281 }
2a34d86… dmestas 282
2a34d86… dmestas 283 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 284 7. Day of week on each timeline date
2a34d86… dmestas 285 Fossil's date rows carry only the date ("2026-11-11"). This puts the
2a34d86… dmestas 286 full weekday on a small line above it. The weekday comes from Ben
2a34d86… dmestas 287 Joffe's branchless method (benjoffe.com/fast-day-of-week), as zit
2a34d86… dmestas 288 uses it: one multiply and two shifts, exact for every 32-bit day
2a34d86… dmestas 289 number. It is read from the date Fossil prints, so it always matches
2a34d86… dmestas 290 that date whether the timeline shows UTC or local time. The skin CSS
2a34d86… dmestas 291 reserves the line before this runs, so setting the name moves nothing.
2a34d86… dmestas 292 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 293 var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
2a34d86… dmestas 294 function weekdayOf(dayNumber) { /* days since 1970-01-01 -> 0 = Sunday */
2a34d86… dmestas 295 return ((Math.imul(dayNumber, 613566756) + 0x95000000 +
2a34d86… dmestas 296 (dayNumber >> 1) + (dayNumber >> 4)) >>> 0) >>> 29;
2a34d86… dmestas 297 }
2a34d86… dmestas 298 function addWeekdays() {
2a34d86… dmestas 299 var rows = document.querySelectorAll('div.timelineDate');
2a34d86… dmestas 300 for (var i = 0; i < rows.length; i++) {
2a34d86… dmestas 301 if (rows[i].hasAttribute('data-dow')) continue;
2a34d86… dmestas 302 var m = /^(\d{4})-(\d\d)-(\d\d)$/.exec(rows[i].textContent.trim());
2a34d86… dmestas 303 if (!m) continue;
2a34d86… dmestas 304 /* The skin CSS shows this in a line it reserves above the date */
2a34d86… dmestas 305 rows[i].setAttribute('data-dow', WEEKDAYS[weekdayOf(Date.UTC(+m[1], m[2] - 1, +m[3]) / 864e5)]);
2a34d86… dmestas 306 }
2a34d86… dmestas 307 }
2a34d86… dmestas 308
2a34d86… dmestas 309 /* ─────────────────────────────────────────────────────────────────────
2a34d86… dmestas 310 Execute all fixes
2a34d86… dmestas 311 The script is deferred so the DOM is fully parsed when this runs.
2a34d86… dmestas 312 Fossil's inline config scripts have already executed, so
2a34d86… dmestas 313 window.fossil exists and we can patch isDark immediately.
2a34d86… dmestas 314 ───────────────────────────────────────────────────────────────────── */
2a34d86… dmestas 315 patchIsDark();
2a34d86… dmestas 316 addMainLandmark();
2a34d86… dmestas 317 fixHamburgerMenu();
2a34d86… dmestas 318 fixTimeline();
2a34d86… dmestas 319 fixTableHeaders();
2a34d86… dmestas 320 fixSubmenuSelects();
2a34d86… dmestas 321 fitCharts();
2a34d86… dmestas 322 showActiveMenuItem();
2a34d86… dmestas 323 fixSortableHeaders();
2a34d86… dmestas 324 addWeekdays();
2a34d86… dmestas 325
2a34d86… dmestas 326 /* Re-run after window.load: Fossil's timeline renderer inserts
2a34d86… dmestas 327 .tl-canvas SVG elements into td.timelineGraph on load, and
2a34d86… dmestas 328 Fossil's own load handlers may reset isDark. */
2a34d86… dmestas 329 window.addEventListener('load', function () {
2a34d86… dmestas 330 patchIsDark();
2a34d86… dmestas 331 fixTimeline();
2a34d86… dmestas 332 fixTableHeaders();
2a34d86… dmestas 333 fixSubmenuSelects();
2a34d86… dmestas 334 });
2a34d86… dmestas 335
2a34d86… dmestas 336 }());
2a34d86… dmestas 337
2a34d86… dmestas 338 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button