!function(a,b){(typeof define).match(/^(object|function)$/)&&define.amd?define(["angular","video.js"],b):"object"==typeof module&&module.exports?module.exports=b(require("angular"),require("video.js")):b(a.angular,a.videojs)}(this,function(a,b){"use strict";function c(){return b&&b.VERSION?b.VERSION:"0.0.0"}function d(a){return"VIDEO"===a[0].nodeName||"AUDIO"===a[0].nodeName}var e=a.module("vjs.video",[]);return e.controller("VjsVideoController",["$scope",function(e){function f(a,c){var e,f=null;if(!b)throw new Error("video.js was not found!");if(c){if(e=a[0].querySelectorAll("video, audio"),0===e.length)throw new Error("video tag must be defined within container directive!");if(e.length>1)throw new Error("only one video can be defined within the container directive!");f=e[0]}else{if(!d(a))throw new Error("directive must be attached to a video or audio tag!");f=a[0]}return f}function g(a,b){var c,d,e,f=b,g=document.createElement("style"),h=function(a){var b=a.split(":"),c='the ratio must either be "wide", "standard" or decimal values in the format of w:h';if(2!==b.length)throw new Error(c);if(isNaN(b[0])||isNaN(b[1]))throw new Error(c);if(0===Number(b[0])||0===Number(b[1]))throw new Error("neither the width or height ratio can be zero!");return Number(b[1])/Number(b[0])*100},i=function(a){var b,c=a[0].querySelector(".vjs-tech");if(!c)throw new Error("Failed to find instance of video-js class!");return b="vjs-container-"+c.getAttribute("id"),a[0].setAttribute("id",b),b};switch(f||(f="16:9"),f){case"wide":f="16:9";break;case"standard":f="4:3"}c=i(a),d=h(f),e=["#",c," ",".video-js {padding-top:",d,"%;}\n",".vjs-fullscreen {padding-top: 0px;}"].join(""),g.type="text/css",g.rel="stylesheet",g.styleSheet?g.styleSheet.cssText=e:g.appendChild(document.createTextNode(e)),a[0].appendChild(g)}function h(a,b){var c,d,e="a sources and/or tracks element must be defined for the vjs-media attribute",f="sources must be an array of objects with at least one item",g="tracks must be an array of objects with at least one item";if(a.vjsMedia){if(!a.vjsMedia.sources&&!a.vjsMedia.tracks)throw new Error(e);if(a.vjsMedia.sources&&!(a.vjsMedia.sources instanceof Array))throw new Error(f);if(a.vjsMedia.tracks&&!(a.vjsMedia.tracks instanceof Array))throw new Error(g);c=document.createElement("div"),a.vjsMedia.sources&&a.vjsMedia.sources.forEach(function(a){d=document.createElement("source"),d.setAttribute("src",a.src||""),d.setAttribute("type",a.type||""),c.appendChild(d)}),a.vjsMedia.tracks&&a.vjsMedia.tracks.forEach(function(a){d=document.createElement("track"),d.setAttribute("kind",a.kind||""),d.setAttribute("label",a.label||""),d.setAttribute("src",a.src||""),d.setAttribute("srclang",a.srclang||""),a["default"]===!0&&d.setAttribute("default",""),c.appendChild(d)}),b.call(void 0,{element:c})}}function i(f,i,j,k){var l,m=i.vjsSetup||{},n=i.vjsRatio,o=d(j)||c().match(/^5\./)?!1:!0;if(!b)return null;i.vjsMedia&&i.vjsMedia.poster&&(m.poster=i.vjsMedia.poster),h(i,k),l=e.$watch(function(){return i.vjsMedia},function(c,d){c&&!a.equals(c,d)&&(l(),o?(b(f).dispose(),e.$emit("vjsVideoMediaChanged")):e.$emit("vjsVideoMediaChanged"))});var p=b(f,m,function(){o&&g(j,n)});p&&e.$emit("vjsVideoReady",{id:f.getAttribute("id"),vid:p,player:p,controlBar:p.controlBar}),e.$on("$destroy",function(){b(f).dispose()})}var j=this;j.initVideoJs=i,j.getVidElement=f}]),e.directive("vjsVideo",["$compile","$timeout",function(a,b){return{restrict:"A",transclude:!0,scope:{vjsSetup:"=?",vjsRatio:"@",vjsMedia:"=?"},controller:"VjsVideoController",controllerAs:"vjsCtrl",bindToController:!0,link:function(d,e,f,g,h){var i,j,k,l,m=function(a){e.children().remove(),e.append(a.element.childNodes)},n=function(){i=g.getVidElement(e),c().match(/^5\./)&&g.vjsRatio&&(g.vjsSetup||(g.vjsSetup={}),g.vjsSetup.aspectRatio=g.vjsRatio),h(function(a){e.append(a),g.initVideoJs(i,g,e,m)})};k=e.clone(),e.parent().hasClass("vjs-video-wrap")||e.wrap('
'),j=e.parent(),d.$on("vjsVideoMediaChanged",function(){var c=j.children()[0];b(function(){d.$destroy()}),l=k.clone(),j.append(l),l=a(l)(d.$parent),c.remove()}),n()}}}]),e.directive("vjsVideoContainer",[function(){return{restrict:"AE",transclude:!0,template:'
',scope:{vjsSetup:"=?",vjsRatio:"@",vjsMedia:"=?"},controller:"VjsVideoController",controllerAs:"vjsCtrl",bindToController:!0,link:function(a,b,d,e,f){var g,h,i=function(a){var c=b[0].querySelector("video, audio");if(c){for(;c.firstChild;)c.removeChild(c.firstChild);for(;a.element.childNodes.length>0;)c.appendChild(a.element.childNodes[0])}},j=function(){if(g=e.getVidElement(b,!0),null!==g.getAttribute("vjs-video"))throw new Error("vjs-video should not be used on the video tag when using vjs-video-container!");if(null!==g.getAttribute("vjs-setup")||null!==g.getAttribute("vjs-media")||null!==g.getAttribute("vjs-ratio"))throw new Error("directive attributes should not be used on the video tag when using vjs-video-container!");c().match(/^5\./)?e.vjsRatio&&(e.vjsSetup||(e.vjsSetup={}),e.vjsSetup.aspectRatio=e.vjsRatio):(g.setAttribute("width","auto"),g.setAttribute("height","auto")),e.initVideoJs(g,e,b,i)};f(function(a){h=a.clone()}),a.$on("vjsVideoMediaChanged",function(){b.children().remove(),b.append(h.clone()),j()}),j()}}}]),e});