osu-wayback/static/components/embed.min.js

1 line
7.6 KiB
JavaScript
Raw Normal View History

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