(() => { 'use strict'; const initSchedule = () => { const listContainer = document.querySelector('#panel-schedule .schedule-list'); const items = document.querySelectorAll('.schedule-item'); const noEventMessage = document.getElementById('no-event-message'); if (!listContainer || !items.length) { if (noEventMessage) noEventMessage.style.display = 'block'; return; } const now = new Date(); const todayString = [ now.getFullYear(), String(now.getMonth() + 1).padStart(2, '0'), String(now.getDate()).padStart(2, '0') ].join('.'); const sorted = Array.from(items).sort((a, b) => { const dateA = (a.getAttribute('data-date') || '').trim(); const dateB = (b.getAttribute('data-date') || '').trim(); return dateA.localeCompare(dateB); }); let displayCount = 0; const fragment = document.createDocumentFragment(); for (let i = 0; i < sorted.length; i++) { const item = sorted[i]; const itemDate = (item.getAttribute('data-date') || '').trim(); if (itemDate >= todayString && displayCount < 3) { item.style.display = 'block'; fragment.appendChild(item); // 表示する分だけ移動 displayCount++; } else { // 表示しない不要な要素は削除して軽量化 item.remove(); } } // 3. 最後にまとめてコンテナに追加(描画の負荷を最小限にする) if (displayCount > 0) { listContainer.appendChild(fragment); if (noEventMessage) noEventMessage.style.display = 'none'; } else { if (noEventMessage) noEventMessage.style.display = 'block'; } }; const initDateLabels = () => { document.querySelectorAll('.js-date').forEach((dateEl) => { const rawText = dateEl.textContent.trim(); const parts = rawText.split('.'); if (parts.length < 3) return; const [year, month, day] = parts; dateEl.innerHTML = `

${year}.

${month}.${day}

`; }); }; const initVideoItems = () => { document.querySelectorAll('.video-item').forEach((item) => { const type = item.getAttribute('data-type'); if (type === 'YouTube') { item.classList.add('youtube'); const el = item.querySelector('.type-youtube'); if (el) el.style.display = 'block'; } else if (type === 'CL') { item.classList.add('cl'); const el = item.querySelector('.type-cl'); if (el) el.style.display = 'block'; } }); }; const initBgVideo = () => { const video = document.querySelector('.bg-video'); if (!video) return; const tryPlay = () => { if (video.paused) video.play().catch(() => { }); }; const isIOS = /iP(hone|ad|od)/.test(navigator.userAgent) || (navigator.userAgent.includes('Mac') && 'ontouchend' in document); if (!isIOS) { video.addEventListener('loadedmetadata', tryPlay, { once: true }); tryPlay(); setTimeout(() => { if (video.readyState < 1) loadBlob(); }, 3000); return; } const startWhenIdle = (fn) => { const run = () => { if ('requestIdleCallback' in window) { requestIdleCallback(fn, { timeout: 3000 }); } else { setTimeout(fn, 500); } }; if (document.readyState === 'complete') run(); else window.addEventListener('load', run, { once: true }); }; startWhenIdle(loadBlob); function loadBlob() { fetch('assets/img/black-bg.mp4') .then((res) => { if (!res.ok) throw new Error('HTTP ' + res.status); return res.blob(); }) .then((blob) => { video.src = URL.createObjectURL(blob); video.load(); video.addEventListener('loadedmetadata', tryPlay, { once: true }); }) .catch(() => { }); } }; document.addEventListener('DOMContentLoaded', () => { initSchedule(); initDateLabels(); initVideoItems(); initBgVideo(); }); })();