/*global jquery */ /*jshint browser:true */ /*! * fitvids 1.1 * * copyright 2013, 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/ * */ (function( $ ){ "use strict"; $.fn.fitvids = function( options ) { var settings = { customselector: null }; if(!document.getelementbyid('fit-vids-style')) { // appendstyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js var head = document.head || document.getelementsbytagname('head')[0]; var css = '.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%;}'; var div = document.createelement('div'); div.innerhtml = '

x

'; head.appendchild(div.childnodes[1]); } 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'); }); }); }; // works with either jquery or zepto })( window.jquery || window.zepto );