forked from saadan/embed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.easyembed.min.js
1 lines (1 loc) · 1.72 KB
/
jquery.easyembed.min.js
1
!function(t,e,o){t.fn.easyEmbed=function(o){var i=this,a=/iPad|iPhone|iPod/.test(navigator.userAgent),n=i.data("easy-embed").split(":"),r=t.extend({id:i.data("id")||n[1]||"ScMzIvxBSi4",provider:i.data("provider")||n[0]||"youtube",width:i.data("width")||16,height:i.data("height")||9,controls:i.data("controls")||!1,showinfo:i.data("showinfo")||!1,color:i.data("color")||"00adef",title:i.data("title")||!1,byline:i.data("byline")||!1,portrait:i.data("portrait")||!1},o),d=function(e){switch(r.provider.toLowerCase()){case"youtube":var o="//img.youtube.com/vi/"+r.id+"/",i=["maxresdefault","hqdefault"];!function a(){var n=o+i[0]+".jpg";t("<img/>").attr("src",n).on("load",function(){120!=this.width&&90!=this.height?e(n):(i.shift(),a())})}();break;case"vimeo":t.get("https://vimeo.com/api/oembed.json?url=http://vimeo.com/"+r.id,function(t){e(t.thumbnail_url)})}},c=function(){switch(r.provider.toLowerCase()){case"youtube":return"//youtube.com/embed/"+r.id+"?rel=0&autoplay=1&controls="+(r.controls+0)+"&showinfo="+(r.showinfo+0);case"vimeo":return"//player.vimeo.com/video/"+r.id+"?autoplay=1&color="+r.color+"&title="+(r.title+0)+"&byline="+(r.byline+0)+"&portrait="+(r.controls+0)}},s=function(t){i.css("background","black url("+t+") 50% 50% / cover no-repeat")},u=function(){i.css("height",i.width()/r.width*r.height)},l=function(){i.html(t("<iframe>").attr("src",c()).attr("width","100%").attr("height","100%").attr("frameborder",0).attr("allowfullscreen",1)),i.addClass("playing-video")};return u(),t(e).resize(function(){u()}),a?l():(d(function(t){s(t)}),i.find("*").addBack().click(function(){l()})),this},t(o).ready(function(){t("[data-easy-embed]").length>0&&t("[data-easy-embed]").each(function(){t(this).easyEmbed()})})}(jQuery,window,document);