/* Site DTF — the public catalog is filled by videos published in Gestão. */ const VIDEOS = [ {id: 'subindo', title: 'Subindo a arte pelo celular', desc: 'Do primeiro toque ao preço, sem instalar nada.', product: null, src: null, captions: null}, {id: 'nota', title: 'O que é a nota da arte — e o que ela não é', desc: 'A nota explica o arquivo; ela não muda o preço.', product: 'file', src: null, captions: null}, {id: 'png', title: 'Por que PNG com fundo transparente', desc: 'O que acontece com JPG e por que o branco sai no filme.', product: 'uvfile', src: null, captions: null}, {id: 'avulsas', title: 'Montando artes avulsas e vendo a folha ao vivo', desc: 'A montagem peça por peça, com o encaixe e a metragem.', product: 'avulsa', src: null, captions: null}, {id: 'retirada', title: 'Retirada em Franca em 24 h', desc: 'O balcão, o recibo e o que levar.', product: null, src: null, captions: null}, {id: 'sala', title: 'A sala às 3 da manhã', desc: 'Por onde o pedido passa até virar filme.', product: null, src: null, captions: null}, ]; function videoElement(video, {controls = false} = {}) { const el = document.createElement('video'); el.src = video.src; el.muted = true; el.playsInline = true; el.preload = 'metadata'; if (controls) el.controls = true; if (controls) el.tabIndex = 0; if (video.captions) { const track = document.createElement('track'); track.kind = 'captions'; track.label = 'Português'; track.srclang = 'pt'; track.src = video.captions; track.default = true; el.append(track); } return el; } // The category shows only videos with a published file. function videosSection() { const grid = document.getElementById('videosGrid'); if (!grid) return; const published=VIDEOS.filter(video=>video.src); document.getElementById('videos').hidden=!published.length; grid.replaceChildren(); for (const video of published) { const card = document.createElement('button'); card.type = 'button'; card.className = 'videoCard'; card.dataset.video = video.id; const play = document.createElement('span'); play.className = 'vcPlay'; play.textContent = '▶'; const title = document.createElement('b'); title.textContent = video.title; const desc = document.createElement('span'); desc.textContent = video.desc; const note = document.createElement('em'); note.textContent = 'Assistir · 30 s'; card.append(play, title, desc, note); card.addEventListener('click', () => openVideo(video, card)); grid.append(card); } } videosSection(); // The category player, opened from a card. let videoModal = null; let videoReturnFocus = null; function openVideo(video, trigger=document.activeElement) { videoReturnFocus = trigger; if (!videoModal) { videoModal = document.createElement('div'); videoModal.className = 'videoModal'; videoModal.setAttribute('role', 'dialog'); videoModal.setAttribute('aria-modal', 'true'); videoModal.setAttribute('aria-label', 'Vídeo: '+video.title); videoModal.hidden = true; videoModal.innerHTML = '
'; videoModal.addEventListener('click', event => { if (event.target === videoModal || event.target.closest('.vmClose')) closeVideo(); }); videoModal.addEventListener('keydown', event => { if (event.key === 'Escape') { event.preventDefault(); closeVideo(); return; } if (event.key !== 'Tab') return; const focusable = [...videoModal.querySelectorAll('button,video[controls]')]; const first=focusable[0], last=focusable[focusable.length-1]; if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }); document.body.append(videoModal); } const box = videoModal.querySelector('.vmBox'); box.querySelectorAll('video').forEach(el => el.remove()); const player = videoElement(video, {controls: true}); player.addEventListener('timeupdate', () => { if (player.currentTime >= 30) player.pause(); }); box.append(player); videoModal.hidden = false; videoModal.setAttribute('aria-label', 'Vídeo: '+video.title); videoModal.querySelector('.vmClose').focus(); player.play().catch(() => {}); document.documentElement.classList.add('videoAberto'); } function closeVideo() { if (!videoModal) return; videoModal.querySelectorAll('video').forEach(el => { el.pause(); el.removeAttribute('src'); el.load(); }); videoModal.hidden = true; document.documentElement.classList.remove('videoAberto'); videoReturnFocus?.focus(); videoReturnFocus = null; } // A floating, muted 30 s video on each product page. It only appears when the // product has a recorded video; until then the page stays clean. let floating = null, floatingId = null; function videoForProduct() { if (document.documentElement.dataset.rota !== 'produto') return null; return VIDEOS.find(video => video.src && video.product === modo) || null; } function syncFloatingVideo() { const video = videoForProduct(); if (!video) { if (floating) { floating.remove(); floating = null; floatingId = null; } return; } if (floating && floatingId === video.id) return; if (floating) { floating.remove(); floating = null; } floatingId = video.id; floating = document.createElement('div'); floating.className = 'videoFloat'; const close = document.createElement('button'); close.type = 'button'; close.className = 'vfClose'; close.setAttribute('aria-label', 'Fechar vídeo'); close.textContent = '×'; close.addEventListener('click', () => { floating.remove(); floating = null; floatingId = null; }); const player = videoElement(video); player.autoplay = true; player.loop = false; // 30 segundos no máximo, como o PDF pede. player.addEventListener('timeupdate', () => { if (player.currentTime >= 30) player.pause(); }); const label = document.createElement('div'); label.className = 'vfLabel'; const title = document.createElement('b'); title.textContent = video.title; const desc = document.createElement('span'); desc.textContent = video.captions ? 'Mudo · com legenda · 30 s' : 'Mudo · 30 s'; label.append(title, desc); floating.append(player, close, label); document.body.append(floating); player.play().catch(() => {}); } addEventListener('dtf-page-changed', syncFloatingVideo); syncFloatingVideo(); window.siteVideosReady=fetch('/api/site/videos').then(response=>response.ok?response.json():null).then(data=>{ for(const published of data?.videos||[]){ const video=VIDEOS.find(item=>item.id===published.id); if(video){video.src=published.src;video.captions=published.captions;video.product=published.product;} } videosSection(); syncFloatingVideo(); }).catch(()=>{});