| 1 |
var epdofitvids = epdofitvids || function ($) |
| 2 |
{ |
| 3 |
|
| 4 |
$.fn.fitVidsEP = function (options) |
| 5 |
{ |
| 6 |
if (_EPYT_.epresponsiveselector.constructor !== Array) |
| 7 |
{ |
| 8 |
_EPYT_.epresponsiveselector = JSON.parse(_EPYT_.epresponsiveselector); |
| 9 |
} |
| 10 |
var settings = { |
| 11 |
customSelector: null |
| 12 |
}; |
| 13 |
|
| 14 |
if (!document.getElementById('fit-vids-style')) |
| 15 |
{ |
| 16 |
|
| 17 |
var styleContainer = document.createElement('style'), |
| 18 |
ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0], |
| 19 |
cssStyles = '.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%;}'; |
| 20 |
|
| 21 |
styleContainer.className = 'fit-vids-style'; |
| 22 |
styleContainer.id = 'fit-vids-style'; |
| 23 |
styleContainer.textContent = cssStyles; |
| 24 |
|
| 25 |
ref.parentNode.insertBefore(styleContainer, ref); |
| 26 |
|
| 27 |
} |
| 28 |
|
| 29 |
if (options) |
| 30 |
{ |
| 31 |
$.extend(settings, options); |
| 32 |
} |
| 33 |
|
| 34 |
return this.each(function () |
| 35 |
{ |
| 36 |
// var selectors = [ |
| 37 |
// "iframe[src*='youtube.com']", |
| 38 |
// "iframe[src*='youtube-nocookie.com']" |
| 39 |
// ]; |
| 40 |
var selectors = _EPYT_.epresponsiveselector; |
| 41 |
|
| 42 |
if (settings.customSelector) |
| 43 |
{ |
| 44 |
selectors.push(settings.customSelector); |
| 45 |
} |
| 46 |
|
| 47 |
var $allVideos = $(this).find(selectors.join(',')); |
| 48 |
$allVideos = $allVideos.not("object object"); // SwfObj conflict patch |
| 49 |
|
| 50 |
$allVideos.each(function () |
| 51 |
{ |
| 52 |
var $this = $(this); |
| 53 |
if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length |
| 54 |
|| $this.parent('.fluid-width-video-wrapper').length |
| 55 |
|| $this.css('position') === 'absolute' |
| 56 |
) |
| 57 |
{ |
| 58 |
return; |
| 59 |
} |
| 60 |
if ($this.is('[data-origwidth]:not([width])')) |
| 61 |
{ |
| 62 |
$this.attr('width', $this.data('origwidth')); |
| 63 |
} |
| 64 |
if ($this.is('[data-origheight]:not([height])')) |
| 65 |
{ |
| 66 |
$this.attr('height', $this.data('origheight')); |
| 67 |
} |
| 68 |
|
| 69 |
var height = (this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10)))) ? parseInt($this.attr('height'), 10) : $this.height(), |
| 70 |
width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), |
| 71 |
aspectRatio = height / width; |
| 72 |
|
| 73 |
if (!$this.attr('id')) |
| 74 |
{ |
| 75 |
var videoID = 'fitvid' + Math.floor(Math.random() * 999999); |
| 76 |
$this.attr('id', videoID); |
| 77 |
} |
| 78 |
|
| 79 |
var attrWidth = $this.attr('width'); |
| 80 |
var attrHeight = $this.attr('height'); |
| 81 |
if ($this.parent().hasClass('epyt-video-wrapper')) |
| 82 |
{ |
| 83 |
try |
| 84 |
{ |
| 85 |
$this.parent().addClass('fluid-width-video-wrapper').attr('style', 'padding-top: ' + (aspectRatio * 100) + "% !important;"); |
| 86 |
$this.removeAttr('height').removeAttr('width'); |
| 87 |
|
| 88 |
setTimeout(function () |
| 89 |
{ |
| 90 |
var resizeEvent = null; |
| 91 |
if (typeof (Event) === 'function') |
| 92 |
{ |
| 93 |
resizeEvent = new Event('resize'); |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
resizeEvent = document.createEvent('Event'); |
| 98 |
resizeEvent.initEvent('resize', true, true); |
| 99 |
} |
| 100 |
window.dispatchEvent(resizeEvent); |
| 101 |
}, 10); |
| 102 |
|
| 103 |
setTimeout(function () |
| 104 |
{ |
| 105 |
if (parseInt($this.parent().css('padding-top'), 10) > $this.height() + 20) |
| 106 |
{ |
| 107 |
$this.parent().removeClass('fluid-width-video-wrapper').css('padding-top', ''); |
| 108 |
$this.attr('width', attrWidth); |
| 109 |
$this.attr('height', attrHeight); |
| 110 |
} |
| 111 |
}, 100); |
| 112 |
} |
| 113 |
catch (wraperr) |
| 114 |
{ |
| 115 |
} |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
var fwvwrap = document.createElement('div'); |
| 120 |
fwvwrap.className = 'fluid-width-video-wrapper'; |
| 121 |
try |
| 122 |
{ |
| 123 |
$this.wrap(fwvwrap).parent('.fluid-width-video-wrapper').attr('style', 'padding-top: ' + (aspectRatio * 100) + "% !important;"); |
| 124 |
$this.removeAttr('height').removeAttr('width'); |
| 125 |
|
| 126 |
setTimeout(function () |
| 127 |
{ |
| 128 |
var resizeEvent = null; |
| 129 |
if (typeof (Event) === 'function') |
| 130 |
{ |
| 131 |
resizeEvent = new Event('resize'); |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
resizeEvent = document.createEvent('Event'); |
| 136 |
resizeEvent.initEvent('resize', true, true); |
| 137 |
} |
| 138 |
window.dispatchEvent(resizeEvent); |
| 139 |
}, 10); |
| 140 |
|
| 141 |
setTimeout(function () |
| 142 |
{ |
| 143 |
if (parseInt($this.parent().css('padding-top'), 10) > $this.height() + 20) |
| 144 |
{ |
| 145 |
$this.parent().removeClass('fluid-width-video-wrapper').css('padding-top', ''); |
| 146 |
$this.attr('width', attrWidth); |
| 147 |
$this.attr('height', attrHeight); |
| 148 |
} |
| 149 |
}, 100); |
| 150 |
} |
| 151 |
catch (wraperr) |
| 152 |
{ |
| 153 |
} |
| 154 |
} |
| 155 |
}); |
| 156 |
}); |
| 157 |
}; |
| 158 |
|
| 159 |
$(document).ready(function () |
| 160 |
{ |
| 161 |
$("body").fitVidsEP(); |
| 162 |
|
| 163 |
$(document).ajaxSuccess(function (e, xhr, settings) |
| 164 |
{ |
| 165 |
if (xhr && xhr.responseText && xhr.responseText.indexOf('<iframe ') !== -1) |
| 166 |
{ |
| 167 |
$("body").fitVidsEP(); |
| 168 |
} |
| 169 |
}); |
| 170 |
}); |
| 171 |
return true; |
| 172 |
}; |
| 173 |
|
| 174 |
try |
| 175 |
{ |
| 176 |
epdofitvids(window.jQuery); |
| 177 |
} |
| 178 |
catch (err) |
| 179 |
{ |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|