Mudanças entre as edições de "Widget:Teste"

De Wiki Gla
Ir para navegação Ir para pesquisar
Linha 38: Linha 38:


     habilidades.forEach((hab, idx) => {
     habilidades.forEach((hab, idx) => {
        // Botão
         const btn = document.createElement('button');
         const btn = document.createElement('button');
         btn.className = 'skillbox-tab' + (idx === 0 ? ' active' : '');
         btn.className = 'skillbox-tab' + (idx === 0 ? ' active' : '');
Linha 45: Linha 44:
         tabsContainer.appendChild(btn);
         tabsContainer.appendChild(btn);


        // Vídeo
         const videoWrapper = document.createElement('div');
         const videoWrapper = document.createElement('div');
         videoWrapper.id = hab.id;
         videoWrapper.id = hab.id;
Linha 95: Linha 93:


     raw.remove();
     raw.remove();
    // Ajusta altura da descrição para evitar "salto"
    setTimeout(() => {
        let maxHeight = 0;
        const temp = document.createElement('div');
        temp.style.position = 'absolute';
        temp.style.visibility = 'hidden';
        temp.style.pointerEvents = 'none';
        temp.style.width = '100%';
        temp.style.fontFamily = window.getComputedStyle(descText).fontFamily;
        temp.style.fontSize = window.getComputedStyle(descText).fontSize;
        temp.style.lineHeight = window.getComputedStyle(descText).lineHeight;
        temp.style.fontWeight = window.getComputedStyle(descText).fontWeight;
        temp.style.boxSizing = 'border-box';
        temp.style.padding = window.getComputedStyle(descText).padding;
        document.body.appendChild(temp);
        habilidades.forEach(hab => {
            temp.innerHTML = hab.descricao.replace(/'''(.*?)'''/g, '<b>$1</b>');
            maxHeight = Math.max(maxHeight, temp.offsetHeight);
        });
        document.body.removeChild(temp);
        descText.style.minHeight = maxHeight + 'px';
    }, 50);
})();
})();
</script>
</script>

Edição das 01h25min de 24 de maio de 2025

<script> (function () {

   const raw = document.getElementById('skillbox-data');
   if (!raw) return;
   const habilidades = [];
   for (let i = 1; i <= 15; i++) {
       const nome = raw.dataset[`hab${i}`];
       const descricao = raw.dataset[`de${i}`];
       const videoFile = raw.dataset[`vid${i}`];
       if (!nome || !videoFile || videoFile.trim() === ) continue;
       habilidades.push({
           nome,
           descricao,
           videoUrl: `https://wiki.gla.com.br/index.php/Special:FilePath/${videoFile}`,
           id: `video${i}`
       });
   }
   const tabsContainer = document.getElementById('skill-tabs');
   const videoContainer = document.getElementById('skill-videos');
   const descText = document.getElementById('desc-text');
   habilidades.forEach((hab, idx) => {
       const btn = document.createElement('button');
       btn.className = 'skillbox-tab' + (idx === 0 ? ' active' : );
       btn.dataset.video = hab.id;
       btn.textContent = hab.nome;
       tabsContainer.appendChild(btn);
       const videoWrapper = document.createElement('div');
       videoWrapper.id = hab.id;
       videoWrapper.className = 'skillbox-video' + (idx === 0 ? ' active' : );
       const video = document.createElement('video');
       video.className = 'skillbox-video-element';
       video.controls = true;
       video.preload = 'auto';
       const source = document.createElement('source');
       source.src = hab.videoUrl;
       source.type = 'video/mp4';
       video.appendChild(source);
       videoWrapper.appendChild(video);
       videoContainer.appendChild(videoWrapper);
   });
   if (habilidades.length) {
       habilidades[0].descricao = habilidades[0].descricao.replace(/(.*?)/g, '$1');
       descText.innerHTML = habilidades[0].descricao;
   }
   const tabs = document.querySelectorAll('.skillbox-tab');
   const videos = document.querySelectorAll('.skillbox-video');
   tabs.forEach((tab, idx) => {
       tab.addEventListener('click', () => {
           tabs.forEach(t => t.classList.remove('active'));
           tab.classList.add('active');
           habilidades[idx].descricao = habilidades[idx].descricao.replace(/(.*?)/g, '$1');
           descText.innerHTML = habilidades[idx].descricao;
           videos.forEach(v => {
               const videoTag = v.querySelector('video');
               if (v.id === habilidades[idx].id) {
                   v.classList.add('active');
                   videoTag.currentTime = 0;
                   videoTag.play();
               } else {
                   v.classList.remove('active');
                   videoTag.pause();
               }
           });
       });
   });
   raw.remove();
   // Ajusta altura da descrição para evitar "salto"
   setTimeout(() => {
       let maxHeight = 0;
       const temp = document.createElement('div');
       temp.style.position = 'absolute';
       temp.style.visibility = 'hidden';
       temp.style.pointerEvents = 'none';
       temp.style.width = '100%';
       temp.style.fontFamily = window.getComputedStyle(descText).fontFamily;
       temp.style.fontSize = window.getComputedStyle(descText).fontSize;
       temp.style.lineHeight = window.getComputedStyle(descText).lineHeight;
       temp.style.fontWeight = window.getComputedStyle(descText).fontWeight;
       temp.style.boxSizing = 'border-box';
       temp.style.padding = window.getComputedStyle(descText).padding;
       document.body.appendChild(temp);
       habilidades.forEach(hab => {
           temp.innerHTML = hab.descricao.replace(/(.*?)/g, '$1');
           maxHeight = Math.max(maxHeight, temp.offsetHeight);
       });
       document.body.removeChild(temp);
       descText.style.minHeight = maxHeight + 'px';
   }, 50);

})(); </script>

<style> .skillbox-video {

 aspect-ratio: 16 / 9;
 opacity: 0;
 transition: opacity 0.2s ease;
 visibility: hidden;
 height: 0;
 overflow: hidden;
 position: absolute;
 width: 100%;
 max-width: 900px;
 margin: 0 auto;

}

.skillbox-video.active {

 position: static;
 opacity: 1;
 visibility: visible;
 height: auto;

} </style>