PluginProbe
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades / 10.2
Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades v10.2
trunk 1.0 1.1 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 11.0 11.0.1 11.1 11.2 11.3 11.3.1 11.4 11.5 11.6 11.7 11.7.1 11.8 All 143 releases
youtube-embed-plus / scripts / _fitvids.js

_fitvids.js in Embed Plus for YouTube Gallery, Livestream and Lazy Loading with Facades 10.2, at scripts/_fitvids.js

76 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*global jQuery */
2 /*jshint multistr:true browser:true */
3 /*!
4 * FitVids 1.0.3
5 *
6 * Copyright 2013, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com
7 * Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
8 * Released under the WTFPL license - http://sam.zoy.org/wtfpl/
9 *
10 * Date: Thu Sept 01 18:00:00 2011 -0500
11 */
12
13 (function( $ ){
14
15 "use strict";
16
17 $.fn.fitVidsEP = function( options ) {
18 var settings = {
19 customSelector: null
20 };
21
22 if(!document.getElementById('fit-vids-style')) {
23
24 var div = document.createElement('div'),
25 ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0],
26 cssStyles = '&shy;<style>.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%;}</style>';
27
28 div.className = 'fit-vids-style';
29 div.id = 'fit-vids-style';
30 div.style.display = 'none';
31 div.innerHTML = cssStyles;
32
33 ref.parentNode.insertBefore(div,ref);
34
35 }
36
37 if ( options ) {
38 $.extend( settings, options );
39 }
40
41 return this.each(function(){
42 // var selectors = [
43 // "iframe[src*='youtube.com']",
44 // "iframe[src*='youtube-nocookie.com']"
45 // ];
46 var selectors = epresponsiveselector;
47
48 if (settings.customSelector) {
49 selectors.push(settings.customSelector);
50 }
51
52 var $allVideos = $(this).find(selectors.join(','));
53 $allVideos = $allVideos.not("object object"); // SwfObj conflict patch
54
55 $allVideos.each(function(){
56 var $this = $(this);
57 if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) {
58 return;
59 }
60 var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(),
61 width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(),
62 aspectRatio = height / width;
63 if(!$this.attr('id')){
64 var videoID = 'fitvid' + Math.floor(Math.random()*999999);
65 $this.attr('id', videoID);
66 }
67 $this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%");
68 $this.removeAttr('height').removeAttr('width');
69 });
70 });
71 };
72 // Works with either jQuery or Zepto
73 })( window.jQuery || window.Zepto );
74 $(document).ready(function(){
75 $("body").fitVidsEP();
76 });