/* * vidim v1.0.1 * 2018-08-24T13:55:53.385Z * https://github.com/OriginalEXE/vidim * * Made by Ante Sepic */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.vidim=e()}(this,function(){"use strict";function t(t,e){Object.keys(e).forEach(function(i){t.hasOwnProperty(i)||(t[i]=e[i])})}function e(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;return"string"==typeof t?e.querySelector(t):t}function i(t,e){var i,s,o,n,r=0,a=function(){r=Date.now(),i=null,n=t.apply(s,o),i||(s=o=null)},l=function(){var l=Date.now();r||(r=l);var h=e-(l-r);return s=this,o=arguments,h<=0||h>e?(i&&(clearTimeout(i),i=null),r=l,n=t.apply(s,o),i||(s=o=null)):i||(i=setTimeout(a,h)),n};return l.cancel=function(){clearTimeout(i),r=0,i=s=o=null},l}function s(t){"loading"!=document.readyState?t():document.addEventListener("DOMContentLoaded",t)}var o=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){function e(t){if(t)return i(t)}function i(t){for(var i in e.prototype)t[i]=e.prototype[i];return t}t.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function i(){this.off(t,i),e.apply(this,arguments)}return i.fn=e,this.on(t,i),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i=this._callbacks["$"+t];if(!i)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var s,o=0;o0&&void 0!==arguments[0]?arguments[0]:100;return this.el.volume=parseFloat(t/100),this},getVolume:function(){return 100*this.el.volume},mute:function(){return this.el.muted=!0,this},unMute:function(){return this.el.muted=!1,this},setTime:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.el.currentTime=t,this},getTime:function(){return this.el.currentTime},getDuration:function(){return this.el.duration},showPoster:function(){this.pause().el.style.opacity="0"},changeSource:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.el.innerHTML="",t.length&&"string"!=typeof t)for(var i=0;ithis._options.ratio&&t/et.getDuration())&&(t.setTime(0),t.play())},100)}),t.on("pause",function(){clearInterval(e)}),t.on("destroy",function(){clearInterval(e)})}},onStateChange:function(e){switch(e.data){case 0:t.emit("end",t);break;case 1:t.emit("play",t);break;case 2:t.emit("pause",t);break;case 3:t.emit("buffering",t)}}}};this._options.loop&&(o.playerVars.playlist=this.videoID,o.playerVars.loop=1),this.player=new YT.Player(s,o),this.el=this.player.getIframe(),this.el.style.position="absolute",this.el.style.left="50%",this.el.style.top="50%",this.el.style.transform="translate(-50%, -50%)",this.el.style.webkitTransform="translate(-50%, -50%)",this.el.style.msTransform="translate(-50%, -50%)",this.el.style.oTransform="translate(-50%, -50%)",this.el.style.mozTransform="translate(-50%, -50%)",this.el.style.minWidth="calc( 100% + 2px )",this.el.style.minHeight="calc( 100% + 2px )",this.el.style.opacity="0",this._constructOverlay(),this.resize()},_listen:function(){var t=this;this.on("play",function(){t.el.style.opacity="1"}),this._options.showPosterBeforePlay||this.once("play",function(){t.wrapper.style.backgroundImage="url('"+t._options.poster+"')"}),this._options.showPosterOnEnd?this.on("end",function(){t.el.style.opacity="0"}):this.on("end",function(){t.player.seekTo(t.player.getDuration()),t.player.playVideo(),t.player.pauseVideo()}),this._options.showPosterOnPause&&this.on("pause",function(){t.el.style.opacity="0"})},play:function(){return this.player.playVideo(),this},pause:function(){return this.player.pauseVideo(),this},setVolume:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;return this.player.setVolume(t),this},getVolume:function(){return this.getVolume()},mute:function(){return this.player.mute(),this},unMute:function(){return this.player.unMute(),this},setTime:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.player.seekTo(t,!0),this},getTime:function(){return this.player.getCurrentTime()},getDuration:function(){return this.player.getDuration()},showPoster:function(){this.pause().el.style.opacity="0"},changeSource:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(11===t.length)this.videoID=t;else{var i=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/,s=t.match(i);if(!s||11!==s[2].length)return new Error("Provided source is not a valid YouTube url");this.videoID=s[2]}if(this.player.loadPlaylist(this.videoID,0,this._options.startAt,this._options.quality),this.player.setLoop(this._options.loop),e){var o=this._options.poster;-1!==this.wrapper.style.backgroundImage.indexOf(o)&&(this.wrapper.style.backgroundImage="url('"+e+"')"),this._options.poster=e}},destroy:function(){this.emit("destroy"),this.player.destroy();try{this.wrapper.parentNode.removeChild(this.wrapper)}catch(t){}e.deleteInstance(this.vidimID),delete this.container.vidimID,this.off()},resize:function(){if(this.el){var t=this.container.offsetHeight,e=this.container.offsetWidth;"BODY"===this.container.nodeName&&(e=window.innerWidth,t=window.innerHeight),1this._options.ratio&&t/e1&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(s).forEach(function(t){_.push(t)}),t(s,w),s.src&&!g[s.type]?new Error("No provider can handle type: '"+s.type+"'"):("string"==typeof s.ratio&&("4/3"===s.ratio?s.ratio=4/3:s.ratio=16/9),this._options=s,this.container=e(i),this.container?(-1===_.indexOf("zIndex")&&"BODY"===this.container.nodeName&&(this._options.zIndex=-1),void this._initialize()):new Error("Could not find the container: "+i))}if(void 0!==a.document){var v=0,m={},w={wrapperClass:"",overlayClass:"",src:!1,type:"HTML5",ratio:1.7778,autoplay:!0,loop:!0,poster:"",showPosterBeforePlay:!0,showPosterOnEnd:!1,showPosterOnPause:!1,zIndex:0,autoResize:!0,muted:!0,startAt:0,onReady:!1},_=[],g={},b=f.prototype;return b._initialize=function(){if(this.vidimID=v++,this.container.vidimID=this.vidimID,m[this.vidimID]=this,o(this),!this._options.src&&this._options.poster)return this._constructWrapper(),void(this.destroy=function(){this.emit("destroy");try{this.wrapper.parentNode.removeChild(this.wrapper)}catch(t){}f.deleteInstance(this.vidimID),delete this.container.vidimID,this.off()});var t=g[this._options.type];for(var e in t)this[e]=t[e];if("function"!=typeof this._initializeProvider)return new Error("Provider is missing method: _initializeProvider");this._constructWrapper(),this._initializeProvider(),this._options.autoResize&&window.addEventListener("resize",i(this.resize,200).bind(this),!1),this.resize()},b._constructWrapper=function(){"static"===getComputedStyle(this.container,null).getPropertyValue("position")&&(this.container.style.position="relative"),this.wrapper=document.createElement("div"),"BODY"===this.container.nodeName?this.wrapper.style.position="fixed":this.wrapper.style.position="absolute",this._options.wrapperClass&&("function"==typeof this._options.wrapperClass?this.wrapper.classList.add(this._options.wrapperClass.call(this)):this.wrapper.classList.add(this._options.wrapperClass)),this.wrapper.style.left=0,this.wrapper.style.top=0,this.wrapper.style.height="100%",this.wrapper.style.width="100%",this.wrapper.style.overflow="hidden",this.wrapper.style.zIndex=parseInt(this._options.zIndex,10),this._options.poster&&(this.wrapper.style.backgroundSize="cover",this.wrapper.style.backgroundPosition="center center",this.wrapper.style.backgroundRepear="no-repeat",this._options.showPosterBeforePlay&&(this.wrapper.style.backgroundImage="url('"+this._options.poster+"')")),this.container.insertBefore(this.wrapper,this.container.firstChild)},b._constructOverlay=function(){this.overlay=document.createElement("div"),this.overlay.style.position="absolute",this._options.overlayClass&&("function"==typeof this._options.overlayClass?this.overlay.classList.add(this._options.overlayClass.call(this)):this.overlay.classList.add(this._options.overlayClass)),this.overlay.style.left=0,this.overlay.style.top=0,this.overlay.style.height="100%",this.overlay.style.width="100%",this.wrapper.appendChild(this.overlay)},f.getInstanceFromID=p,f.getInstanceFromElement=c,f.registerProvider=h,f.destroyAllInstances=u,f.deleteInstance=d,f.utility=n,f.scanDOM=y,r(f),l(f),s(y),f}}("undefined"!=typeof window?window:void 0)});