Skip to content

Instantly share code, notes, and snippets.

@hayleyxyz
Created April 3, 2018 13:12
Show Gist options
  • Save hayleyxyz/a4c3871540379980e1891288f09935fe to your computer and use it in GitHub Desktop.
Save hayleyxyz/a4c3871540379980e1891288f09935fe to your computer and use it in GitHub Desktop.
embed: function(t, e) {
var i = function(t) {
var e = JSON.parse(t.data),
i = e.action,
n = e.data || {};
void 0 !== mediamanager[i] && mediamanager[i](n)
};
this.eventsSet || (void 0 !== window.addEventListener ? (window.removeEventListener("message", i), window.addEventListener("message", i)) : (window.detachEvent("onmessage", i), window.attachEvent("onmessage", i)), this.eventsSet = !0), void 0 === this.meta.pageurl && (this.meta.pageurl = window.location.href), void 0 === this.autoresize && (this.autoresize = !1), void 0 === this.aspect && (this.aspect = ["16", "6"]);
var n,
r = void 0 !== this.scroll && this.scroll;
this.id = void 0 === e || null === e ? this.id : e, "object" == typeof this.id && (this.meta.playlist = this.id.join("|"), this.id = this.id[0]), n = "video" === this.type ? void 0 === this.t ? this.URL + "video/" + this.id + "?" + this.serialize(this.meta) : this.URL + "video/" + this.id + "/" + this.t + "?" + this.serialize(this.meta) : void 0 === this.t ? this.URL + "audio/" + this.id + "?" + this.serialize(this.meta) : this.URL + "audio/" + this.id + "/" + this.t + "?" + this.serialize(this.meta), void 0 === this.type && (n = this.URL + "external/template/" + this.t + "?" + this.serialize(this.meta), this.id = this.t), this.iframeURL = n;
var o = document.createElement("IFRAME");
this.iframe = o, o.setAttribute("src", n), o.setAttribute("id", this.id), o.setAttribute("scrolling", r ? "yes" : "no"), o.setAttribute("frameBorder", 0), o.setAttribute("allowfullscreen", 1), o.setAttribute("webkitallowfullscreen", 1), o.setAttribute("mozallowfullscreen", 1), o.style.border = "none";
var s = this.findDiv(t, this.id);
if (void 0 !== this.w ? o.setAttribute("width", this.w) : o.setAttribute("width", s.style.width), void 0 !== this.h ? o.setAttribute("height", this.h) : o.setAttribute("height", s.style.height), void 0 !== this.h && void 0 !== this.w && "number" != typeof this.h && "number" != typeof this.w) {
var a = this.h.split("%"),
l = this.w.split("%");
parseInt(a[0]) >= 100 && a.length > 1 && parseInt(l[0]) >= 100 && l.length > 1 && !this.autoresize && (s.style.position = "fixed")
}
if (this.autoresize || (s.style.height = this.h, s.style.width = this.w), s.appendChild(o), this.autoresize) {
var c = this;
window.onresize = function() {
var t = s.clientWidth / c.aspect[0] * c.aspect[1];
s.style.height = t, o.setAttribute("height", t)
}, 0 === s.clientWidth ? setTimeout(function() {
window.onresize()
}, 1e3) : window.onresize()
}
},
findDiv: function(t, e) {
var i = void 0 === e || null === e ? this.id : e,
n = void 0 === t || null === t ? document.getElementById("mediamanager_" + e) : document.getElementById(t);
if (null === n) {
var r = document.getElementsByTagName("script"),
o = document.createElement("DIV");
o.setAttribute("id", "mediamanager_" + i), o.setAttribute("class", "mediamanager-embed mediamanager-video"), r[r.length - 1].parentNode.insertBefore(o, null), n = o
}
return n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment