| 1 |
var epdofitvids = epdofitvids || function ($) |
| 2 |
{ |
| 3 |
if (_EPYT_.epresponsiveselector.constructor !== Array) |
| 4 |
{ |
| 5 |
_EPYT_.epresponsiveselector = JSON.parse(_EPYT_.epresponsiveselector); |
| 6 |
} |
| 7 |
|
| 8 |
$.fn.fitVidsEP = function (options) { |
| 9 |
var settings = { |
| 10 |
customSelector: null |
| 11 |
}; |
| 12 |
|
| 13 |
if (!document.getElementById('fit-vids-style')) { |
| 14 |
|
| 15 |
var div = document.createElement('div'), |
| 16 |
ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0], |
| 17 |
cssStyles = '­<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>'; |
| 18 |
|
| 19 |
div.className = 'fit-vids-style'; |
| 20 |
div.id = 'fit-vids-style'; |
| 21 |
div.style.display = 'none'; |
| 22 |
div.innerHTML = cssStyles; |
| 23 |
|
| 24 |
ref.parentNode.insertBefore(div, ref); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
if (options) { |
| 29 |
$.extend(settings, options); |
| 30 |
} |
| 31 |
|
| 32 |
return this.each(function () { |
| 33 |
// var selectors = [ |
| 34 |
// "iframe[src*='youtube.com']", |
| 35 |
// "iframe[src*='youtube-nocookie.com']" |
| 36 |
// ]; |
| 37 |
var selectors = _EPYT_.epresponsiveselector; |
| 38 |
|
| 39 |
if (settings.customSelector) { |
| 40 |
selectors.push(settings.customSelector); |
| 41 |
} |
| 42 |
|
| 43 |
var $allVideos = $(this).find(selectors.join(',')); |
| 44 |
$allVideos = $allVideos.not("object object"); // SwfObj conflict patch |
| 45 |
|
| 46 |
$allVideos.each(function () { |
| 47 |
var $this = $(this); |
| 48 |
if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { |
| 49 |
return; |
| 50 |
} |
| 51 |
var height = (this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10)))) ? parseInt($this.attr('height'), 10) : $this.height(), |
| 52 |
width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), |
| 53 |
aspectRatio = height / width; |
| 54 |
if (!$this.attr('id')) { |
| 55 |
var videoID = 'fitvid' + Math.floor(Math.random() * 999999); |
| 56 |
$this.attr('id', videoID); |
| 57 |
} |
| 58 |
var fwvwrap = document.createElement('div'); |
| 59 |
fwvwrap.className = 'fluid-width-video-wrapper'; |
| 60 |
try { |
| 61 |
$this.wrap(fwvwrap).parent('.fluid-width-video-wrapper').attr('style', 'padding-top: ' + (aspectRatio * 100) + "% !important;"); |
| 62 |
$this.removeAttr('height').removeAttr('width'); |
| 63 |
} |
| 64 |
catch (wraperr) { |
| 65 |
} |
| 66 |
}); |
| 67 |
}); |
| 68 |
}; |
| 69 |
|
| 70 |
$(document).ready(function () { |
| 71 |
$("body").fitVidsEP(); |
| 72 |
|
| 73 |
$(document).ajaxSuccess(function (e, xhr, settings) { |
| 74 |
if (xhr.responseText.indexOf('<iframe ') !== -1) |
| 75 |
{ |
| 76 |
$("body").fitVidsEP(); |
| 77 |
} |
| 78 |
}); |
| 79 |
}); |
| 80 |
return true; |
| 81 |
}; |
| 82 |
|
| 83 |
try { |
| 84 |
epdofitvids(window.jQuery); |
| 85 |
} catch (err) { |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|