/*global jquery */ /*jshint multistr:true browser:true */ /*! * fitvids 1.0 * * copyright 2011, chris coyier - http://css-tricks.com + dave rupert - http://daverupert.com * credit to thierry koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ * released under the wtfpl license - http://sam.zoy.org/wtfpl/ * * date: thu sept 01 18:00:00 2011 -0500 */ (function( $ ){ "use strict"; $.fn.fitvids = function( options ) { var settings = { customselector: null }; if(!document.getelementbyid('fit-vids-style')) { var div = document.createelement('div'), ref = document.getelementsbytagname('base')[0] || document.getelementsbytagname('script')[0]; div.classname = 'fit-vids-style'; div.id = 'fit-vids-style'; div.style.display = 'none'; div.innerhtml = ''; ref.parentnode.insertbefore(div,ref); } if ( options ) { $.extend( settings, options ); } return this.each(function(){ var selectors = [ "iframe[src*='player.vimeo.com']", "iframe[src*='youtube.com']", "iframe[src*='youtube-nocookie.com']", "iframe[src*='kickstarter.com'][src*='video.html']", "object", "embed" ]; if (settings.customselector) { selectors.push(settings.customselector); } var $allvideos = $(this).find(selectors.join(',')); $allvideos = $allvideos.not("object object"); // swfobj conflict patch $allvideos.each(function(){ var $this = $(this); if (this.tagname.tolowercase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } var height = ( this.tagname.tolowercase() === 'object' || ($this.attr('height') && !isnan(parseint($this.attr('height'), 10))) ) ? parseint($this.attr('height'), 10) : $this.height(), width = !isnan(parseint($this.attr('width'), 10)) ? parseint($this.attr('width'), 10) : $this.width(), aspectratio = height / width; if(!$this.attr('id')){ var videoid = 'fitvid' + math.floor(math.random()*999999); $this.attr('id', videoid); } $this.wrap('
').parent('.fluid-width-video-wrapper').css('padding-top', (aspectratio * 100)+"%"); $this.removeattr('height').removeattr('width'); }); }); }; })( jquery );