- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.js
More file actions
Latest commit
287 lines (246 loc) · 10.4 KB
/
Copy pathsite.js
File metadata and controls
287 lines (246 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* ============================================================
MathEXplained — Shared site behaviour
Nav state, banner dismissal, scroll affordances, archive filter.
============================================================ */
(function(){
'use strict';
varreduceMotion=window.matchMedia&&
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
/* ---------- Mark the current page in the nav ---------- */
(functionactiveNav(){
varhere=location.pathname.split('/').pop()||'index.html';
document.querySelectorAll('.nav-right a[href]').forEach(function(a){
varhref=a.getAttribute('href');
if(href&&href.split('/').pop()===here){
a.classList.add('is-active');
a.setAttribute('aria-current','page');
}
});
})();
/* ---------- Dismissible announcement banner ---------- */
(functionbanner(){
varel=document.querySelector('.announcement-banner');
if(!el)return;
// Key on the message itself, so publishing a new announcement
// re-shows the bar for people who dismissed the previous one.
varkey='mx-banner:'+(el.dataset.bannerId||el.textContent.trim().slice(0,60));
varstore;
try{store=window.localStorage;}catch(e){store=null;}
functionhide(){
document.body.classList.add('banner-hidden');
el.remove();
document.documentElement.style.removeProperty('--banner-h');
}
if(store&&store.getItem(key)){hide();return;}
// The banner is fixed-position and the header sits directly beneath it,
// so --banner-h has to match its real rendered height. Announcement text
// that wraps to two lines on a phone would otherwise slide under the header.
functionmeasure(){
document.documentElement.style.setProperty('--banner-h',el.offsetHeight+'px');
}
measure();
window.addEventListener('resize',measure,{passive: true});
if(document.fonts&&document.fonts.ready)document.fonts.ready.then(measure);
varclose=document.createElement('button');
close.type='button';
close.className='banner-close';
close.setAttribute('aria-label','Dismiss announcement');
close.innerHTML='×';
close.addEventListener('click',function(){
hide();
if(store){try{store.setItem(key,'1');}catch(e){/* quota / private mode */}}
});
el.appendChild(close);
})();
/* ---------- Shadow the header once the page scrolls ---------- */
(functionheaderState(){
varheader=document.querySelector('.headerbar');
if(!header)return;
varticking=false;
functionupdate(){
ticking=false;
header.classList.toggle('is-scrolled',window.scrollY>12);
}
window.addEventListener('scroll',function(){
if(ticking)return;
ticking=true;
requestAnimationFrame(update);
},{passive: true});
update();
})();
/* ---------- Reveal cards as they scroll into view ---------- */
(functionreveal(){
vartargets=document.querySelectorAll('.release-card, .staff-card, .info-card');
if(!targets.length)return;
if(reduceMotion||!('IntersectionObserver'inwindow)){
targets.forEach(function(el){el.classList.add('is-revealed');});
return;
}
targets.forEach(function(el){el.classList.add('will-reveal');});
vario=newIntersectionObserver(function(entries){
entries.forEach(function(entry){
if(!entry.isIntersecting)return;
entry.target.classList.add('is-revealed');
io.unobserve(entry.target);
});
},{rootMargin: '0px 0px -8% 0px',threshold: 0.05});
targets.forEach(function(el){io.observe(el);});
})();
/* ---------- Close staff modals with Escape ---------- */
(functionmodalEscape(){
if(!document.querySelector('.staff-modal'))return;
document.addEventListener('keydown',function(e){
if(e.key==='Escape'&&location.hash&&location.hash!=='#close'){
location.hash='#close';
}
});
})();
/* ---------- Count the hero stats up from zero ----------
Runs after heroStats has written the real figures, so the target is
whatever is in the DOM — derived or hard-coded, with any '+' suffix
preserved. Fires once per page load, when the stats scroll into view. */
(functionheroStatsCountUp(){
varstats=document.querySelectorAll('.hero-stats dt');
if(!stats.length||reduceMotion)return;
varDURATION=1800;
functionanimate(el){
vartext=el.textContent.trim();
vartarget=parseInt(text,10);
if(isNaN(target))return;
// Keep everything that isn't the leading number, e.g. the '+' in '100+'.
varsuffix=text.slice(String(target).length);
varstart;
el.textContent='0'+suffix;
functionframe(now){
if(start===undefined)start=now;
vart=Math.min((now-start)/DURATION,1);
// easeOutCubic: quick off the mark, settling gently onto the final value.
vareased=1-Math.pow(1-t,3);
el.textContent=Math.round(eased*target)+suffix;
if(t<1)requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
if(!('IntersectionObserver'inwindow)){
stats.forEach(animate);
return;
}
vario=newIntersectionObserver(function(entries){
entries.forEach(function(entry){
if(!entry.isIntersecting)return;
io.unobserve(entry.target);
animate(entry.target);
});
},{threshold: 0.5});
stats.forEach(function(el){io.observe(el);});
})();
/* ---------- Archive filter (index only) ---------- */
(functionarchive(){
varroot=document.querySelector('[data-archive]');
if(!root)return;
varcards=Array.from(document.querySelectorAll('.release-card'));
varpillBox=root.querySelector('.filter-pills');
varsearch=root.querySelector('#archive-search');
varcountEl=root.querySelector('#archive-count');
varempty=document.querySelector('.archive-empty');
if(!cards.length||!pillBox)return;
functiontitleOf(card){
vart=card.querySelector('.releasetitle');
returnt ? t.textContent.trim() : '';
}
functionbodyOf(card){
vard=card.querySelector('.releasedescription');
returnd ? d.textContent.toLowerCase() : '';
}
// Cache the searchable text once rather than re-reading the DOM per keystroke.
cards.forEach(function(card){
vartitle=titleOf(card);
varm=title.match(/\b(20\d{2})\b/);
card.dataset.year=card.classList.contains('exclusive-card') ? '2026' : (m ? m[1] : '');
card.dataset.haystack=(title+' '+bodyOf(card)).toLowerCase();
// Normalize exclusive attribute so checks are predictable. Do NOT mark any cards here.
card.dataset.exclusive=card.dataset.exclusive==='true' ? 'true' : '';
});
varyears=Array.from(newSet(cards.map(function(c){returnc.dataset.year;})))
.filter(Boolean)
.sort(function(a,b){returnb-a;});
varactiveYear='all';
varactiveexclusive='all';// 'all' or 'only'
functionmakePill(value,label){
varb=document.createElement('button');
b.type='button';
b.className='filter-pill';
b.dataset.year=value;
b.textContent=label;
b.setAttribute('aria-pressed',String(value==='all'));
if(value==='all')b.classList.add('is-active');
b.addEventListener('click',function(){
activeYear=value;
pillBox.querySelectorAll('.filter-pill').forEach(function(p){
// Only toggle year pills here — exclusive pill handled separately below.
if(p.dataset.year!==undefined&&p.dataset.year!==''){
varon=p===b;
p.classList.toggle('is-active',on);
p.setAttribute('aria-pressed',String(on));
}
});
apply();
});
returnb;
}
// Year pills (unchanged behaviour)
pillBox.appendChild(makePill('all','All years'));
years.forEach(function(y){pillBox.appendChild(makePill(y,y));});
// exclusive pill — same visual style as year pills
varexclusivePill=document.createElement('button');
exclusivePill.type='button';
exclusivePill.className='filter-pill';
exclusivePill.dataset.exclusive='only';
exclusivePill.textContent='Exclusive';
exclusivePill.setAttribute('aria-pressed','false');
exclusivePill.addEventListener('click',function(){
// Toggle between showing only exclusives and showing all
activeexclusive=activeexclusive==='only' ? 'all' : 'only';
exclusivePill.classList.toggle('is-active',activeexclusive==='only');
exclusivePill.setAttribute('aria-pressed',String(activeexclusive==='only'));
apply();
});
// Keep the same styling as the other pills; slight separation so it doesn't
// visually merge with the year buttons (optional but subtle).
exclusivePill.style.backgroundColor='var(--gold-soft)';
pillBox.appendChild(exclusivePill);
functionapply(){
varq=(search&&search.value||'').trim().toLowerCase();
varshown=0;
cards.forEach(function(card){
varyearOk=(activeYear==='all'||card.dataset.year===activeYear);
vartextOk=(!q||card.dataset.haystack.indexOf(q)!==-1);
varisexclusiveCard=card.dataset.exclusive==='true';
varexclusiveOk=isexclusiveCard ? (activeexclusive==='only') : (activeexclusive==='all');
// exclusive cards are intentionally hidden until the user primes the filter by
// selecting the exclusive pill; once selected, year filtering continues to work.
if(isexclusiveCard&&activeexclusive!=='only'){
exclusiveOk=false;
}
varok=yearOk&&textOk&&exclusiveOk;
card.hidden=!ok;
if(ok)shown++;
});
if(countEl){
countEl.textContent=shown+(shown===1 ? ' issue' : ' issues');
}
if(empty)empty.hidden=shown!==0;
}
if(search){
vart;
search.addEventListener('input',function(){
clearTimeout(t);
t=setTimeout(apply,120);
});
search.addEventListener('keydown',function(e){
if(e.key==='Escape'){search.value='';apply();}
});
}
apply();
})();
})();