ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

video-bg.js (2214B)


      1 (function ($) {
      2 
      3     window.addEventListener('resize', function () {
      4         var videoElement = document.querySelector('video#wp-custom-header-video') || document.querySelector('iframe#wp-custom-header-video');
      5         if (videoElement) {
      6             videoSize(videoElement);
      7         }
      8     });
      9 
     10     function videoSize(videoElement, animate) {
     11         var $videoElement = jQuery(videoElement);
     12         var $header = jQuery(".header-homepage.cp-video-bg");
     13         var videoWidth = $header.width(),
     14             videoHeight = $header.height();
     15 
     16             videoWidth = Math.max(videoWidth,videoHeight);            
     17 
     18         if (videoWidth < videoHeight * 16 / 9) {
     19             videoWidth = 16 / 9 * videoHeight;
     20         } else {
     21             videoHeight = videoWidth * 9 / 16;
     22         }
     23 
     24         var marginLeft = -0.5 * (videoWidth - $header.width());
     25 
     26         $videoElement.css({
     27             width: videoWidth,
     28             height: videoHeight,
     29             "opacity": 1,
     30             "left": marginLeft
     31         });
     32 
     33         if (animate === false) {
     34             return;
     35         }
     36 
     37 
     38     }
     39 
     40     jQuery(function () {
     41         var videoElement = document.querySelector('video#wp-custom-header-video') || document.querySelector('iframe#wp-custom-header-video');
     42         if (videoElement) {
     43             videoSize(videoElement, false);
     44         }
     45     });
     46 
     47     __cpVideoElementFirstPlayed = false;
     48 
     49     document.addEventListener('wp-custom-header-video-loaded', function () {
     50         var videoElement = document.querySelector('video#wp-custom-header-video');
     51 
     52         if (videoElement) {
     53             videoSize(videoElement);
     54             return;
     55         }
     56 
     57         document.querySelector('#wp-custom-header').addEventListener('play', function () {
     58             var iframeVideo = document.querySelector('iframe#wp-custom-header-video');
     59             var videoElement = document.querySelector('video#wp-custom-header-video') || iframeVideo;
     60           
     61             if (videoElement && !__cpVideoElementFirstPlayed) {
     62                 __cpVideoElementFirstPlayed = true;
     63                 videoSize(videoElement);
     64             }
     65           
     66         });
     67 
     68     });
     69 })(jQuery);