video-bg.js (2181B)
1 (function ($) { 2 3 function getHandler() { 4 for (var id in wp.customHeader.handlers) { 5 var handle = wp.customHeader.handlers[id]; 6 7 if (handle.settings) { 8 return handle; 9 } 10 11 } 12 } 13 14 function resizeVideo(videoElement, animate) { 15 var $videoElement = jQuery(videoElement); 16 17 18 var size = materialis_video_background.getVideoRect(); 19 $videoElement.css({ 20 width: Math.round(size.width), 21 "max-width": Math.round(size.width), 22 height: Math.round(size.height), 23 "opacity": 1, 24 "left": size.left 25 }); 26 27 if (animate === false) { 28 return; 29 } 30 31 32 } 33 34 window.addEventListener('resize', function () { 35 var videoElement = document.querySelector('video#wp-custom-header-video') || document.querySelector('iframe#wp-custom-header-video'); 36 if (videoElement) { 37 resizeVideo(videoElement); 38 materialis_video_background.resizePoster() 39 } 40 }); 41 42 43 jQuery(function () { 44 var videoElement = document.querySelector('video#wp-custom-header-video') || document.querySelector('iframe#wp-custom-header-video'); 45 if (videoElement) { 46 resizeVideo(videoElement, false); 47 } 48 }); 49 50 var __cpVideoElementFirstPlayed = false; 51 52 document.addEventListener('wp-custom-header-video-loaded', function () { 53 var videoElement = document.querySelector('video#wp-custom-header-video'); 54 55 if (videoElement) { 56 resizeVideo(videoElement); 57 return; 58 } 59 60 document.querySelector('#wp-custom-header').addEventListener('play', function () { 61 var iframeVideo = document.querySelector('iframe#wp-custom-header-video'); 62 var videoElement = document.querySelector('video#wp-custom-header-video') || iframeVideo; 63 64 if (videoElement && !__cpVideoElementFirstPlayed) { 65 __cpVideoElementFirstPlayed = true; 66 resizeVideo(videoElement); 67 } 68 69 var handler = getHandler(); 70 handler.play(); 71 72 }); 73 74 }); 75 76 77 })(jQuery);