Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | // One generic controller for every .viewer. Reads the develop/pr/highlight // frames off data-* attributes, swaps the <img> src in place on click, and // runs Blink as a setInterval that alternates develop and pr. Press-and-hold // on the image peeks at develop (release restores the active mode). (function () { var BLINK_MS = 500; document.querySelectorAll('.viewer').forEach(function (v) { var img = v.querySelector('img.frame'); var frames = { develop: v.getAttribute('data-develop'), pr: v.getAttribute('data-pr'), highlight: v.getAttribute('data-highlight'), }; var current = v.getAttribute('data-default') || 'pr'; var timer = null; function stopBlink() { if (timer) { clearInterval(timer); timer = null; } var b = v.querySelector('button.blink'); if (b) b.classList.remove('blinking'); } function setActiveButton(mode) { v.querySelectorAll('button.mode').forEach(function (btn) { btn.classList.toggle('active', btn.getAttribute('data-mode') === mode); }); } function show(mode) { if (frames[mode]) { img.src = frames[mode]; current = mode; } } v.querySelectorAll('button.mode').forEach(function (btn) { btn.addEventListener('click', function () { var mode = btn.getAttribute('data-mode'); if (mode === 'blink') { if (timer) { stopBlink(); setActiveButton(current); show(current); return; } // Start blinking: alternate develop <-> pr, leave the static mode // buttons un-highlighted so it's clear blink is the active state. setActiveButton(null); btn.classList.add('blinking'); var toggle = false; img.src = frames.develop; timer = setInterval(function () { toggle = !toggle; img.src = toggle ? frames.pr : frames.develop; }, BLINK_MS); return; } stopBlink(); setActiveButton(mode); show(mode); }); }); // Press-and-hold the image to peek develop; release restores current mode. function peek(e) { e.preventDefault(); if (frames.develop) img.src = frames.develop; } function release() { if (!timer) show(current); } img.addEventListener('mousedown', peek); img.addEventListener('touchstart', peek, { passive: false }); window.addEventListener('mouseup', release); img.addEventListener('touchend', release); // Init. img.src = frames[current] || frames.pr || frames.develop || frames.highlight; }); // Space bar peeks develop on the viewer nearest the top of the viewport — // a quick keyboard equivalent of press-and-hold for the page you're reading. var spaceTarget = null; document.addEventListener('keydown', function (e) { if (e.code !== 'Space' || e.repeat) return; var vs = Array.prototype.slice.call(document.querySelectorAll('.viewer')).filter(function (v) { return !v.closest('[hidden]'); }); spaceTarget = vs.find(function (v) { var top = v.getBoundingClientRect().top; return top > -200 && top < window.innerHeight; }); if (spaceTarget) { e.preventDefault(); var d = spaceTarget.getAttribute('data-develop'); var i = spaceTarget.querySelector('img.frame'); if (d) { spaceTarget._restore = i.src; i.src = d; } } }); document.addEventListener('keyup', function (e) { if (e.code !== 'Space' || !spaceTarget) return; var i = spaceTarget.querySelector('img.frame'); if (spaceTarget._restore) i.src = spaceTarget._restore; spaceTarget = null; }); // Filters: the component filter and "Changed pages only" both hide sections; a page shows if neither hides it. var filter = document.getElementById('component-filter'); var changedOnly = document.getElementById('changed-only'); var sticky = document.querySelector('.sticky-top'); var sections = Array.prototype.slice.call(document.querySelectorAll('main section')); var pos = document.getElementById('page-pos'); var prevBtn = document.getElementById('prev-page'); var nextBtn = document.getElementById('next-page'); var visible = function () { return sections.filter(function (sec) { return !sec.hidden; }); }; // The page being read: the last visible one whose top has reached the bottom of the sticky header. var currentIndex = function (list) { var line = sticky.offsetHeight + 16; var idx = 0; list.forEach(function (sec, i) { if (sec.getBoundingClientRect().top <= line) idx = i; }); return idx; }; var updatePager = function () { var list = visible(); var i = currentIndex(list); pos.textContent = list.length ? i + 1 + ' / ' + list.length : '0 / 0'; prevBtn.disabled = i <= 0; nextBtn.disabled = i >= list.length - 1; }; var applyFilter = function () { sections.forEach(function (sec) { var comps = (sec.getAttribute('data-components') || '').split('|'); var byComponent = !!filter.value && comps.indexOf(filter.value) === -1; var byStatus = changedOnly.checked && sec.classList.contains('clean'); sec.hidden = byComponent || byStatus; }); updatePager(); }; var step = function (dir) { var list = visible(); var target = list[currentIndex(list) + dir]; if (target) target.scrollIntoView({ behavior: 'smooth' }); }; // Section titles must land just below the sticky header, whatever height it has. var setOffset = function () { sections.forEach(function (sec) { sec.style.scrollMarginTop = sticky.offsetHeight + 8 + 'px'; }); }; setOffset(); window.addEventListener('resize', function () { setOffset(); updatePager(); }); var ticking = false; window.addEventListener('scroll', function () { if (ticking) return; ticking = true; requestAnimationFrame(function () { ticking = false; updatePager(); }); }); filter.addEventListener('change', applyFilter); changedOnly.addEventListener('change', applyFilter); prevBtn.addEventListener('click', function () { step(-1); }); nextBtn.addEventListener('click', function () { step(1); }); // Left / right arrows step through pages, unless a control has focus (no single-letter keys, WCAG 2.1.4). document.addEventListener('keydown', function (e) { if (e.ctrlKey || e.metaKey || e.altKey) return; if ( /^(SELECT|TEXTAREA)$/.test(e.target.tagName) || (e.target.tagName === 'INPUT' && e.target.type !== 'checkbox') ) return; if (e.key === 'ArrowRight') step(1); else if (e.key === 'ArrowLeft') step(-1); else return; e.preventDefault(); }); applyFilter(); // Jump dropdowns: unhide the chosen page if a filter hides it, go to it, // then reset so the same entry can be picked again. document.querySelectorAll('nav select:not(#component-filter)').forEach(function (sel) { sel.addEventListener('change', function () { if (!sel.value) return; var target = document.getElementById(sel.value); if (target && target.hidden) { filter.value = ''; changedOnly.checked = false; applyFilter(); } if (target) target.scrollIntoView({ behavior: 'smooth' }); sel.value = ''; }); }); })(); |