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 lines
7.5 KiB

!function(E,U,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 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,c=t.error,a=t.metadata,o=t.namespace,i=t.templates,l="."+o,d="module-"+o,u=(E(U),E(this)),s=(u.find(e.placeholder),u.find(e.icon),u.find(e.embed)),m=this,p=u.data(d),f={initialize:function(){f.debug("Initializing embed"),f.determine.autoplay(),f.create(),f.bind.events(),f.instantiate()},instantiate:function(){f.verbose("Storing instance of module",f),p=f,u.data(d,f)},destroy:function(){f.verbose("Destroying previous instance of embed"),f.reset(),u.removeData(d).off(l)},refresh:function(){f.verbose("Refreshing selector cache"),u.find(e.placeholder),u.find(e.icon),s=u.find(e.embed)},bind:{events:function(){f.has.placeholder()&&(f.debug("Adding placeholder events"),u.on("click"+l,e.placeholder,f.createAndShow).on("click"+l,e.icon,f.createAndShow))}},create:function(){f.get.placeholder()?f.createPlaceholder():f.createAndShow()},createPlaceholder:function(e){var n=f.get.icon(),o=f.get.url();f.generate.embed(o);e=e||f.get.placeholder(),u.html(i.placeholder(e,n)),f.debug("Creating placeholder for embed",e,n)},createEmbed:function(e){f.refresh(),e=e||f.get.url(),s=E("<div/>").addClass(n.embed).html(f.generate.embed(e)).appendTo(u),t.onCreate.call(m,e),f.debug("Creating embed object",s)},changeEmbed:function(e){s.html(f.generate.embed(e))},createAndShow:function(){f.createEmbed(),f.show()},change:function(e,n,o){f.debug("Changing video to ",e,n,o),u.data(a.source,e).data(a.id,n),o?u.data(a.url,o):u.removeData(a.url),f.has.embed()?f.changeEmbed():f.create()},reset:function(){f.debug("Clearing embed and showing placeholder"),f.remove.data(),f.remove.active(),f.remove.embed(),f.showPlaceholder(),t.onReset.call(m)},show:function(){f.debug("Showing embed"),f.set.active(),t.onDisplay.call(m)},hide:function(){f.debug("Hiding embed"),f.showPlaceholder()},showPlaceholder:function(){f.debug("Showing placeholder image"),f.remove.active(),t.onPlaceholderDisplay.call(m)},get:{id:function(){return t.id||u.data(a.id)},placeholder:function(){return t.placeholder||u.data(a.placeholder)},icon:function(){return t.icon?t.icon:u.data(a.icon)!==j?u.data(a.icon):f.determine.icon()},source:function(e){return t.source?t.source:u.data(a.source)!==j?u.data(a.source):f.determine.source()},type:function(){var e=f.get.source();return r[e]!==j&&r[e].type},url:function(){return t.url?t.url:u.data(a.url)!==j?u.data(a.url):f.determine.url()}},determine:{autoplay:function(){f.should.autoplay()&&(t.autoplay=!0)},source:function(o){var t=!1;return(o=o||f.get.url())&&E.each(r,function(e,n){if(-1!==o.search(n.domain))return t=e,!1}),t},icon:function(){var e=f.get.source();return r[e]!==j&&r[e].icon},url:function(){var e=t.id||u.data(a.id),n=t.source||u.data(a.source),o=r[n]!==j&&r[n].url.replace("{id}",e);return o&&u.data(a.url,o),o}},set:{active:function(){u.addClass(n.active)}},remove:{data:function(){u.removeData(a.id).removeData(a.icon).removeData(a.placeholder).removeData(a.source).removeData(a.url)},active:function(){u.removeClass(n.active)},embed:function(){s.empty()}},encode:{parameters:function(e){var n,o=[];for(n in e)o.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return o.join("&amp;")}},generate:{embed:function(e){f.debug("Generating embed html");var n,o,t=f.get.source();return(e=f.get.url(e))?(o=f.generate.parameters(t),n=i.iframe(e,o)):f.error(c.noURL,u),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),f.encode.parameters(o)}},has:{embed:function(){return 0<s.length},placeholder:function(){return t.placeholder||u.data(a.placeholder)}},should:{autoplay:function(){return"auto"===t.autoplay?t.placeholder||u.data(a.placeholder)!==j:t.autoplay}},is:{video:function(){return"video"==f.get.type()}},setting:function(e,n){if(f.debug("Changing setting",e,n),E.isPlainObject(e))E.extend(!0,t,e);else{if(n===j)return t[e];E.isPlainObject(t[e])?E.extend(!0,t[e],n):t[e]=n}},internal:function(e,n){if(E.isPlainObject(e))E.extend(!0,f,e);else{if(n===j)return f[e];f[e]=n}},debug:function(){!t.silent&&t.debug&&(t.performance?f.performance.log(arguments):(f.debug=Function.prototype.bind.call(console.info,console,t.name+":"),f.debug.apply(console,arguments)))},verbose:function(){!t.silent&&t.verbose&&t.debug&&(t.performance?f.performance.log(arguments):(f.verbose=Function.prototype.bind.call(console.info,console,t.name+":"),f.verbose.apply(console,arguments)))},error:function(){t.silent||(f.error=Function.prototype.bind.call(console.error,console,t.name+":"),f.error.apply(console,arguments))},performance:{log:function(e){var n,o;t.performance&&(o=(n=(new Date).getTime())-(y||n),y=n,w.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:m,"Execution Time":o})),clearTimeout(f.performance.timer),f.performance.timer=setTimeout(f.performance.display,500)},display:function(){var e=t.name+":",o=0;y=!1,clearTimeout(f.performance.timer),E.each(w,function(e,n){o+=n["Execution Time"]}),e+=" "+o+"ms",v&&(e+=" '"+v+"'"),1<g.length&&(e+=" ("+g.length+")"),(console.group!==j||console.table!==j)&&0<w.length&&(console.groupCollapsed(e),console.table?console.table(w):E.each(w,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),w=[]}},invoke:function(t,e,n){var r,a,o,i=p;return e=e||D,n=m||n,"string"==typeof t&&i!==j&&(t=t.split(/[\. ]/),r=t.length-1,E.each(t,function(e,n){var o=e!=r?n+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(E.isPlainObject(i[o])&&e!=r)i=i[o];else{if(i[o]!==j)return a=i[o],!1;if(!E.isPlainObject(i[n])||e==r)return i[n]!==j?a=i[n]:f.error(c.method,t),!1;i=i[n]}})),E.isFunction(a)?o=a.apply(n,e):a!==j&&(o=a),E.isArray(b)?b.push(o):b!==j?b=[b,o]:o!==j&&(b=o),a}};C?(p===j&&f.initialize(),f.invoke(P)):(p!==j&&p.invoke("destroy"),f.initialize())}),b!==j?b:this},E.fn.embed.settings={name:"Embed",namespace:"embed",silent:!1,debug:!1,verbose:!1,performance:!0,icon:!1,source:!1,url:!1,id:!1,autoplay:"auto",color:"#444444",hd:!0,brandedUI:!1,parameters:!1,onDisplay:function(){},onPlaceholderDisplay:function(){},onReset:function(){},onCreate:function(e){},onEmbed:function(e){return e},metadata:{id:"id",icon:"icon",placeholder:"placeholder",source:"source",url:"url"},error:{noURL:"No URL specified",method:"The method you called is not defined"},className:{active:"active",embed:"embed"},selector:{embed:".embed",placeholder:".placeholder",icon:".icon"},sources:{youtube:{name:"youtube",type:"video",icon:"video play",domain:"youtube.com",url:"//www.youtube.com/embed/{id}",parameters:function(e){return{autohide:!e.brandedUI,autoplay:e.autoplay,color:e.color||j,hq:e.hd,jsapi:e.api,modestbranding:!e.brandedUI}}},vimeo:{name:"vimeo",type:"video",icon:"video play",domain:"vimeo.com",url:"//player.vimeo.com/video/{id}",parameters:function(e){return{api:e.api,autoplay:e.autoplay,byline:e.brandedUI,color:e.color||j,portrait:e.brandedUI,title:e.brandedUI}}}},templates:{iframe:function(e,n){var o=e;return n&&(o+="?"+n),'<iframe src="'+o+'" width="100%" height="100%" frameborder="0" scrolling="no" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'},placeholder:function(e,n){var o="";return n&&(o+='<i class="'+n+' icon"></i>'),e&&(o+='<img class="placeholder" src="'+e+'">'),o}},api:!1,onPause:function(){},onPlay:function(){},onStop:function(){}}}(jQuery,window,void document);