2018-09-11 05:10:33 +08:00
|
|
|
!function(e,n,o,t){"use strict";n=void 0!==n&&n.Math==Math?n:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.embed=function(o){var r,a=e(this),i=a.selector||"",c=(new Date).getTime(),l=[],d=arguments[0],u="string"==typeof d,s=[].slice.call(arguments,1);return a.each(function(){var m,p=e.isPlainObject(o)?e.extend(!0,{},e.fn.embed.settings,o):e.extend({},e.fn.embed.settings),f=p.selector,h=p.className,b=p.sources,g=p.error,v=p.metadata,y=p.namespace,w=p.templates,P="."+y,C="module-"+y,E=(e(n),e(this)),U=(E.find(f.placeholder),E.find(f.icon),E.find(f.embed)),j=this,S=E.data(C);m={initialize:function(){m.debug("Initializing embed"),m.determine.autoplay(),m.create(),m.bind.events(),m.instantiate()},instantiate:function(){m.verbose("Storing instance of module",m),S=m,E.data(C,m)},destroy:function(){m.verbose("Destroying previous instance of embed"),m.reset(),E.removeData(C).off(P)},refresh:function(){m.verbose("Refreshing selector cache"),E.find(f.placeholder),E.find(f.icon),U=E.find(f.embed)},bind:{events:function(){m.has.placeholder()&&(m.debug("Adding placeholder events"),E.on("click"+P,f.placeholder,m.createAndShow).on("click"+P,f.icon,m.createAndShow))}},create:function(){m.get.placeholder()?m.createPlaceholder():m.createAndShow()},createPlaceholder:function(e){var n=m.get.icon(),o=m.get.url();m.generate.embed(o);e=e||m.get.placeholder(),E.html(w.placeholder(e,n)),m.debug("Creating placeholder for embed",e,n)},createEmbed:function(n){m.refresh(),n=n||m.get.url(),U=e("<div/>").addClass(h.embed).html(m.generate.embed(n)).appendTo(E),p.onCreate.call(j,n),m.debug("Creating embed object",U)},changeEmbed:function(e){U.html(m.generate.embed(e))},createAndShow:function(){m.createEmbed(),m.show()},change:function(e,n,o){m.debug("Changing video to ",e,n,o),E.data(v.source,e).data(v.id,n),o?E.data(v.url,o):E.removeData(v.url),m.has.embed()?m.changeEmbed():m.create()},reset:function(){m.debug("Clearing embed and showing placeholder"),m.remove.active(),m.remove.embed(),m.showPlaceholder(),p.onReset.call(j)},show:function(){m.debug("Showing embed"),m.set.active(),p.onDisplay.call(j)},hide:function(){m.debug("Hiding embed"),m.showPlaceholder()},showPlaceholder:function(){m.debug("Showing placeholder image"),m.remove.active(),p.onPlaceholderDisplay.call(j)},get:{id:function(){return p.id||E.data(v.id)},placeholder:function(){return p.placeholder||E.data(v.placeholder)},icon:function(){return p.icon?p.icon:E.data(v.icon)!==t?E.data(v.icon):m.determine.icon()},source:function(e){return p.source?p.source:E.data(v.source)!==t?E.data(v.source):m.determine.source()},type:function(){var e=m.get.source();return b[e]!==t&&b[e].type},url:function(){return p.url?p.url:E.data(v.url)!==t?E.data(v.url):m.determine.url()}},determine:{autoplay:function(){m.should.autoplay()&&(p.autoplay=!0)},source:function(n){var o=!1;return(n=n||m.get.url())&&e.each(b,function(e,t){if(-1!==n.search(t.domain))return o=e,!1}),o},icon:function(){var e=m.get.source();return b[e]!==t&&b[e].icon},url:function(){var e,n=p.id||E.data(v.id),o=p.source||E.data(v.source);return(e=b[o]!==t&&b[o].url.replace("{id}",n))&&E.data(v.url,e),e}},set:{active:function(){E.addClass(h.active)}},remove:{active:function(){E.removeClass(h.active)},embed:function(){U.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){m.debug("Generating embed html");var n,o,t=m.get.source();return(e=m.get.url(e))?(o=m.generate.parameters(t),n=w.iframe(e,o)):m.error(g.noURL,E),n},parameters:function(n,o){var r=b[n]&&b[n].parameters!==t?b[n].parameters(p):{};return(o=o||p.parameters)&&(r=e.extend({},r,o)),r=p.onEmbed(r),m.encode.parameters(r)}},has:{embed:function(){return U.length>0},placeholder:function(){return p.placeholder||E.data(v.placeholder)}},should:{autoplay:function(){return"auto"===p.autoplay?p.placeholder||E.data(v.placeholder)!==t:p.autoplay}},is:{video:function(){return"video"==m.get.type()}},setting:function(n,o){if(m.debug("Changing setting",n
|