You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.5 KiB
1 line
7.5 KiB
6 years ago
|
!function(E,U,e,j){"use strict";U=void 0!==U&&U.Math==Math?U:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),E.fn.embed=function(h){var b,g=E(this),v=g.selector||"",y=(new Date).getTime(),w=[],P=h,C="string"==typeof P,D=[].slice.call(arguments,1);return g.each(function(){var c,t=E.isPlainObject(h)?E.extend(!0,{},E.fn.embed.settings,h):E.extend({},E.fn.embed.settings),e=t.selector,n=t.className,r=t.sources,l=t.error,a=t.metadata,o=t.namespace,i=t.templates,d="."+o,u="module-"+o,s=(E(U),E(this)),m=(s.find(e.placeholder),s.find(e.icon),s.find(e.embed)),p=this,f=s.data(u);c={initialize:function(){c.debug("Initializing embed"),c.determine.autoplay(),c.create(),c.bind.events(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of module",c),f=c,s.data(u,c)},destroy:function(){c.verbose("Destroying previous instance of embed"),c.reset(),s.removeData(u).off(d)},refresh:function(){c.verbose("Refreshing selector cache"),s.find(e.placeholder),s.find(e.icon),m=s.find(e.embed)},bind:{events:function(){c.has.placeholder()&&(c.debug("Adding placeholder events"),s.on("click"+d,e.placeholder,c.createAndShow).on("click"+d,e.icon,c.createAndShow))}},create:function(){c.get.placeholder()?c.createPlaceholder():c.createAndShow()},createPlaceholder:function(e){var n=c.get.icon(),o=c.get.url();c.generate.embed(o);e=e||c.get.placeholder(),s.html(i.placeholder(e,n)),c.debug("Creating placeholder for embed",e,n)},createEmbed:function(e){c.refresh(),e=e||c.get.url(),m=E("<div/>").addClass(n.embed).html(c.generate.embed(e)).appendTo(s),t.onCreate.call(p,e),c.debug("Creating embed object",m)},changeEmbed:function(e){m.html(c.generate.embed(e))},createAndShow:function(){c.createEmbed(),c.show()},change:function(e,n,o){c.debug("Changing video to ",e,n,o),s.data(a.source,e).data(a.id,n),o?s.data(a.url,o):s.removeData(a.url),c.has.embed()?c.changeEmbed():c.create()},reset:function(){c.debug("Clearing embed and showing placeholder"),c.remove.data(),c.remove.active(),c.remove.embed(),c.showPlaceholder(),t.onReset.call(p)},show:function(){c.debug("Showing embed"),c.set.active(),t.onDisplay.call(p)},hide:function(){c.debug("Hiding embed"),c.showPlaceholder()},showPlaceholder:function(){c.debug("Showing placeholder image"),c.remove.active(),t.onPlaceholderDisplay.call(p)},get:{id:function(){return t.id||s.data(a.id)},placeholder:function(){return t.placeholder||s.data(a.placeholder)},icon:function(){return t.icon?t.icon:s.data(a.icon)!==j?s.data(a.icon):c.determine.icon()},source:function(e){return t.source?t.source:s.data(a.source)!==j?s.data(a.source):c.determine.source()},type:function(){var e=c.get.source();return r[e]!==j&&r[e].type},url:function(){return t.url?t.url:s.data(a.url)!==j?s.data(a.url):c.determine.url()}},determine:{autoplay:function(){c.should.autoplay()&&(t.autoplay=!0)},source:function(o){var t=!1;return(o=o||c.get.url())&&E.each(r,function(e,n){if(-1!==o.search(n.domain))return t=e,!1}),t},icon:function(){var e=c.get.source();return r[e]!==j&&r[e].icon},url:function(){var e,n=t.id||s.data(a.id),o=t.source||s.data(a.source);return(e=r[o]!==j&&r[o].url.replace("{id}",n))&&s.data(a.url,e),e}},set:{active:function(){s.addClass(n.active)}},remove:{data:function(){s.removeData(a.id).removeData(a.icon).removeData(a.placeholder).removeData(a.source).removeData(a.url)},active:function(){s.removeClass(n.active)},embed:function(){m.empty()}},encode:{parameters:function(e){var n,o=[];for(n in e)o.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return o.join("&")}},generate:{embed:function(e){c.debug("Generating embed html");var n,o,t=c.get.source();return(e=c.get.url(e))?(o=c.generate.parameters(t),n=i.iframe(e,o)):c.error(l.noURL,s),n},parameters:function(e,n){var o=r[e]&&r[e].parameters!==j?r[e].parameters(t):{};return(n=n||t.parameters)&&(o=E.extend({},o,n)),o=t.onEmbed(o),c.encode.parameters(o)}},has:{embed:function(){return 0<m.length},placeholder:function(){return t.placeholder||s.data(a.placeholder)}},should:{autoplay:function(){return"auto"===t.autoplay?t.placeholder||s.data(a.placehold
|