forked from videogular/bower-videogular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideogular.min.js
1 lines (1 loc) · 10.5 KB
/
videogular.min.js
1
"use strict";angular.module("com.2fdevs.videogular",["ngSanitize"]).constant("VG_STATES",{PLAY:"play",PAUSE:"pause",STOP:"stop"}).service("VG_UTILS",function(){this.fixEventOffset=function(a){if(navigator.userAgent.match(/Firefox/i)){var b=a.currentTarget.currentStyle||window.getComputedStyle(a.target,null),c=parseInt(b.borderLeftWidth,10),d=parseInt(b.borderTopWidth,10),e=a.currentTarget.getBoundingClientRect(),f=a.clientX-c-e.left,g=a.clientY-d-e.top;a.offsetX=f,a.offsetY=g}return a},this.getZIndex=function(){var a=1;return angular.element("*").filter(function(){return"auto"!==angular.element(this).css("zIndex")}).each(function(){var b=parseInt(angular.element(this).css("zIndex"));b>a&&(a=b+1)}),a},this.toUTCDate=function(a){return new Date(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),a.getUTCHours(),a.getUTCMinutes(),a.getUTCSeconds(),a.getUTCMilliseconds())},this.secondsToDate=function(a){isNaN(a)&&(a=0);var b=new Date;return b.setTime(1e3*a),b=this.toUTCDate(b)},this.isMobileDevice=function(){return"undefined"!=typeof window.orientation||-1!==navigator.userAgent.indexOf("IEMobile")},this.isiOSDevice=function(){return navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/iPad/i)}}).run(["$window","VG_UTILS",function(a,b){var c,d={w3:{enabled:"fullscreenEnabled",element:"fullscreenElement",request:"requestFullscreen",exit:"exitFullscreen",onchange:"fullscreenchange",onerror:"fullscreenerror"},newWebkit:{enabled:"webkitFullscreenEnabled",element:"webkitFullscreenElement",request:"webkitRequestFullscreen",exit:"webkitExitFullscreen",onchange:"webkitfullscreenchange",onerror:"webkitfullscreenerror"},oldWebkit:{enabled:"webkitIsFullScreen",element:"webkitCurrentFullScreenElement",request:"webkitRequestFullScreen",exit:"webkitCancelFullScreen",onchange:"webkitfullscreenchange",onerror:"webkitfullscreenerror"},moz:{enabled:"mozFullScreen",element:"mozFullScreenElement",request:"mozRequestFullScreen",exit:"mozCancelFullScreen",onchange:"mozfullscreenchange",onerror:"mozfullscreenerror"},ios:{enabled:"webkitFullscreenEnabled",element:"webkitFullscreenElement",request:"webkitEnterFullscreen",exit:"webkitExitFullscreen",onchange:"webkitfullscreenchange",onerror:"webkitfullscreenerror"},ms:{enabled:"msFullscreenEnabled",element:"msFullscreenElement",request:"msRequestFullscreen",exit:"msExitFullscreen",onchange:"msfullscreenchange",onerror:"msfullscreenerror"}};for(var e in d)if(d[e].enabled in document){c=d[e],c.isFullScreen=function(){return null!=document[this.element]};break}b.isiOSDevice()&&(c=d.ios,c.isFullScreen=function(){return null!=document[this.element]}),angular.element(a)[0].fullScreenAPI=c}]).directive("videogular",["$window","VG_STATES","VG_UTILS",function(a,b,c){return{restrict:"E",scope:{theme:"=vgTheme",autoPlay:"=vgAutoplay",vgComplete:"&",vgUpdateVolume:"&",vgUpdateTime:"&",vgUpdateState:"&",vgPlayerReady:"&",vgChangeSource:"&",vgError:"&"},controller:["$scope","$timeout",function(d){var e=null,f=!1,g=!1,h=d.vgComplete(),i=d.vgUpdateVolume(),j=d.vgUpdateTime(),k=d.vgUpdateState(),l=d.vgPlayerReady(),m=d.vgChangeSource(),n=d.vgError();this.videogularElement=null,this.clearMedia=function(){d.API.mediaElement[0].src=""},this.onCanPlay=function(){d.API.isBuffering=!1,d.$apply()},this.onVideoReady=function(){d.API.isReady=!0,d.API.autoPlay=d.autoPlay,d.API.currentState=b.STOP,g=!0,d.vgPlayerReady()&&(l=d.vgPlayerReady())(d.API)},this.onLoadMetaData=function(a){d.API.isBuffering=!1,d.API.onUpdateTime(a)},this.onUpdateTime=function(a){d.API.currentTime=c.secondsToDate(a.target.currentTime),1/0!=a.target.duration?(d.API.totalTime=c.secondsToDate(a.target.duration),d.API.timeLeft=c.secondsToDate(a.target.duration-a.target.currentTime),d.API.isLive=!1):d.API.isLive=!0,d.vgUpdateTime()&&(j=d.vgUpdateTime())(a.target.currentTime,a.target.duration),d.$apply()},this.onPlay=function(){d.API.setState(b.PLAY),d.$apply()},this.onPause=function(){d.API.setState(b.PAUSE),d.$apply()},this.onVolumeChange=function(){d.API.volume=d.API.mediaElement[0].volume,d.$apply()},this.seekTime=function(a,b){var e;b?(e=a*d.API.mediaElement[0].duration/100,d.API.mediaElement[0].currentTime=e):(e=a,d.API.mediaElement[0].currentTime=e),d.API.currentTime=c.secondsToDate(e)},this.playPause=function(){d.API.mediaElement[0].paused?this.play():this.pause()},this.setState=function(a){return a&&a!=d.API.currentState&&(d.vgUpdateState()&&(k=d.vgUpdateState())(a),d.API.currentState=a),d.API.currentState},this.play=function(){d.API.mediaElement[0].play(),this.setState(b.PLAY)},this.pause=function(){d.API.mediaElement[0].pause(),this.setState(b.PAUSE)},this.stop=function(){d.API.mediaElement[0].pause(),d.API.mediaElement[0].currentTime=0,this.setState(b.STOP)},this.toggleFullScreen=function(){angular.element(a)[0].fullScreenAPI?angular.element(a)[0].fullScreenAPI.isFullScreen()?c.isMobileDevice()||document[angular.element(a)[0].fullScreenAPI.exit]():c.isMobileDevice()?c.isiOSDevice()?g?this.enterElementInFullScreen(d.API.mediaElement[0]):(f=!0,this.play()):this.enterElementInFullScreen(d.API.mediaElement[0]):this.enterElementInFullScreen(d.API.videogularElement[0]):(d.API.isFullScreen?(d.API.videogularElement.removeClass("fullscreen"),d.API.videogularElement.css("z-index",0)):(d.API.videogularElement.addClass("fullscreen"),d.API.videogularElement.css("z-index",c.getZIndex())),d.API.isFullScreen=!d.API.isFullScreen)},this.enterElementInFullScreen=function(b){b[angular.element(a)[0].fullScreenAPI.request]()},this.changeSource=function(a){d.vgChangeSource()&&(m=d.vgChangeSource())(a)},this.setVolume=function(a){d.vgUpdateVolume()&&(i=d.vgUpdateVolume())(a),d.API.mediaElement[0].volume=a,d.API.volume=a},this.updateTheme=function(a){if(e)for(var b=document.getElementsByTagName("link"),c=0,d=b.length;d>c;c++)b[c].outerHTML.indexOf(e)>=0&&b[c].parentNode.removeChild(b[c]);if(a){var f=angular.element(document).find("head");f.append("<link rel='stylesheet' href='"+a+"'>"),e=a}},this.onStartBuffering=function(){d.API.isBuffering=!0,d.$apply()},this.onStartPlaying=function(){d.API.isBuffering=!1,d.$apply()},this.onComplete=function(){d.vgComplete()&&(h=d.vgComplete())(),d.API.setState(b.STOP),d.API.isCompleted=!0,d.$apply()},this.onVideoError=function(a){d.vgError()&&(n=d.vgError())(a)},this.addListeners=function(){d.API.mediaElement[0].addEventListener("canplay",d.API.onCanPlay,!1),d.API.mediaElement[0].addEventListener("loadedmetadata",d.API.onLoadMetaData,!1),d.API.mediaElement[0].addEventListener("waiting",d.API.onStartBuffering,!1),d.API.mediaElement[0].addEventListener("ended",d.API.onComplete,!1),d.API.mediaElement[0].addEventListener("playing",d.API.onStartPlaying,!1),d.API.mediaElement[0].addEventListener("play",d.API.onPlay,!1),d.API.mediaElement[0].addEventListener("pause",d.API.onPause,!1),d.API.mediaElement[0].addEventListener("volumechange",d.API.onVolumeChange,!1),d.API.mediaElement[0].addEventListener("timeupdate",d.API.onUpdateTime,!1),d.API.mediaElement[0].addEventListener("error",d.API.onVideoError,!1)},d.API=this,d.init=function(){d.API.isReady=!1,d.API.isCompleted=!1,d.API.currentTime=c.secondsToDate(0),d.API.totalTime=c.secondsToDate(0),d.API.timeLeft=c.secondsToDate(0),d.API.isLive=!1,d.API.updateTheme(d.theme),d.addBindings(),angular.element(a)[0].fullScreenAPI&&document.addEventListener(angular.element(a)[0].fullScreenAPI.onchange,d.onFullScreenChange)},d.addBindings=function(){d.$watch("theme",function(a,b){a!=b&&d.API.updateTheme(a)}),d.$watch("autoPlay",function(a,b){a!=b&&a&&d.API.play()})},d.onFullScreenChange=function(){d.API.isFullScreen=angular.element(a)[0].fullScreenAPI.isFullScreen(),d.$apply()},d.$on("$destroy",this.clearMedia),d.$on("$routeChangeStart",this.clearMedia),d.init()}],link:{pre:function(a,b,c,d){d.videogularElement=angular.element(b)}}}}]).directive("vgVideo",["$compile","$timeout","VG_UTILS","VG_STATES",function(a,b,c,d){return{restrict:"E",require:"^videogular",scope:{vgSrc:"=",vgLoop:"=",vgPreload:"=",vgNativeControls:"=",vgTracks:"="},link:function(e,f,g,h){function i(){if(k="",h.mediaElement[0].canPlayType){for(var a=0,e=j.length;e>a;a++)if(k=h.mediaElement[0].canPlayType(j[a].type),"maybe"==k||"probably"==k){h.mediaElement.attr("src",j[a].src),h.mediaElement.attr("type",j[a].type);break}}else h.mediaElement.attr("src",j[0].src),h.mediaElement.attr("type",j[0].type);b(function(){(h.autoPlay&&!c.isMobileDevice()||h.currentState===d.PLAY)&&h.play()}),""==k&&h.onVideoError()}var j,k;e.$watch("vgSrc",function(a,b){j&&a==b||!a||(j=a,h.sources=j,i())}),h.sources=e.vgSrc,h.mediaElement=angular.element('<video vg-source="vgSrc"></video>');var l=a(h.mediaElement)(e);h.addListeners(),f.append(l),h.onVideoReady()}}}]).directive("vgAudio",["$compile","$timeout","VG_UTILS","VG_STATES",function(a,b,c,d){return{restrict:"E",require:"^videogular",scope:{vgSrc:"=",vgLoop:"=",vgPreload:"=",vgNativeControls:"=",vgTracks:"="},link:function(e,f,g,h){function i(){if(k="",h.mediaElement[0].canPlayType){for(var a=0,e=j.length;e>a;a++)if(k=h.mediaElement[0].canPlayType(j[a].type),"maybe"==k||"probably"==k){h.mediaElement.attr("src",j[a].src),h.mediaElement.attr("type",j[a].type);break}}else h.mediaElement.attr("src",j[0].src),h.mediaElement.attr("type",j[0].type);b(function(){(h.autoPlay&&!c.isMobileDevice()||h.currentState===d.PLAY)&&h.play()})}var j,k;e.$watch("vgSrc",function(a,b){j&&a==b||!a||(j=a,h.sources=j,i())}),h.sources=e.vgSrc,h.mediaElement=angular.element('<audio vg-source="vgSrc"></audio>');var l=a(h.mediaElement)(e);h.addListeners(),f.append(l),h.onVideoReady()}}}]).directive("vgTracks",[function(){return{restrict:"A",require:"^videogular",link:{pre:function(a,b,c,d){function e(){var a,b,c=d.mediaElement.children();for(a=0,b=c.length;b>a;a++)c[a].remove();if(f)for(a=0,b=f.length;b>a;a++){g="",g+="<track ";for(var e in f[a])g+=e+'="'+f[a][e]+'" ';g+="></track>",d.mediaElement.append(g)}}var f,g;a.$watch(c.vgTracks,function(a,b){f&&a==b||(f=a,d.tracks=f,e())})}}}}]).directive("vgLoop",[function(){return{restrict:"A",require:"^videogular",link:{pre:function(a,b,c,d){var e;a.$watch(c.vgLoop,function(a,b){e&&a==b||!a?d.mediaElement.removeAttr("loop"):(e=a,d.mediaElement.attr("loop",e))})}}}}]).directive("vgPreload",[function(){return{restrict:"A",require:"^videogular",link:{pre:function(a,b,c,d){var e;a.$watch(c.vgPreload,function(a,b){e&&a==b||!a?d.mediaElement.removeAttr("preload"):(e=a,d.mediaElement.attr("preload",e))})}}}}]).directive("vgNativeControls",[function(){return{restrict:"A",require:"^videogular",link:{pre:function(a,b,c,d){var e;a.$watch(c.vgNativeControls,function(a,b){e&&a==b||!a?d.mediaElement.removeAttr("controls"):(e=a,d.mediaElement.attr("controls",""))})}}}}]);