Files
SamiAhmed7777 0b7e2d0a5b feat: Add comprehensive documentation suite and reorganize project structure
- Created complete documentation in docs/ directory
- Added PROJECT_OVERVIEW.md with feature highlights and getting started guide
- Added ARCHITECTURE.md with system design and technical details
- Added SECURITY.md with comprehensive security implementation guide
- Added DEVELOPMENT.md with development workflows and best practices
- Added DEPLOYMENT.md with production deployment instructions
- Added API.md with complete REST API documentation
- Added CONTRIBUTING.md with contribution guidelines
- Added CHANGELOG.md with version history and migration notes
- Reorganized all documentation files into docs/ directory for better organization
- Updated README.md with proper documentation links and quick navigation
- Enhanced project structure with professional documentation standards
2025-10-21 00:39:45 -07:00

2 lines
33 KiB
JavaScript

(function(window,videojs,undefined){"use strict";var VIDEO_EVENTS=videojs.getComponent("Html5").Events,cancelContentPlay=function(player){if(player.ads.cancelPlayTimeout){return}player.ads.cancelPlayTimeout=window.setTimeout(function(){player.ads.cancelPlayTimeout=null;if(!player.paused()){player.pause()}player.one("contentplayback",function(){if(player.paused()){player.play()}})},1)},isLive=function(player){if(player.duration()===Infinity){return true}else if(videojs.browser.IOS_VERSION==="8"&&player.duration()===0){return true}return false},getPlayerSnapshot=function(player){var currentTime;if(videojs.browser.IS_IOS&&isLive(player)){currentTime=player.currentTime()-player.seekable().end(0)}else{currentTime=player.currentTime()}var tech=player.$(".vjs-tech"),tracks=player.remoteTextTracks?player.remoteTextTracks():[],track,i,suppressedTracks=[],snapshot={ended:player.ended(),currentSrc:player.currentSrc(),src:player.src(),currentTime:currentTime,type:player.currentType()};if(tech){snapshot.nativePoster=tech.poster;snapshot.style=tech.getAttribute("style")}i=tracks.length;while(i--){track=tracks[i];suppressedTracks.push({track:track,mode:track.mode});track.mode="disabled"}snapshot.suppressedTracks=suppressedTracks;return snapshot},restorePlayerSnapshot=function(player,snapshot){var tech=player.$(".vjs-tech"),attempts=20,suppressedTracks=snapshot.suppressedTracks,trackSnapshot,restoreTracks=function(){var i=suppressedTracks.length;while(i--){trackSnapshot=suppressedTracks[i];trackSnapshot.track.mode=trackSnapshot.mode}},resume=function(){var ended=false;var updateEnded=function(){ended=true};var currentTime;if(videojs.browser.IS_IOS&&isLive(player)){if(snapshot.currentTime<0){currentTime=player.seekable().end(0)+snapshot.currentTime;player.currentTime(currentTime)}}else{player.currentTime(snapshot.currentTime)}if(!snapshot.ended){player.play()}else{player.ads.resumeEndedTimeout=window.setTimeout(function(){if(!ended){player.play()}player.off("ended",updateEnded);player.ads.resumeEndedTimeout=null},250);player.on("ended",updateEnded);player.on("dispose",function(){window.clearTimeout(player.ads.resumeEndedTimeout)})}},tryToResume=function(){player.off("contentcanplay",tryToResume);if(player.ads.tryToResumeTimeout_){player.clearTimeout(player.ads.tryToResumeTimeout_);player.ads.tryToResumeTimeout_=null}tech=player.el().querySelector(".vjs-tech");if(tech.readyState>1){return resume()}if(tech.seekable===undefined){return resume()}if(tech.seekable.length>0){return resume()}if(attempts--){window.setTimeout(tryToResume,50)}else{(function(){try{resume()}catch(e){videojs.log.warn("Failed to resume the content after an advertisement",e)}})()}},srcChanged;if(snapshot.nativePoster){tech.poster=snapshot.nativePoster}if("style"in snapshot){tech.setAttribute("style",snapshot.style||"")}srcChanged=player.src()!==snapshot.src||player.currentSrc()!==snapshot.currentSrc;if(srcChanged){player.one("contentloadedmetadata",restoreTracks);player.src({src:snapshot.currentSrc,type:snapshot.type});player.load();player.one("contentcanplay",tryToResume);player.ads.tryToResumeTimeout_=player.setTimeout(tryToResume,2e3)}else if(!player.ended()||!snapshot.ended){restoreTracks();player.play()}},removeNativePoster=function(player){var tech=player.$(".vjs-tech");if(tech){tech.removeAttribute("poster")}},defaults={timeout:5e3,prerollTimeout:100,postrollTimeout:100,debug:false},adFramework=function(options){var player=this;var settings=videojs.mergeOptions(defaults,options);var fsmHandler;(function(){var videoEvents=VIDEO_EVENTS.concat(["firstplay","loadedalldata"]);var returnTrue=function(){return true};var triggerEvent=function(type,event){event.isImmediatePropagationStopped=returnTrue;event.cancelBubble=true;event.isPropagationStopped=returnTrue;player.trigger({type:type+event.type,state:player.ads.state,originalEvent:event})};player.on(videoEvents,function redispatch(event){if(player.ads.state==="ad-playback"){triggerEvent("ad",event)}else if(player.ads.state==="content-playback"&&event.type==="ended"){triggerEvent("content",event)}else if(player.ads.state==="content-resuming"){if(player.ads.snapshot){if(player.currentSrc()!==player.ads.snapshot.currentSrc){if(event.type==="loadstart"){return}return triggerEvent("content",event)}else if(player.ads.snapshot.ended){if(event.type==="pause"||event.type==="ended"){player.addClass("vjs-has-started");return}return triggerEvent("content",event)}}if(event.type!=="playing"){triggerEvent("content",event)}}})})();player.on(["addurationchange","adcanplay"],function(){if(typeof player.ads.snapshot!=="undefined"&&player.currentSrc()===player.ads.snapshot.currentSrc){return}player.play()});player.on("nopreroll",function(){player.ads.nopreroll_=true});player.on("nopostroll",function(){player.ads.nopostroll_=true});player.ads={state:"content-set",startLinearAdMode:function(){if(player.ads.state==="preroll?"||player.ads.state==="content-playback"||player.ads.state==="postroll?"){player.trigger("adstart")}},endLinearAdMode:function(){if(player.ads.state==="ad-playback"){player.trigger("adend")}},skipLinearAdMode:function(){if(player.ads.state!=="ad-playback"){player.trigger("adskip")}}};fsmHandler=function(event){var fsm={"content-set":{events:{adscanceled:function(){this.state="content-playback"},adsready:function(){this.state="ads-ready"},play:function(){this.state="ads-ready?";cancelContentPlay(player);removeNativePoster(player)},adserror:function(){this.state="content-playback"},adskip:function(){this.state="content-playback"}}},"ads-ready":{events:{play:function(){this.state="preroll?";cancelContentPlay(player)},adskip:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"}}},"preroll?":{enter:function(){if(player.ads.nopreroll_){player.trigger("readyforpreroll");player.trigger("nopreroll")}else{player.addClass("vjs-ad-loading");player.ads.adTimeoutTimeout=window.setTimeout(function(){player.trigger("adtimeout")},settings.prerollTimeout);player.trigger("readyforpreroll")}},leave:function(){window.clearTimeout(player.ads.adTimeoutTimeout);player.removeClass("vjs-ad-loading")},events:{play:function(){cancelContentPlay(player)},adstart:function(){this.state="ad-playback"},adskip:function(){this.state="content-playback"},adtimeout:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"},nopreroll:function(){this.state="content-playback"}}},"ads-ready?":{enter:function(){player.addClass("vjs-ad-loading");player.ads.adTimeoutTimeout=window.setTimeout(function(){player.trigger("adtimeout")},settings.timeout)},leave:function(){window.clearTimeout(player.ads.adTimeoutTimeout);player.removeClass("vjs-ad-loading")},events:{play:function(){cancelContentPlay(player)},adscanceled:function(){this.state="content-playback"},adsready:function(){this.state="preroll?"},adskip:function(){this.state="content-playback"},adtimeout:function(){this.state="content-playback"},adserror:function(){this.state="content-playback"}}},"ad-playback":{enter:function(){if(videojs.browser.IS_IOS||player.duration()!==Infinity){this.snapshot=getPlayerSnapshot(player)}if(!videojs.browser.IS_IOS&&player.duration()===Infinity){this.preAdVolume_=player.volume();player.volume(0)}player.addClass("vjs-ad-playing");removeNativePoster(player);if(player.ads.cancelPlayTimeout){window.clearTimeout(player.ads.cancelPlayTimeout);player.ads.cancelPlayTimeout=null}},leave:function(){player.removeClass("vjs-ad-playing");if(videojs.browser.IS_IOS||player.duration()!==Infinity){restorePlayerSnapshot(player,this.snapshot)}if(!videojs.browser.IS_IOS&&player.duration()===Infinity){player.volume(this.preAdVolume_)}if(player.ads.triggerevent!=="adend"){player.trigger("adend")}},events:{adend:function(){this.state="content-resuming"},adserror:function(){this.state="content-resuming"}}},"content-resuming":{enter:function(){if(this.snapshot&&this.snapshot.ended){window.clearTimeout(player.ads._fireEndedTimeout);player.ads._fireEndedTimeout=window.setTimeout(function(){player.trigger("ended")},1e3)}},leave:function(){window.clearTimeout(player.ads._fireEndedTimeout)},events:{contentupdate:function(){this.state="content-set"},contentresumed:function(){this.state="content-playback"},playing:function(){this.state="content-playback"},ended:function(){this.state="content-playback"}}},"postroll?":{enter:function(){this.snapshot=getPlayerSnapshot(player);if(player.ads.nopostroll_){player.ads.state="content-resuming";window.setTimeout(function(){player.trigger("ended")},1)}else{player.addClass("vjs-ad-loading");player.ads.adTimeoutTimeout=window.setTimeout(function(){player.trigger("adtimeout")},settings.postrollTimeout)}},leave:function(){window.clearTimeout(player.ads.adTimeoutTimeout);player.removeClass("vjs-ad-loading")},events:{adstart:function(){this.state="ad-playback"},adskip:function(){this.state="content-resuming";window.setTimeout(function(){player.trigger("ended")},1)},adtimeout:function(){this.state="content-resuming";window.setTimeout(function(){player.trigger("ended")},1)},adserror:function(){this.state="content-resuming";window.setTimeout(function(){player.trigger("ended")},1)}}},"content-playback":{enter:function(){if(player.ads.cancelPlayTimeout){window.clearTimeout(player.ads.cancelPlayTimeout);player.ads.cancelPlayTimeout=null}player.trigger({type:"contentplayback",triggerevent:player.ads.triggerevent})},events:{adsready:function(){player.trigger("readyforpreroll")},adstart:function(){this.state="ad-playback"},contentupdate:function(){if(player.paused()){this.state="content-set"}else{this.state="ads-ready?"}},contentended:function(){this.state="postroll?"}}}};(function(state){var noop=function(){};((fsm[state].events||{})[event.type]||noop).apply(player.ads);if(state!==player.ads.state){player.ads.triggerevent=event.type;(fsm[state].leave||noop).apply(player.ads);(fsm[player.ads.state].enter||noop).apply(player.ads);if(settings.debug){videojs.log("ads",player.ads.triggerevent+" triggered: "+state+" -> "+player.ads.state)}}})(player.ads.state)};player.on(VIDEO_EVENTS.concat(["adtimeout","contentupdate","contentplaying","contentended","contentresumed","adsready","adserror","adscanceled","adstart","adend","adskip","nopreroll"]),fsmHandler);player.ads.contentSrc=player.currentSrc();(function(){var checkSrc=function(){var src;if(player.ads.state!=="ad-playback"){src=player.currentSrc();if(src!==player.ads.contentSrc){player.trigger({type:"contentupdate",oldValue:player.ads.contentSrc,newValue:src});player.ads.contentSrc=src}}};player.on("loadstart",checkSrc);window.setTimeout(checkSrc,1)})();if(!player.paused()){fsmHandler({type:"play"})}};videojs.plugin("ads",adFramework)})(window,videojs);
(function(factory){if(typeof define==="function"&&define["amd"]){define(["video.js","videojs-contrib-ads"],function(videojs){factory(window,document,videojs)})}else if(typeof exports==="object"&&typeof module==="object"){var vjs=require("video.js");require("videojs-contrib-ads");factory(window,document,vjs)}else{factory(window,document,videojs)}})(function(window,document,videojs){"use strict";var extend=function(obj){var arg;var index;var key;for(index=1;index<arguments.length;index++){arg=arguments[index];for(key in arg){if(arg.hasOwnProperty(key)){obj[key]=arg[key]}}}return obj};var ima_defaults={debug:false,timeout:5e3,prerollTimeout:100,adLabel:"Advertisement",showControlsForJSAds:true};var init=function(options,readyCallback){this.ima=new ImaPlugin(this,options,readyCallback)};var ImaPlugin=function(player,options,readyCallback){this.player=player;var assignControlAttributes_=function(element,controlName){element.id=this.controlPrefix+controlName;element.className=this.controlPrefix+controlName+" "+controlName}.bind(this);var getClassRegexp_=function(className){return new RegExp("(^|[^A-Za-z-])"+className+"((?![A-Za-z-])|$)","gi")};var addClass_=function(element,classToAdd){if(getClassRegexp_(classToAdd).test(element.className)){return element}return element.className=element.className.trim()+" "+classToAdd};var removeClass_=function(element,classToRemove){var classRegexp=getClassRegexp_(classToRemove);if(!classRegexp.test(element.className)){return element}return element.className=element.className.trim().replace(classRegexp,"")};var createAdContainer_=function(){this.vjsControls=this.player.getChild("controlBar");this.adContainerDiv=this.vjsControls.el().parentNode.appendChild(document.createElement("div"));assignControlAttributes_(this.adContainerDiv,"ima-ad-container");this.adContainerDiv.style.position="absolute";this.adContainerDiv.style.zIndex=1111;this.adContainerDiv.addEventListener("mouseenter",showAdControls_,false);this.adContainerDiv.addEventListener("mouseleave",hideAdControls_,false);createControls_();this.adDisplayContainer=new google.ima.AdDisplayContainer(this.adContainerDiv,this.contentPlayer)}.bind(this);var createControls_=function(){this.controlsDiv=document.createElement("div");assignControlAttributes_(this.controlsDiv,"ima-controls-div");this.controlsDiv.style.width="100%";this.countdownDiv=document.createElement("div");assignControlAttributes_(this.countdownDiv,"ima-countdown-div");this.countdownDiv.innerHTML=this.settings.adLabel;this.countdownDiv.style.display=this.showCountdown?"block":"none";this.seekBarDiv=document.createElement("div");assignControlAttributes_(this.seekBarDiv,"ima-seek-bar-div");this.seekBarDiv.style.width="100%";this.progressDiv=document.createElement("div");assignControlAttributes_(this.progressDiv,"ima-progress-div");this.playPauseDiv=document.createElement("div");assignControlAttributes_(this.playPauseDiv,"ima-play-pause-div");addClass_(this.playPauseDiv,"ima-playing");this.playPauseDiv.addEventListener("click",onAdPlayPauseClick_,false);this.muteDiv=document.createElement("div");assignControlAttributes_(this.muteDiv,"ima-mute-div");addClass_(this.muteDiv,"ima-non-muted");this.muteDiv.addEventListener("click",onAdMuteClick_,false);this.sliderDiv=document.createElement("div");assignControlAttributes_(this.sliderDiv,"ima-slider-div");this.sliderDiv.addEventListener("mousedown",onAdVolumeSliderMouseDown_,false);this.sliderLevelDiv=document.createElement("div");assignControlAttributes_(this.sliderLevelDiv,"ima-slider-level-div");this.fullscreenDiv=document.createElement("div");assignControlAttributes_(this.fullscreenDiv,"ima-fullscreen-div");addClass_(this.fullscreenDiv,"ima-non-fullscreen");this.fullscreenDiv.addEventListener("click",onAdFullscreenClick_,false);this.adContainerDiv.appendChild(this.controlsDiv);this.controlsDiv.appendChild(this.countdownDiv);this.controlsDiv.appendChild(this.seekBarDiv);this.controlsDiv.appendChild(this.playPauseDiv);this.controlsDiv.appendChild(this.muteDiv);this.controlsDiv.appendChild(this.sliderDiv);this.controlsDiv.appendChild(this.fullscreenDiv);this.seekBarDiv.appendChild(this.progressDiv);this.sliderDiv.appendChild(this.sliderLevelDiv)}.bind(this);this.initializeAdDisplayContainer=function(){this.adDisplayContainerInitialized=true;this.adDisplayContainer.initialize()}.bind(this);this.requestAds=function(){if(!this.adDisplayContainerInitialized){this.adDisplayContainer.initialize()}var adsRequest=new google.ima.AdsRequest;if(this.settings.adTagUrl){adsRequest.adTagUrl=this.settings.adTagUrl}else{adsRequest.adsResponse=this.settings.adsResponse}if(this.settings.forceNonLinearFullSlot){adsRequest.forceNonLinearFullSlot=true}adsRequest.linearAdSlotWidth=this.getPlayerWidth();adsRequest.linearAdSlotHeight=this.getPlayerHeight();adsRequest.nonLinearAdSlotWidth=this.settings.nonLinearWidth||this.getPlayerWidth();adsRequest.nonLinearAdSlotHeight=this.settings.nonLinearHeight||this.getPlayerHeight()/3;adsRequest.setAdWillAutoPlay(this.settings.adWillAutoPlay);this.adsLoader.requestAds(adsRequest)}.bind(this);var onAdsManagerLoaded_=function(adsManagerLoadedEvent){this.adsManager=adsManagerLoadedEvent.getAdsManager(this.contentPlayheadTracker,this.adsRenderingSettings);this.adsManager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdError_);this.adsManager.addEventListener(google.ima.AdEvent.Type.AD_BREAK_READY,onAdBreakReady_);this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED,this.onContentPauseRequested_);this.adsManager.addEventListener(google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED,this.onContentResumeRequested_);this.adsManager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED,onAllAdsCompleted_);this.adsManager.addEventListener(google.ima.AdEvent.Type.LOADED,onAdLoaded_);this.adsManager.addEventListener(google.ima.AdEvent.Type.STARTED,onAdStarted_);this.adsManager.addEventListener(google.ima.AdEvent.Type.CLICK,onAdPlayPauseClick_);this.adsManager.addEventListener(google.ima.AdEvent.Type.COMPLETE,this.onAdComplete_);this.adsManager.addEventListener(google.ima.AdEvent.Type.SKIPPED,this.onAdComplete_);if(!this.autoPlayAdBreaks){try{var initWidth=this.getPlayerWidth();var initHeight=this.getPlayerHeight();this.adsManagerDimensions.width=initWidth;this.adsManagerDimensions.height=initHeight;this.adsManager.init(initWidth,initHeight,google.ima.ViewMode.NORMAL);this.adsManager.setVolume(this.player.muted()?0:this.player.volume())}catch(adError){onAdError_(adError)}}this.player.trigger("adsready")}.bind(this);this.start=function(){window.console.log("WARNING: player.ima.start is deprecated. Use "+"player.ima.startFromReadyCallback instead.")};this.startFromReadyCallback=function(){if(this.autoPlayAdBreaks){try{this.adsManager.init(this.getPlayerWidth(),this.getPlayerHeight(),google.ima.ViewMode.NORMAL);this.adsManager.setVolume(this.player.muted()?0:this.player.volume());this.adsManager.start()}catch(adError){onAdError_(adError)}}}.bind(this);var onAdsLoaderError_=function(event){window.console.log("AdsLoader error: "+event.getError());this.adContainerDiv.style.display="none";if(this.adsManager){this.adsManager.destroy()}this.player.trigger({type:"adserror",data:{AdError:event.getError(),AdErrorEvent:event}})}.bind(this);var onAdError_=function(adErrorEvent){var errorMessage=adErrorEvent.getError!==undefined?adErrorEvent.getError():adErrorEvent.stack;window.console.log("Ad error: "+errorMessage);this.vjsControls.show();this.adsManager.destroy();this.adContainerDiv.style.display="none";this.player.trigger({type:"adserror",data:{AdError:errorMessage,AdErrorEvent:adErrorEvent}})}.bind(this);var onAdBreakReady_=function(adEvent){this.adBreakReadyListener(adEvent)}.bind(this);this.playAdBreak=function(){if(!this.autoPlayAdBreaks){this.adsManager.start()}}.bind(this);this.onContentPauseRequested_=function(adEvent){this.adsActive=true;this.adPlaying=true;this.contentSource=this.player.currentSrc();this.player.off("ended",this.localContentEndedListener);if(adEvent.getAd().getAdPodInfo().getPodIndex()!=-1){this.player.ads.startLinearAdMode()}this.adContainerDiv.style.display="block";var contentType=adEvent.getAd().getContentType();if(contentType==="application/javascript"&&!this.settings.showControlsForJSAds){this.controlsDiv.style.display="none"}else{this.controlsDiv.style.display="block"}this.vjsControls.hide();showPlayButton();this.player.pause()}.bind(this);this.onContentResumeRequested_=function(adEvent){this.adsActive=false;this.adPlaying=false;this.player.on("ended",this.localContentEndedListener);if(this.currentAd==null||this.currentAd.isLinear()){this.adContainerDiv.style.display="none"}this.vjsControls.show();if(!this.currentAd){this.player.ads.endLinearAdMode()}else if(!this.contentComplete&&this.currentAd.getAdPodInfo().getPodIndex()!=-1){this.player.ads.endLinearAdMode()}this.controlsDiv.style.display="none";this.countdownDiv.innerHTML=""}.bind(this);var onAllAdsCompleted_=function(adEvent){this.allAdsCompleted=true;this.adContainerDiv.style.display="none";if(this.contentComplete==true){if(this.contentPlayer.src!=this.contentSource){this.player.src(this.contentSource)}for(var index in this.contentAndAdsEndedListeners){this.contentAndAdsEndedListeners[index]()}}}.bind(this);var onAdLoaded_=function(adEvent){if(!adEvent.getAd().isLinear()){this.player.play()}}.bind(this);var onAdStarted_=function(adEvent){this.currentAd=adEvent.getAd();if(this.currentAd.isLinear()){this.adTrackingTimer=setInterval(onAdPlayheadTrackerInterval_,250);removeClass_(this.adContainerDiv,"bumpable-ima-ad-container")}else{addClass_(this.adContainerDiv,"bumpable-ima-ad-container")}this.adContainerDiv.style.display="block"}.bind(this);this.onAdComplete_=function(adEvent){if(this.currentAd.isLinear()){clearInterval(this.adTrackingTimer)}}.bind(this);var onAdPlayheadTrackerInterval_=function(){var remainingTime=this.adsManager.getRemainingTime();var duration=this.currentAd.getDuration();var currentTime=duration-remainingTime;currentTime=currentTime>0?currentTime:0;var isPod=false;var totalAds=0;var adPosition;if(this.currentAd.getAdPodInfo()){isPod=true;adPosition=this.currentAd.getAdPodInfo().getAdPosition();totalAds=this.currentAd.getAdPodInfo().getTotalAds()}var remainingMinutes=Math.floor(remainingTime/60);var remainingSeconds=Math.floor(remainingTime%60);if(remainingSeconds.toString().length<2){remainingSeconds="0"+remainingSeconds}var podCount=": ";if(isPod&&totalAds>1){podCount=" ("+adPosition+" of "+totalAds+"): "}this.countdownDiv.innerHTML=this.settings.adLabel+podCount+remainingMinutes+":"+remainingSeconds;var playProgressRatio=currentTime/duration;var playProgressPercent=playProgressRatio*100;this.progressDiv.style.width=playProgressPercent+"%"}.bind(this);this.getPlayerWidth=function(){var retVal=parseInt(getComputedStyle(this.player.el()).width,10)||this.player.width();return retVal}.bind(this);this.getPlayerHeight=function(){var retVal=parseInt(getComputedStyle(this.player.el()).height,10)||this.player.height();return retVal}.bind(this);var hideAdControls_=function(){this.controlsDiv.style.height="14px";this.playPauseDiv.style.display="none";this.muteDiv.style.display="none";this.sliderDiv.style.display="none";this.fullscreenDiv.style.display="none"}.bind(this);var showAdControls_=function(){this.controlsDiv.style.height="37px";this.playPauseDiv.style.display="block";this.muteDiv.style.display="block";this.sliderDiv.style.display="block";this.fullscreenDiv.style.display="block"}.bind(this);var showPauseButton=function(){addClass_(this.playPauseDiv,"ima-paused");removeClass_(this.playPauseDiv,"ima-playing")}.bind(this);var showPlayButton=function(){addClass_(this.playPauseDiv,"ima-playing");removeClass_(this.playPauseDiv,"ima-paused")}.bind(this);var onAdPlayPauseClick_=function(){if(this.adPlaying){showPauseButton();this.adsManager.pause();this.adPlaying=false}else{showPlayButton();this.adsManager.resume();this.adPlaying=true}}.bind(this);var onAdMuteClick_=function(){if(this.adMuted){addClass_(this.muteDiv,"ima-non-muted");removeClass_(this.muteDiv,"ima-muted");this.adsManager.setVolume(1);this.player.muted(false);this.adMuted=false;this.sliderLevelDiv.style.width=this.player.volume()*100+"%"}else{addClass_(this.muteDiv,"ima-muted");removeClass_(this.muteDiv,"ima-non-muted");this.adsManager.setVolume(0);this.player.muted(true);this.adMuted=true;this.sliderLevelDiv.style.width="0%"}}.bind(this);var onAdVolumeSliderMouseDown_=function(){document.addEventListener("mouseup",onMouseUp_,false);document.addEventListener("mousemove",onMouseMove_,false)};var onMouseMove_=function(event){setVolumeSlider_(event)};var onMouseUp_=function(event){setVolumeSlider_(event);document.removeEventListener("mousemove",onMouseMove_);document.removeEventListener("mouseup",onMouseUp_)};var setVolumeSlider_=function(event){var percent=(event.clientX-this.sliderDiv.getBoundingClientRect().left)/this.sliderDiv.offsetWidth;percent*=100;percent=Math.min(Math.max(percent,0),100);this.sliderLevelDiv.style.width=percent+"%";this.player.volume(percent/100);this.adsManager.setVolume(percent/100);if(this.player.volume()==0){addClass_(this.muteDiv,"ima-muted");removeClass_(this.muteDiv,"ima-non-muted");this.player.muted(true);this.adMuted=true}else{addClass_(this.muteDiv,"ima-non-muted");removeClass_(this.muteDiv,"ima-muted");this.player.muted(false);this.adMuted=false}}.bind(this);var onAdFullscreenClick_=function(){if(this.player.isFullscreen()){this.player.exitFullscreen()}else{this.player.requestFullscreen()}}.bind(this);var onFullscreenChange_=function(){if(this.player.isFullscreen()){addClass_(this.fullscreenDiv,"ima-fullscreen");removeClass_(this.fullscreenDiv,"ima-non-fullscreen");if(this.adsManager){this.adsManager.resize(window.screen.width,window.screen.height,google.ima.ViewMode.FULLSCREEN)}}else{addClass_(this.fullscreenDiv,"ima-non-fullscreen");removeClass_(this.fullscreenDiv,"ima-fullscreen");if(this.adsManager){this.adsManager.resize(this.getPlayerWidth(),this.getPlayerHeight(),google.ima.ViewMode.NORMAL)}}}.bind(this);var onVolumeChange_=function(){var newVolume=this.player.muted()?0:this.player.volume();if(this.adsManager){this.adsManager.setVolume(newVolume)}if(newVolume==0){this.adMuted=true;addClass_(this.muteDiv,"ima-muted");removeClass_(this.muteDiv,"ima-non-muted");this.sliderLevelDiv.style.width="0%"}else{this.adMuted=false;addClass_(this.muteDiv,"ima-non-muted");removeClass_(this.muteDiv,"ima-muted");this.sliderLevelDiv.style.width=newVolume*100+"%"}}.bind(this);var seekContentToZero_=function(){this.player.off("loadedmetadata",seekContentToZero_);this.player.currentTime(0)}.bind(this);var playContentFromZero_=function(){this.player.off("loadedmetadata",playContentFromZero_);this.player.currentTime(0);this.player.play()}.bind(this);var resetIMA_=function(){this.adsActive=false;this.adPlaying=false;this.player.on("ended",this.localContentEndedListener);if(this.currentAd&&this.currentAd.isLinear()){this.adContainerDiv.style.display="none"}this.vjsControls.show();this.player.ads.endLinearAdMode();if(this.adTrackingTimer){clearInterval(this.adTrackingTimer)}if(this.adsManager){this.adsManager.destroy();this.adsManager=null}if(this.adsLoader&&!this.contentComplete){this.adsLoader.contentComplete()}this.contentComplete=false;this.allAdsCompleted=false}.bind(this);this.addEventListener=function(event,callback){if(this.adsManager){this.adsManager.addEventListener(event,callback)}}.bind(this);this.getAdsManager=function(){return this.adsManager}.bind(this);this.setContent=function(contentSrc,adTag,playOnLoad){window.console.log("WARNING: player.ima.setContent is deprecated. Use "+"player.ima.setContentWithAdTag instead.");this.setContentWithAdTag(contentSrc,adTag,playOnLoad)}.bind(this);this.setContentWithAdTag=function(contentSrc,adTag,playOnLoad){resetIMA_();this.settings.adTagUrl=adTag?adTag:this.settings.adTagUrl;changeSource_(contentSrc,playOnLoad)}.bind(this);this.setContentWithAdsResponse=function(contentSrc,adsResponse,playOnLoad){resetIMA_();this.settings.adsResponse=adsResponse?adsResponse:this.settings.adsResponse;changeSource_(contentSrc,playOnLoad)}.bind(this);this.changeAdTag=function(adTag){resetIMA_();this.settings.adTagUrl=adTag}.bind(this);var changeSource_=function(contentSrc,playOnLoad){if(!!this.player.currentSrc()){this.player.currentTime(0);this.player.pause()}if(contentSrc){this.player.src(contentSrc)}if(playOnLoad){this.player.on("loadedmetadata",playContentFromZero_)}else{this.player.on("loadedmetadata",seekContentToZero_)}}.bind(this);this.addContentEndedListener=function(listener){this.contentEndedListeners.push(listener)}.bind(this);this.addContentAndAdsEndedListener=function(listener){this.contentAndAdsEndedListeners.push(listener)}.bind(this);this.setAdBreakReadyListener=function(listener){this.adBreakReadyListener=listener}.bind(this);this.pauseAd=function(){if(this.adsActive&&this.adPlaying){showPauseButton();this.adsManager.pause();this.adPlaying=false}}.bind(this);this.resumeAd=function(){if(this.adsActive&&!this.adPlaying){showPlayButton();this.adsManager.resume();this.adPlaying=true}}.bind(this);var setUpPlayerIntervals_=function(){this.updateTimeIntervalHandle=setInterval(updateCurrentTime_,this.seekCheckInterval);this.seekCheckIntervalHandle=setInterval(checkForSeeking_,this.seekCheckInterval);this.resizeCheckIntervalHandle=setInterval(checkForResize_,this.resizeCheckInterval)}.bind(this);var updateCurrentTime_=function(){if(!this.contentPlayheadTracker.seeking){this.contentPlayheadTracker.currentTime=this.player.currentTime()}}.bind(this);var checkForSeeking_=function(){var tempCurrentTime=this.player.currentTime();var diff=(tempCurrentTime-this.contentPlayheadTracker.previousTime)*1e3;if(Math.abs(diff)>this.seekCheckInterval+this.seekThreshold){this.contentPlayheadTracker.seeking=true}else{this.contentPlayheadTracker.seeking=false}this.contentPlayheadTracker.previousTime=this.player.currentTime()}.bind(this);var checkForResize_=function(){var currentWidth=this.getPlayerWidth();var currentHeight=this.getPlayerHeight();if(this.adsManager&&(currentWidth!=this.adsManagerDimensions.width||currentHeight!=this.adsManagerDimensions.height)){this.adsManagerDimensions.width=currentWidth;this.adsManagerDimensions.height=currentHeight;this.adsManager.resize(currentWidth,currentHeight,google.ima.ViewMode.NORMAL)}}.bind(this);this.setShowCountdown=function(showCountdownIn){this.showCountdown=showCountdownIn;this.countdownDiv.style.display=this.showCountdown?"block":"none"}.bind(this);this.VERSION="0.2.0";this.settings;this.controlPrefix;this.contentPlayer;this.showCountdown;this.autoPlayAdBreaks;this.vjsControls;this.adContainerDiv;this.controlsDiv;this.countdownDiv;this.seekBarDiv;this.progressDiv;this.playPauseDiv;this.muteDiv;this.sliderDiv;this.sliderLevelDiv;this.fullscreenDiv;this.adDisplayContainer;this.adDisplayContainerInitialized=false;this.adsLoader;this.adsManager;this.adsRenderingSettings=null;this.adTagUrl;this.adsResponse;this.currentAd;this.contentTrackingTimer;this.adTrackingTimer;this.adsActive=false;this.adPlaying=false;this.adMuted=false;this.contentComplete=false;this.allAdsCompleted=false;this.updateTimeIntervalHandle;this.seekCheckIntervalHandle;this.seekCheckInterval=1e3;this.resizeCheckIntervalHandle;this.resizeCheckInterval=250;this.seekThreshold=100;this.contentPlayheadTracker={currentTime:0,previousTime:0,seeking:false,duration:0};this.adPlayheadTracker={currentTime:0,duration:0,isPod:false,adPosition:0,totalAds:0};this.adsManagerDimensions={width:0,height:0};this.contentEndedListeners=[];this.contentAndAdsEndedListeners=[];this.adBreakReadyListener=undefined;this.contentSource="";this.localContentEndedListener=function(){if(this.adsLoader&&!this.contentComplete){this.adsLoader.contentComplete();this.contentComplete=true}for(var index in this.contentEndedListeners){this.contentEndedListeners[index]()}if(this.allAdsCompleted){for(var index in this.contentAndAdsEndedListeners){this.contentAndAdsEndedListeners[index]()}}clearInterval(this.updateTimeIntervalHandle);clearInterval(this.seekCheckIntervalHandle);clearInterval(this.resizeCheckIntervalHandle);if(this.player.el()){this.player.one("play",setUpPlayerIntervals_)}}.bind(this);this.playerDisposedListener=function(){this.contentEndedListeners,this.contentAndAdsEndedListeners=[],[];this.contentComplete=true;this.player.off("ended",this.localContentEndedListener);if(this.player.ads.adTimeoutTimeout){clearTimeout(this.player.ads.adTimeoutTimeout)}var intervalsToClear=[this.updateTimeIntervalHandle,this.seekCheckIntervalHandle,this.adTrackingTimer,this.resizeCheckIntervalHandle];for(var index in intervalsToClear){var interval=intervalsToClear[index];if(interval){clearInterval(interval)}}if(this.adsManager){this.adsManager.destroy();this.adsManager=null}}.bind(this);this.settings=extend({},ima_defaults,options||{});if(!this.settings["id"]){window.console.log("Error: must provide id of video.js div");return}this.controlPrefix=this.settings.id+"_"||"";this.contentPlayer=document.getElementById(this.settings["id"]+"_html5_api");if(this.contentPlayer.hasAttribute("autoplay")){this.settings["adWillAutoPlay"]=this.settings["adWillAutoPlay"]||true}this.showCountdown=true;if(this.settings["showCountdown"]==false){this.showCountdown=false}this.autoPlayAdBreaks=true;if(this.settings["autoPlayAdBreaks"]==false){this.autoPlayAdBreaks=false}player.one("play",setUpPlayerIntervals_);player.on("ended",this.localContentEndedListener);player.on("dispose",this.playerDisposedListener);var contrib_ads_defaults={debug:this.settings.debug,timeout:this.settings.timeout,prerollTimeout:this.settings.prerollTimeout};var ads_plugin_settings=extend({},contrib_ads_defaults,options["contribAdsSettings"]||{});player.ads(ads_plugin_settings);this.adsRenderingSettings=new google.ima.AdsRenderingSettings;this.adsRenderingSettings.restoreCustomPlaybackStateOnAdBreakComplete=true;if(this.settings["adsRenderingSettings"]){for(var setting in this.settings["adsRenderingSettings"]){this.adsRenderingSettings[setting]=this.settings["adsRenderingSettings"][setting]}}if(this.settings["locale"]){google.ima.settings.setLocale(this.settings["locale"])}createAdContainer_();this.adsLoader=new google.ima.AdsLoader(this.adDisplayContainer);this.adsLoader.getSettings().setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.ENABLED);if(this.settings.vpaidAllowed==false){this.adsLoader.getSettings().setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.DISABLED)}if(this.settings.vpaidMode){this.adsLoader.getSettings().setVpaidMode(this.settings.vpaidMode)}if(this.settings.locale){this.adsLoader.getSettings().setLocale(this.settings.locale)}if(this.settings.numRedirects){this.adsLoader.getSettings().setNumRedirects(this.settings.numRedirects)}this.adsLoader.getSettings().setPlayerType("videojs-ima");this.adsLoader.getSettings().setPlayerVersion(this.VERSION);this.adsLoader.getSettings().setAutoPlayAdBreaks(this.autoPlayAdBreaks);this.adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,onAdsManagerLoaded_,false);this.adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdsLoaderError_,false);if(!readyCallback){readyCallback=this.startFromReadyCallback}player.on("readyforpreroll",readyCallback);player.ready(function(){player.on("fullscreenchange",onFullscreenChange_);player.on("volumechange",onVolumeChange_)})};videojs.plugin("ima",init)});