1/* 2 * FitVids 1.0 3 * Copyright 2011, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com 4 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ 5 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/ 6 * Date: Thu Sept 01 18:00:00 2011 -0500 7 */ 8 9(function( $ ){ 10 11 $.fn.fitVids = function( options ) { 12 var settings = { 13 customSelector: null 14 } 15 16 var div = document.createElement('div'), 17 ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0]; 18 19 div.className = 'fit-vids-style'; 20 div.innerHTML = '­<style> \ 21 .fluid-width-video-wrapper { \ 22 width: 100%; \ 23 position: relative; \ 24 padding: 0; \ 25 } \ 26 \ 27 .fluid-width-video-wrapper iframe, \ 28 .fluid-width-video-wrapper object, \ 29 .fluid-width-video-wrapper embed { \ 30 position: absolute; \ 31 top: 0; \ 32 left: 0; \ 33 width: 100%; \ 34 height: 100%; \ 35 } \ 36 </style>'; 37 38 ref.parentNode.insertBefore(div,ref); 39 40 if ( options ) { 41 $.extend( settings, options ); 42 } 43 44 return this.each(function(){ 45 var selectors = [ 46 "iframe[src^='http://player.vimeo.com']", 47 "iframe[src^='http://www.youtube.com']", 48 "iframe[src^='https://www.youtube.com']", 49 "iframe[src^='http://www.kickstarter.com']", 50 "object", 51 "embed" 52 ]; 53 54 if (settings.customSelector) { 55 selectors.push(settings.customSelector); 56 } 57 58 var $allVideos = $(this).find(selectors.join(',')); 59 60 $allVideos.each(function(){ 61 var $this = $(this); 62 if (this.tagName.toLowerCase() == 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } 63 var height = this.tagName.toLowerCase() == 'object' ? $this.attr('height') : $this.height(), 64 aspectRatio = height / $this.width(); 65 if(!$this.attr('id')){ 66 var videoID = 'fitvid' + Math.floor(Math.random()*999999); 67 $this.attr('id', videoID); 68 } 69 $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%"); 70 $this.removeAttr('height').removeAttr('width'); 71 }); 72 }); 73 74 } 75})( jQuery );
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.