wishthis/node_modules/fomantic-ui/dist/components/embed.min.js
2023-08-17 11:47:40 +02:00

11 lines
No EOL
7.8 KiB
JavaScript

/*
* # Fomantic UI - 2.9.2
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(E,e){"use strict";e=void 0!==e&&e.Math===Math?e:globalThis,E.fn.embed=function(h){var b,v=E(this),g=v.selector||"",y=Date.now(),w=[],P=h,C="string"==typeof P,D=[].slice.call(arguments,1);return v.each(function(){var t=E.isPlainObject(h)?E.extend(!0,{},E.fn.embed.settings,h):E.extend({},E.fn.embed.settings),e=t.selector,o=t.className,r=t.sources,d=t.error,a=t.metadata,n=t.namespace,i=t.templates,c="."+n,l="module-"+n,u=E(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=E("<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(a.source,e).data(a.id,o),n?u.data(a.url,n):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||(void 0!==u.data(a.icon)?u.data(a.icon):f.determine.icon())},source:function(e){return t.source||(void 0!==u.data(a.source)?u.data(a.source):f.determine.source())},type:function(){var e=f.get.source();return void 0!==r[e]&&r[e].type},url:function(){return t.url||(void 0!==u.data(a.url)?u.data(a.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())&&E.each(r,function(e,o){if(-1!==n.search(o.domain))return t=e,!1}),t},icon:function(){var e=f.get.source();return void 0!==r[e]&&r[e].icon},url:function(){var e=t.id||u.data(a.id),o=t.source||u.data(a.source),o=void 0!==r[o]&&r[o].url.replace("{id}",e);return o&&u.data(a.url,o),o}},set:{active:function(){u.addClass(o.active)}},remove:{data:function(){u.removeData(a.id).removeData(a.icon).removeData(a.placeholder).removeData(a.source).removeData(a.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=r[e]&&void 0!==r[e].parameters?r[e].parameters(t):{};return(o=o||t.parameters)&&(e=E.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(a.placeholder)}},should:{autoplay:function(){return"auto"===t.autoplay?t.placeholder||void 0!==u.data(a.placeholder):t.autoplay}},is:{video:function(){return"video"===f.get.type()}},setting:function(e,o){if(f.debug("Changing setting",e,o),E.isPlainObject(e))E.extend(!0,t,e);else{if(void 0===o)return t[e];E.isPlainObject(t[e])?E.extend(!0,t[e],o):t[e]=o}},internal:function(e,o){if(E.isPlainObject(e))E.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())-(y||o),y=o,w.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:m,"Execution Time":n})),clearTimeout(f.performance.timer),f.performance.timer=setTimeout(f.performance.display,500)},display:function(){var e=t.name+":",n=0;y=!1,clearTimeout(f.performance.timer),E.each(w,function(e,o){n+=o["Execution Time"]}),e+=" "+n+"ms",g&&(e+=" '"+g+"'"),1<v.length&&(e+=" ("+v.length+")"),0<w.length&&(console.groupCollapsed(e),console.table?console.table(w):E.each(w,function(e,o){console.log(o.Name+": "+o["Execution Time"]+"ms")}),console.groupEnd()),w=[]}},invoke:function(t,e,o){var r,a,n,i,c=p;return e=e||D,o=o||m,"string"==typeof t&&void 0!==c&&(t=t.split(/[ .]/),r=t.length-1,E.each(t,function(e,o){var n=e!==r?o+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(E.isPlainObject(c[n])&&e!==r)c=c[n];else{if(void 0!==c[n])return a=c[n],!1;{if(!E.isPlainObject(c[o])||e===r)return void 0!==c[o]?a=c[o]:f.error(d.method,t),!1;c=c[o]}}})),"function"==typeof(i=a)&&"number"!=typeof i.nodeType?n=a.apply(o,e):void 0!==a&&(n=a),Array.isArray(b)?b.push(n):void 0!==b?b=[b,n]:void 0!==n&&(b=n),a}};C?(void 0===p&&f.initialize(),f.invoke(P)):(void 0!==p&&p.invoke("destroy"),f.initialize())}),void 0!==b?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:"#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,E.fn.embed.settings.templates.deQuote)(e)+'" width="100%" height="100%" msallowFullScreen allowFullScreen></iframe>'},placeholder:function(e,o){var n="",t=E.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);