tools/site/assets/reading.js
const pageToc=document.querySelector('.toc');if(pageToc){const narrow=window.matchMedia('(max-width:800px)');const syncToc=()=>{pageToc.open=!narrow.matches;};syncToc();narrow.addEventListener('change',syncToc);}
"use strict";
document.querySelectorAll('.print-page').forEach(button=>button.addEventListener('click',()=>window.print()));
if(document.querySelector('.mermaid')&&window.mermaid){window.mermaid.initialize({startOnLoad:false,securityLevel:'strict',theme:'base',themeVariables:{fontFamily:'Segoe UI,Arial,sans-serif',primaryColor:'#f5f6f3',primaryTextColor:'#18374b',primaryBorderColor:'#92713b',lineColor:'#586773',secondaryColor:'#e9eff1',tertiaryColor:'#fff'},flowchart:{htmlLabels:false,useMaxWidth:true}});window.mermaid.run({querySelector:'.mermaid'}).catch(()=>{document.querySelectorAll('.decision-figure figcaption').forEach(c=>c.textContent='The diagram could not render. Expand the source below to read the full decision flow.');});}
const searchInput=document.getElementById('document-search');
if(searchInput){let indexPromise;let generation=0;const status=document.getElementById('search-status'),results=document.getElementById('search-results'),browse=document.getElementById('browse-documents');const load=()=>indexPromise||(indexPromise=fetch(searchInput.dataset.searchIndex).then(r=>{if(!r.ok)throw Error('unavailable');return r.json();}));searchInput.addEventListener('input',async()=>{const turn=++generation;const q=searchInput.value.trim().toLowerCase();if(!q){results.hidden=true;browse.hidden=false;status.textContent=browse.querySelectorAll('li').length+' documents';return;}try{const data=await load();if(turn!==generation)return;const terms=q.split(/\s+/);const ranked=data.map(d=>{const title=(d.title+' '+d.project).toLowerCase();const text=(title+' '+d.text).toLowerCase();return {d,score:terms.every(t=>text.includes(t))?terms.reduce((n,t)=>n+(title.includes(t)?10:1),0):0};}).filter(x=>x.score).sort((a,b)=>b.score-a.score);results.replaceChildren();for(const {d} of ranked.slice(0,30)){const li=document.createElement('li'),a=document.createElement('a'),strong=document.createElement('strong'),span=document.createElement('span');a.href=d.url;strong.textContent=d.title;span.textContent=d.project+' · '+d.kind;a.append(strong,span);li.append(a);results.append(li);}browse.hidden=true;results.hidden=false;status.textContent=ranked.length+' matching documents'+(ranked.length>30?' · showing first 30':'');}catch{status.textContent='Search is unavailable. Browse the complete document list below.';browse.hidden=false;results.hidden=true;}});}
Source and scopePublished from CM-2026/tools/site/assets/reading.js at revision 78bcf6107b11. Full source text is retained; HTML presentation does not establish independent clinical review. See authorship, provenance and review records.