feat: the Site has a videos area and a floating product video (front 4)
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 4m18s
Build and deploy / Publish images (push) Successful in 1m5s

The home lists the six DTF videos with their titles and state; a card opens
a modal player. A product page gets a muted, captioned 30 s floating video
when its file is configured. The files themselves are still to be recorded;
until then the cards say "Em produção".
This commit is contained in:
Cauê Faleiros
2026-11-06 12:44:33 -03:00
parent b10eeead6e
commit 7e22262280
4 changed files with 187 additions and 3 deletions

147
web/site-videos.js Normal file
View File

@@ -0,0 +1,147 @@
/* Site DTF — vídeos da categoria DTF e o vídeo flutuante por produto (frente 4).
O espaço e o player ficam prontos agora; os seis arquivos entram quando a
Dropstar gravar. Para publicar um vídeo, coloque o MP4/WebM em web/videos/
e preencha `src` (e, se houver, `captions`) abaixo. `product` liga o vídeo
ao modo do produto: file, avulsa, uvfile ou uv. */
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 (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 strip: six cards. A card without a file says it is being made
// instead of opening a broken player.
(function videosSection() {
const grid = document.getElementById('videosGrid');
if (!grid) return;
for (const video of VIDEOS) {
const card = document.createElement('button');
card.type = 'button';
card.className = 'videoCard';
card.dataset.video = video.id;
if (!video.src) card.dataset.soon = '1';
const play = document.createElement('span');
play.className = 'vcPlay';
play.textContent = video.src ? '▶' : '…';
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 = video.src ? 'Assistir · 30 s' : 'Em produção';
card.append(play, title, desc, note);
if (!video.src) {
card.setAttribute('aria-disabled', 'true');
} else {
card.addEventListener('click', () => openVideo(video));
}
grid.append(card);
}
})();
// The category player, opened from a card.
let videoModal = null;
function openVideo(video) {
if (!videoModal) {
videoModal = document.createElement('div');
videoModal.className = 'videoModal';
videoModal.hidden = true;
videoModal.innerHTML = '<div class="vmBox"><button type="button" class="vmClose" aria-label="Fechar vídeo">×</button></div>';
videoModal.addEventListener('click', event => {
if (event.target === videoModal || event.target.closest('.vmClose')) closeVideo();
});
document.body.append(videoModal);
}
const box = videoModal.querySelector('.vmBox');
box.querySelectorAll('video').forEach(el => el.remove());
const player = videoElement(video, {controls: true});
box.append(player);
videoModal.hidden = false;
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');
}
// 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 = 'Mudo · com legenda · 30 s';
label.append(title, desc);
floating.append(player, close, label);
document.body.append(floating);
player.play().catch(() => {});
}
addEventListener('dtf-page-changed', syncFloatingVideo);
syncFloatingVideo();