1 /*jshint browser:true */
6 * Copyright 2017, Chris Coyier + Dave Rupert + Ghost Foundation
7 * This is an unofficial release, ported by John O'Nolan
8 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
9 * Released under the MIT license
17 $.fn
.fitVids = function( options
) {
23 if(!document
.getElementById('fit-vids-style')) {
24 // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js
25 var head
= document
.head
|| document
.getElementsByTagName('head')[0];
26 var css
= '.fluid-width-video-container{flex-grow: 1;width:100%;}.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}';
27 var div
= document
.createElement("div");
28 div
.innerHTML
= '<p>x</p><style id="fit-vids-style">' + css
+ '</style>';
29 head
.appendChild(div
.childNodes
[1]);
33 $.extend( settings
, options
);
36 return this.each(function(){
38 'iframe[src*="player.vimeo.com"]',
39 'iframe[src*="youtube.com"]',
40 'iframe[src*="youtube-nocookie.com"]',
41 'iframe[src*="kickstarter.com"][src*="video.html"]',
46 if (settings
.customSelector
) {
47 selectors
.push(settings
.customSelector
);
50 var ignoreList
= '.fitvidsignore';
53 ignoreList
= ignoreList
+ ', ' + settings
.ignore
;
56 var $allVideos
= $(this).find(selectors
.join(','));
57 $allVideos
= $allVideos
.not('object object'); // SwfObj conflict patch
58 $allVideos
= $allVideos
.not(ignoreList
); // Disable FitVids on this video.
60 $allVideos
.each(function(){
62 if($this.parents(ignoreList
).length
> 0) {
63 return; // Disable FitVids on this video.
65 if (this.tagName
.toLowerCase() === 'embed' && $this.parent('object').length
|| $this.parent('.fluid-width-video-wrapper').length
) { return; }
66 if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width'))))
68 $this.attr('height', 9);
69 $this.attr('width', 16);
71 var height
= ( this.tagName
.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(),
72 width
= !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(),
73 aspectRatio
= height
/ width
;
74 if(!$this.attr('name')){
75 var videoName
= 'fitvid' + $.fn
.fitVids
._count
;
76 $this.attr('name', videoName
);
77 $.fn
.fitVids
._count
++;
79 $this.wrap('<div class="fluid-width-video-container"><div class="fluid-width-video-wrapper"></div></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio
* 100)+'%');
80 $this.removeAttr('height').removeAttr('width');
85 // Internal counter for unique video names.
86 $.fn
.fitVids
._count
= 0;
88 // Works with either jQuery or Zepto
89 })( window
.jQuery
|| window
.Zepto
);