14 lines
3.9 KiB
JavaScript
14 lines
3.9 KiB
JavaScript
(()=>{const destination=document.querySelector('.writer3-destination'),reader=document.querySelector('.manuscript-reader');
|
|
if(destination?.dataset.bookId){const key='plotdirector.reviewChapter.v1.'+destination.dataset.layoutOwner+'.'+destination.dataset.bookId;try{if(reader?.dataset.chapterId)sessionStorage.setItem(key,reader.dataset.chapterId);const selected=sessionStorage.getItem(key),valid=(destination.dataset.reviewChapters||'').split(',');if(selected&&valid.includes(selected))for(const link of document.querySelectorAll('a[href]')){const url=new URL(link.href,location.href);if(url.origin===location.origin&&url.pathname.toLowerCase()==='/writer/review'&&url.searchParams.get('bookId')===destination.dataset.bookId&&!url.searchParams.has('chapterId')){url.searchParams.set('chapterId',selected);link.href=url;}}}catch{}}
|
|
for(const root of document.querySelectorAll('[data-workspace-tabs]'))for(const button of root.querySelectorAll('[data-tab]'))button.addEventListener('click',()=>{for(const b of root.querySelectorAll('[data-tab]'))b.setAttribute('aria-selected',String(b===button));for(const panel of root.querySelectorAll('[data-pane]'))panel.hidden=panel.dataset.pane!==button.dataset.tab;});
|
|
document.querySelector('[data-session-filter]')?.addEventListener('input',event=>{for(const row of document.querySelectorAll('[data-session-history] article'))row.hidden=!row.textContent.toLowerCase().includes(event.target.value.toLowerCase());});
|
|
const editorial=document.querySelector('.writer21-editorial');
|
|
if(editorial){const toggles=[...document.querySelectorAll('[data-editorial-toggle]')],panels=toggles.map(button=>document.getElementById(button.dataset.editorialToggle));let narrow=null,wideVisible=panels.map(panel=>!panel.hidden);
|
|
const sync=()=>toggles.forEach((button,index)=>button.setAttribute('aria-expanded',String(!panels[index].hidden)));
|
|
const close=index=>{if(panels[index].contains(document.activeElement))toggles[index].focus({preventScroll:true});panels[index].hidden=true;sync();};
|
|
for(const [index,button] of toggles.entries()){button.setAttribute('aria-controls',panels[index].id);button.addEventListener('click',()=>{const show=panels[index].hidden;if(narrow&&show)panels.forEach((panel,other)=>{if(other!==index)close(other);});panels[index].hidden=!show;if(!narrow)wideVisible=panels.map(panel=>!panel.hidden);sync();if(narrow&&show)panels[index].querySelector('button,textarea,input,select')?.focus({preventScroll:true});});const closeButton=document.createElement('button');closeButton.type='button';closeButton.className='btn btn-outline-secondary';closeButton.dataset.editorialClose='';closeButton.textContent='Close '+(index===0?'chapter':'scene')+' notes';closeButton.addEventListener('click',()=>close(index));panels[index].prepend(closeButton);panels[index].addEventListener('keydown',event=>{if(event.key==='Escape'&&narrow){event.preventDefault();close(index);}});}
|
|
let frame=0;const measure=()=>{frame=0;const box=editorial.getBoundingClientRect(),next=box.width<1050,sticky=parseFloat(getComputedStyle(destination||editorial).getPropertyValue('--writer-sticky-top'))||12;editorial.style.setProperty('--editorial-note-top',Math.max(sticky,Math.min(box.top,Math.max(sticky,innerHeight-200)))+'px');editorial.style.setProperty('--editorial-left',Math.max(8,box.left)+'px');editorial.style.setProperty('--editorial-right',Math.max(8,innerWidth-box.right)+'px');editorial.style.setProperty('--editorial-width',Math.max(240,box.width-16)+'px');if(next!==narrow){if(next){if(narrow===false)wideVisible=panels.map(panel=>!panel.hidden);panels.forEach((_,index)=>close(index));}else panels.forEach((panel,index)=>panel.hidden=!wideVisible[index]);narrow=next;editorial.dataset.noteOverlay=String(next);sync();}};
|
|
const schedule=()=>{if(!frame)frame=requestAnimationFrame(measure);};new ResizeObserver(schedule).observe(editorial);window.addEventListener('resize',schedule);window.addEventListener('scroll',schedule,{passive:true});measure();
|
|
}
|
|
})();
|