wishthis/node_modules/fomantic-ui/dist/components/embed.min.js

11 lines
No EOL
7.8 KiB
JavaScript

/*
* # Fomantic UI - 2.9.3
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(D,e){"use strict";e=void 0!==e&&e.Math===Math?e:globalThis,D.fn.embed=function(h){var b,v=D(this),g=Date.now(),y=[],w=h,P="string"==typeof w,C=[].slice.call(arguments,1);return v.each(function(){var t=D.isPlainObject(h)?D.extend(!0,{},D.fn.embed.settings,h):D.extend({},D.fn.embed.settings),e=t.selector,o=t.className,a=t.sources,d=t.error,r=t.metadata,n=t.namespace,i=t.templates,c="."+n,l="module-"+n,u=D(this),s=(u.find(e.placeholder),u.find(e.icon),u.find(e.embed)),m=this,p=u.data(l),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(l,f)},destroy:function(){f.verbose("Destroying previous instance of embed"),f.reset(),u.removeData(l).off(c)},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"+c,e.placeholder,f.createAndShow).on("click"+c,e.icon,f.createAndShow))}},create:function(){f.get.placeholder()?f.createPlaceholder():f.createAndShow()},createPlaceholder:function(e){var o=f.get.icon();e=e||f.get.placeholder(),u.html(i.placeholder(e,o)),f.debug("Creating placeholder for embed",e,o)},createEmbed:function(e){f.refresh(),e=e||f.get.url(),s=D("<div/>").addClass(o.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,o,n){f.debug("Changing video to ",e,o,n),u.data(r.source,e).data(r.id,o),n?u.data(r.url,n):u.removeData(r.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(r.id)},placeholder:function(){return t.placeholder||u.data(r.placeholder)},icon:function(){return t.icon||(void 0!==u.data(r.icon)?u.data(r.icon):f.determine.icon())},source:function(e){return t.source||(void 0!==u.data(r.source)?u.data(r.source):f.determine.source())},type:function(){var e=f.get.source();return void 0!==a[e]&&a[e].type},url:function(){return t.url||(void 0!==u.data(r.url)?u.data(r.url):f.determine.url())}},determine:{autoplay:function(){f.should.autoplay()&&(t.autoplay=!0)},source:function(n){var t=!1;return(n=n||f.get.url())&&D.each(a,function(e,o){if(-1!==n.search(o.domain))return t=e,!1}),t},icon:function(){var e=f.get.source();return void 0!==a[e]&&a[e].icon},url:function(){var e=t.id||u.data(r.id),o=t.source||u.data(r.source),o=void 0!==a[o]&&a[o].url.replace("{id}",e);return o&&u.data(r.url,o),o}},set:{active:function(){u.addClass(o.active)}},remove:{data:function(){u.removeData(r.id).removeData(r.icon).removeData(r.placeholder).removeData(r.source).removeData(r.url)},active:function(){u.removeClass(o.active)},embed:function(){s.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){f.debug("Generating embed html");var o,n=f.get.source();return(e=f.get.url(e))?(n=f.generate.parameters(n),o=i.iframe(e,n)):f.error(d.noURL,u),o},parameters:function(e,o){e=a[e]&&void 0!==a[e].parameters?a[e].parameters(t):{};return(o=o||t.parameters)&&(e=D.extend({},e,o)),e=t.onEmbed(e),f.encode.parameters(e)}},has:{embed:function(){return 0<s.length},placeholder:function(){return t.placeholder||u.data(r.placeholder)}},should:{autoplay:function(){return"auto"===t.autoplay?t.placeholder||void 0!==u.data(r.placeholder):t.autoplay}},is:{video:function(){return"video"===f.get.type()}},setting:function(e,o){if(f.debug("Changing setting",e,o),D.isPlainObject(e))D.extend(!0,t,e);else{if(void 0===o)return t[e];D.isPlainObject(t[e])?D.extend(!0,t[e],o):t[e]=o}},internal:function(e,o){if(D.isPlainObject(e))D.extend(!0,f,e);else{if(void 0===o)return f[e];f[e]=o}},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 o,n;t.performance&&(n=(o=Date.now())-(g||o),g=o,y.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:m,"Execution Time":n})),clearTimeout(f.performance.timer),f.performance.timer=setTimeout(function(){f.performance.display()},500)},display:function(){var e=t.name+":",n=0;g=!1,clearTimeout(f.performance.timer),D.each(y,function(e,o){n+=o["Execution Time"]}),e+=" "+n+"ms",1<v.length&&(e+=" ("+v.length+")"),0<y.length&&(console.groupCollapsed(e),console.table?console.table(y):D.each(y,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),y=[]}},invoke:function(t,e,o){var a,r,n,i,c=p;return e=e||C,o=o||m,"string"==typeof t&&void 0!==c&&(t=t.split(/[ .]/),a=t.length-1,D.each(t,function(e,o){var n=e!==a?o+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(D.isPlainObject(c[n])&&e!==a)c=c[n];else{if(void 0!==c[n])return r=c[n],!1;{if(!D.isPlainObject(c[o])||e===a)return void 0!==c[o]?r=c[o]:f.error(d.method,t),!1;c=c[o]}}})),"function"==typeof(i=r)&&"number"!=typeof i.nodeType?n=r.apply(o,e):void 0!==r&&(n=r),Array.isArray(b)?b.push(n):void 0!==b?b=[b,n]:void 0!==n&&(b=n),r}};P?(void 0===p&&f.initialize(),f.invoke(w)):(void 0!==p&&p.invoke("destroy"),f.initialize())}),void 0!==b?b:this},D.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:"#444",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||void 0,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||void 0,portrait:e.brandedUI,title:e.brandedUI}}}},templates:{deQuote:function(e,o){return String(e).replace(/"/g,o?"&quot;":"")},iframe:function(e,o){return o&&(e+="?"+o),'<iframe src="'+(0,D.fn.embed.settings.templates.deQuote)(e)+'" width="100%" height="100%" msallowFullScreen allowFullScreen></iframe>'},placeholder:function(e,o){var n="",t=D.fn.embed.settings.templates.deQuote;return o&&(n+='<i class="'+t(o)+' icon"></i>'),e&&(n+='<img class="placeholder" src="'+t(e)+'">'),n}},api:!1,onPause:function(){},onPlay:function(){},onStop:function(){}}}(jQuery,window,document);