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