1/*jshint browser:true */ 2/*! 3 * FitVids 1.1 4 * 5 * Copyright 2013, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com 6 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ 7 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/ 8 * 9 */ 10 11(function ($) { 12 'use strict'; 13 14 $.fn.fitVids = function (options) { 15 var settings = { 16 customSelector: null, 17 ignore: null, 18 }; 19 20 if (!document.getElementById('fit-vids-style')) { 21 // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js 22 var head = document.head || document.getElementsByTagName('head')[0]; 23 var css = 24 '.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%;}'; 25 var div = document.createElement('div'); 26 div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>'; 27 head.appendChild(div.childNodes[1]); 28 } 29 30 if (options) { 31 $.extend(settings, options); 32 } 33 34 return this.each(function () { 35 var selectors = [ 36 'iframe[src*="player.vimeo.com"]', 37 'iframe[src*="youtube.com"]', 38 'iframe[src*="youtube-nocookie.com"]', 39 'iframe[src*="kickstarter.com"][src*="video.html"]', 40 'object', 41 'embed', 42 ]; 43 44 if (settings.customSelector) { 45 selectors.push(settings.customSelector); 46 } 47 48 var ignoreList = '.fitvidsignore'; 49 50 if (settings.ignore) { 51 ignoreList = ignoreList + ', ' + settings.ignore; 52 } 53 54 var $allVideos = $(this).find(selectors.join(',')); 55 $allVideos = $allVideos.not('object object'); // SwfObj conflict patch 56 $allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video. 57 58 $allVideos.each(function () { 59 var $this = $(this); 60 if ($this.parents(ignoreList).length > 0) { 61 return; // Disable FitVids on this video. 62 } 63 if ( 64 (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length) || 65 $this.parent('.fluid-width-video-wrapper').length 66 ) { 67 return; 68 } 69 if ( 70 !$this.css('height') && 71 !$this.css('width') && 72 (isNaN($this.attr('height')) || isNaN($this.attr('width'))) 73 ) { 74 $this.attr('height', 9); 75 $this.attr('width', 16); 76 } 77 var height = 78 this.tagName.toLowerCase() === 'object' || 79 ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) 80 ? parseInt($this.attr('height'), 10) 81 : $this.height(), 82 width = !isNaN(parseInt($this.attr('width'), 10)) 83 ? parseInt($this.attr('width'), 10) 84 : $this.width(), 85 aspectRatio = height / width; 86 if (!$this.attr('name')) { 87 var videoName = 'fitvid' + $.fn.fitVids._count; 88 $this.attr('name', videoName); 89 $.fn.fitVids._count++; 90 } 91 $this 92 .wrap('<div class="fluid-width-video-wrapper"></div>') 93 .parent('.fluid-width-video-wrapper') 94 .css('padding-top', aspectRatio * 100 + '%'); 95 $this.removeAttr('height').removeAttr('width'); 96 }); 97 }); 98 }; 99 100 // Internal counter for unique video names. 101 $.fn.fitVids._count = 0; 102 103 // Works with either jQuery or Zepto 104})(window.jQuery || window.Zepto);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.