Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
84 lines
4.9 KiB
JavaScript
84 lines
4.9 KiB
JavaScript
(() => {
|
||
const ja = document.documentElement.lang.startsWith('ja');
|
||
const t = (a,b) => ja ? a : b;
|
||
const city = document.querySelector('[data-city-map-dialog]');
|
||
const cityButton = document.querySelector('[data-city-map-launch]');
|
||
const launch = document.querySelector('[data-calendar-upcoming-launch]');
|
||
const modal = document.querySelector('[data-calendar-upcoming-dialog]');
|
||
const notification = document.querySelector('[data-notification-dialog]');
|
||
const notificationButton = document.querySelector('[data-notification-launch]');
|
||
// Keep the visual/tab order City → Calendar → Notifications → Profile.
|
||
if (launch && notificationButton) notificationButton.before(launch);
|
||
const bind = (dialog, button, close) => {
|
||
if (!dialog || !button) return;
|
||
dialog.setAttribute('aria-modal','true');
|
||
button.setAttribute('aria-haspopup','dialog');
|
||
dialog.querySelector(close)?.addEventListener('click',()=>dialog.close());
|
||
dialog.addEventListener('click', e => {
|
||
if (e.target !== dialog) return;
|
||
const r=dialog.getBoundingClientRect();
|
||
if(e.clientX<r.left || e.clientX>r.right || e.clientY<r.top || e.clientY>r.bottom) dialog.close();
|
||
});
|
||
};
|
||
bind(city,cityButton,'[data-city-map-close]');
|
||
if(cityButton && city) cityButton.addEventListener('click',()=>{
|
||
const frame=city.querySelector('iframe');
|
||
if(!frame.getAttribute('src')) frame.src=frame.dataset.src;
|
||
if(!city.open) city.showModal();
|
||
});
|
||
if(notification) {
|
||
notification.setAttribute('aria-modal','true');
|
||
notification.querySelector('h2').textContent=t('通知','Notifications');
|
||
notification.querySelector('footer a').textContent=t('すべての通知を見る','View all notifications');
|
||
notificationButton?.setAttribute('aria-label',t('通知','Notifications'));
|
||
notificationButton?.setAttribute('title',t('通知','Notifications'));
|
||
}
|
||
bind(modal,launch,'[data-calendar-upcoming-close]');
|
||
if(!launch || !modal) return;
|
||
const timezone=modal.dataset.timezone||'UTC';
|
||
const dateFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-US',{timeZone:timezone,year:'numeric',month:'2-digit',day:'2-digit'});
|
||
const timeFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-US',{timeZone:timezone,hour:'2-digit',minute:'2-digit',hourCycle:'h23'});
|
||
const fullFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-US',{timeZone:timezone,dateStyle:'medium',timeStyle:'short'});
|
||
const parts=value=>Object.fromEntries(new Intl.DateTimeFormat('en-CA',{timeZone:timezone,year:'numeric',month:'2-digit',day:'2-digit'}).formatToParts(value).filter(p=>p.type!=='literal').map(p=>[p.type,p.value]));
|
||
let pending;
|
||
modal.addEventListener('close',()=>pending?.abort());
|
||
launch.addEventListener('click',async()=>{
|
||
if(modal.open) return;
|
||
modal.showModal();
|
||
const list=modal.querySelector('[data-calendar-upcoming-list]');
|
||
const status=modal.querySelector('[data-calendar-upcoming-status]');
|
||
list.replaceChildren(); status.textContent=t('読み込み中…','Loading…');
|
||
pending=new AbortController();
|
||
const request=pending;
|
||
const date=new Date(),civil=parts(date);
|
||
const today=[civil.year,civil.month,civil.day].join('-');
|
||
try {
|
||
const r=await fetch('/_/api/v1/extension/organizer.calendar/upcoming?date='+today,{credentials:'same-origin',headers:{Accept:'application/json'},signal:request.signal,cache:'no-store'});
|
||
if(!r.ok) throw Error('unavailable');
|
||
const data=await r.json();
|
||
if(request.signal.aborted) return;
|
||
status.textContent=data.events.length?'':t('この期間の予定はありません。','No events in this period.');
|
||
const fragment=document.createDocumentFragment();
|
||
for(const event of data.events) {
|
||
const a=document.createElement('a'); a.className='calendar-upcoming-item'; a.href=event.href;
|
||
const day=document.createElement('time');day.className='calendar-upcoming-date';
|
||
const start=document.createElement('time');start.className='calendar-upcoming-time';
|
||
const title=document.createElement('strong');title.textContent=event.summary||t('無題','Untitled');
|
||
if(event.all_day) {
|
||
const end=new Date(Date.parse(event.end)-86400000).toISOString().slice(0,10);
|
||
day.textContent=event.start.slice(0,10).replaceAll('-','/');
|
||
start.textContent=t('終日','All day');
|
||
a.title=event.calendar+' · '+event.start.slice(0,10)+(end===event.start.slice(0,10)?'':' – '+end);
|
||
} else {
|
||
const begins=new Date(event.start),ends=new Date(event.end);
|
||
day.textContent=dateFormat.format(begins);
|
||
start.textContent=timeFormat.format(begins);
|
||
a.title=event.calendar+' · '+fullFormat.format(begins)+' – '+fullFormat.format(ends);
|
||
}
|
||
a.append(day,start,title);fragment.append(a);
|
||
}
|
||
list.append(fragment);
|
||
} catch(e) { if(!request.signal.aborted) status.textContent=t('予定を取得できませんでした。','Events unavailable.'); }
|
||
});
|
||
})();
|