MediaWiki:Common.js: mudanças entre as edições
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 17: | Linha 17: | ||
} ); | } ); | ||
} )( jQuery ); | } )( jQuery ); | ||
//Js para autoplay e mostrar preview | |||
$(function() { | |||
$('.video-preview').each(function() { | |||
var $container = $(this); | |||
var videoId = $container.data('video-id'); | |||
var $img = $container.find('img'); | |||
var player; | |||
$container.mouseenter(function() { | |||
// Cria o iframe do YouTube dinamicamente | |||
var iframe = $('<iframe>', { | |||
src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&mute=1&controls=0&modestbranding=1', | |||
width: $img.attr('width'), | |||
height: $img.attr('height'), | |||
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'); | |||
}); | |||
}); | |||
}); | |||