Blame view

backend/makest/js/plugins/video/responsible-video.js 714 Bytes
d1f8bd40   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  $(function() {
      var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed"),
          $fluidEl = $("figure");
  
      $allVideos.each(function() {
          $(this)
              // jQuery .data does not work on object/embed elements
              .attr('data-aspectRatio', this.height / this.width)
              .removeAttr('height')
              .removeAttr('width');
      });
      $(window).resize(function() {
          var newWidth = $fluidEl.width();
          $allVideos.each(function() {
              var $el = $(this);
              $el
                  .width(newWidth)
                  .height(newWidth * $el.attr('data-aspectRatio'));
          });
      }).resize();
  });