(function($) { $.fn.wpShowerResponsiveVideos = function() { if (this.length == 0) return this; if (this.length > 1) { this.each(function() { $(this).wpShowerResponsiveVideos(); }); return this; } var plugin = { el: this }; function getRatio(video) { var width = video.attr('width'); var height = video.attr('height'); if (typeof width !== 'undefined' && width !== false && typeof height !== 'undefined' && height !== false) { var ratio = parseInt(height) / parseInt(width) * 100; return ratio.toFixed(2); } return 0; } var videos = ['iframe', 'object', 'embed', '.responsive-video']; var items = []; var item = false; var ratio = 0; for (var i = 0; i < videos.length; i++) { items = plugin.el.find(videos[i]); if (items.length !== 0) { items.each(function() { item = $(this); ratio = getRatio(item); if (ratio !== 0) { item.parent().css({ 'position': 'relative', 'overflow': 'hidden', 'padding-bottom': ratio + '%', 'height': 0 }); item.css({ 'position': 'absolute', 'top': 0, 'left': 0, 'width': '100%', 'height': '100%' }); } }); } } return this; }; })(jQuery);