Created
February 22, 2016 12:48
-
-
Save cpnielsen/225350db7d01e5fe3614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(n) { | |
n.fn.fitVids = function(t) { | |
var i = { | |
customSelector: null | |
}, | |
r = document.createElement("div"), | |
u = document.getElementsByTagName("base")[0] || document.getElementsByTagName("script")[0]; | |
return r.className = "fit-vids-style", r.innerHTML = "­<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>", u.parentNode.insertBefore(r, u), t && n.extend(i, t), this.each(function() { | |
var t = ["iframe[src*='vimeo.com']", "iframe[src*='youtube.com']", "iframe[src*='23video.com']", "object", "embed"], | |
r; | |
i.customSelector && t.push(i.customSelector); | |
r = n(this).find(t.join(",")); | |
r.each(function() { | |
var t = n(this), | |
i; | |
if ((this.tagName.toLowerCase() != "embed" || !t.parent("object").length) && !t.parent(".fluid-width-video-wrapper").length) { | |
var r = this.tagName.toLowerCase() == "object" || t.attr("height") ? t.attr("height") : t.height(), | |
u = t.attr("width") ? t.attr("width") : t.width(), | |
f = r / u; | |
t.attr("id") || (i = "fitvid" + Math.floor(Math.random() * 999999), t.attr("id", i)); | |
t.wrap('<div class="fluid-width-video-wrapper"><\/div>').parent(".fluid-width-video-wrapper").css("padding-top", f * 100 + "%"); | |
t.removeAttr("height").removeAttr("width") | |
} | |
}) | |
}) | |
} | |
})(DONGEnergy.jQuery.$) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment