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.

10 lines
7.3 KiB

  1. /*!
  2. * # Semantic UI 2.1.6 - Video
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2015 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,n,o,r){"use strict";e.fn.embed=function(o){var t,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,C="."+y,P="module-"+y,U=(e(n),e(this)),E=U.find(f.placeholder),S=U.find(f.icon),T=U.find(f.embed),j=this,A=U.data(P);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),A=m,U.data(P,m)},destroy:function(){m.verbose("Destroying previous instance of embed"),m.reset(),U.removeData(P).off(C)},refresh:function(){m.verbose("Refreshing selector cache"),E=U.find(f.placeholder),S=U.find(f.icon),T=U.find(f.embed)},bind:{events:function(){m.has.placeholder()&&(m.debug("Adding placeholder events"),U.on("click"+C,f.placeholder,m.createAndShow).on("click"+C,f.icon,m.createAndShow))}},create:function(){var e=m.get.placeholder();e?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(),U.html(w.placeholder(e,n)),m.debug("Creating placeholder for embed",e,n)},createEmbed:function(n){m.refresh(),n=n||m.get.url(),T=e("<div/>").addClass(h.embed).html(m.generate.embed(n)).appendTo(U),p.onCreate.call(j,n),m.debug("Creating embed object",T)},createAndShow:function(){m.createEmbed(),m.show()},change:function(e,n,o){m.debug("Changing video to ",e,n,o),U.data(v.source,e).data(v.id,n).data(v.url,o),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||U.data(v.id)},placeholder:function(){return p.placeholder||U.data(v.placeholder)},icon:function(){return p.icon?p.icon:U.data(v.icon)!==r?U.data(v.icon):m.determine.icon()},source:function(e){return p.source?p.source:U.data(v.source)!==r?U.data(v.source):m.determine.source()},type:function(){var e=m.get.source();return b[e]!==r?b[e].type:!1},url:function(){return p.url?p.url:U.data(v.url)!==r?U.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(),n&&e.each(b,function(e,r){return-1!==n.search(r.domain)?(o=e,!1):void 0}),o},icon:function(){var e=m.get.source();return b[e]!==r?b[e].icon:!1},url:function(){var e,n=p.id||U.data(v.id),o=p.source||U.data(v.source);return e=b[o]!==r?b[o].url.replace("{id}",n):!1,e&&U.data(v.url,e),e}},set:{active:function(){U.addClass(h.active)}},remove:{active:function(){U.removeClass(h.active)},embed:function(){T.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){m.debug("Generating embed html");var n,o,r=m.get.source();return e=m.get.url(e),e?(o=m.generate.parameters(r),n=w.iframe(e,o)):m.error(g.noURL,U),n},parameters:function(n,o){var t=b[n]&&b[n].parameters!==r?b[n].parameters(p):{};return o=o||p.parameters,o&&(t=e.extend({},t,o)),t=p.onEmbed(t),m.encode.parameters(t)}},has:{placeholder:function(){return p.placeholder||U.data(v.placeholder)}},should:{autoplay:function(){return"auto"===p.autoplay?p.placeholder||U.data(v.placeholder)!==r:p.autoplay}},is:{video:function(){return"video"==m.get.type()}},setting:function(n,o){if(m.debug("Changing setting",n,o),e.isPlainObject(n))e.extend(!0,p,n);else{if(o===r)return p[n];p[n]=o}},internal:function(n,o){if(e.isPlainObject(n))e.extend(!0,m,n);else{if(o===r)return m[n];m[n]=o}},debug:function(){p.debug&&(p.performance?m.p