MediaWiki:Common.js: mudanças entre as edições

Sem resumo de edição
Sem resumo de edição
Linha 21: Linha 21:
//Js para  autoplay e mostrar  preview  
//Js para  autoplay e mostrar  preview  


$(function() {
$('.video-teste-final').each(function() {
    $('.video-preview').each(function() {
    var $container = $(this);
        var $container = $(this);
    var videoId = $container.data('video-id');
        var videoId = $container.data('video-id');
    var thumbUrl = 'https://img.youtube.com/vi/' + videoId + '/maxresdefault.jpg';
        var $img = $container.find('img');
   
         var player;
    // Coloca a imagem de fundo via JS para não brigar com o parser do Wiki
    $container.css({
        'background-image': 'url(' + thumbUrl + ')',
        'background-size': 'cover',
         'background-position': 'center'
    }).find('.aviso-teste').hide();


        $container.mouseenter(function() {
    $container.on('mouseenter', function() {
            // Cria o iframe do YouTube dinamicamente
        var iframe = $('<iframe>', {
            var iframe = $('<iframe>', {
            src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&mute=1&controls=0&modestbranding=1',
                src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&mute=1&controls=0&modestbranding=1',
            width: '100%', height: '100%', frameborder: 0,
                width: $img.attr('width'),
            allow: 'autoplay; encrypted-media',
                height: $img.attr('height'),
             style: 'position:absolute; top:0; left:0; pointer-events:none;'
                frameborder: 0,
                allow: 'autoplay; encrypted-media'
             });
 
            $img.hide();
            $container.append(iframe);
        });
 
        $container.mouseleave(function() {
            // Remove o iframe e volta a imagem original
            $container.find('iframe').remove();
            $img.show();
        });
       
        // Opcional: Clique para ir ao vídeo real no YouTube
        $container.click(function() {
            window.open('https://www.youtube.com/watch?v=' + videoId, '_blank');
         });
         });
        $container.append(iframe);
    }).on('mouseleave', function() {
        $container.find('iframe').remove();
     });
     });
});
});
console.log("Teste de Hover Ativado!");