diff --git a/.eslintignore b/.eslintignore index fe5da7b8b19..452b0df9d05 100644 --- a/.eslintignore +++ b/.eslintignore @@ -56,7 +56,8 @@ lib/amd/src/chartjs-lazy.js lib/maxmind/GeoIp2/ lib/maxmind/MaxMind/ lib/ltiprovider/ -media/player/videojs/amd/src/ +media/player/videojs/amd/src/video-lazy.js +media/player/videojs/amd/src/Youtube-lazy.js media/player/videojs/videojs/ mod/assign/feedback/editpdf/fpdi/ repository/s3/S3.php diff --git a/.stylelintignore b/.stylelintignore index cafa933157a..48f1959ef89 100644 --- a/.stylelintignore +++ b/.stylelintignore @@ -57,7 +57,8 @@ lib/amd/src/chartjs-lazy.js lib/maxmind/GeoIp2/ lib/maxmind/MaxMind/ lib/ltiprovider/ -media/player/videojs/amd/src/ +media/player/videojs/amd/src/video-lazy.js +media/player/videojs/amd/src/Youtube-lazy.js media/player/videojs/videojs/ mod/assign/feedback/editpdf/fpdi/ repository/s3/S3.php diff --git a/media/player/videojs/amd/build/Youtube-lazy.min.js b/media/player/videojs/amd/build/Youtube-lazy.min.js new file mode 100644 index 00000000000..7e010eac46c --- /dev/null +++ b/media/player/videojs/amd/build/Youtube-lazy.min.js @@ -0,0 +1 @@ +!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("video.js")):"function"==typeof define&&define.amd?define(["media_videojs/video-lazy"],function(c){return a.Youtube=b(c)}):a.Youtube=b(a.videojs)}(this,function(a){"use strict";function b(){YT.ready(function(){g.isApiReady=!0;for(var a=0;a0}var f=a.getComponent("Tech"),g=a.extend(f,{constructor:function(a,b){f.call(this,a,b),this.setPoster(a.poster),this.setSrc(this.options_.source,!0),setTimeout(function(){this.el_.parentNode.className+=" vjs-youtube",h&&(this.el_.parentNode.className+=" vjs-youtube-mobile"),g.isApiReady?this.initYTPlayer():g.apiReadyQueue.push(this)}.bind(this))},dispose:function(){if(this.ytPlayer)this.ytPlayer.stopVideo(),this.ytPlayer.destroy();else{var a=g.apiReadyQueue.indexOf(this);a!==-1&&g.apiReadyQueue.splice(a,1)}this.ytPlayer=null,this.el_.parentNode.className=this.el_.parentNode.className.replace(" vjs-youtube","").replace(" vjs-youtube-mobile",""),this.el_.remove(),f.prototype.dispose.call(this)},createEl:function(){var a=document.createElement("div");a.setAttribute("id",this.options_.techId),a.setAttribute("style","width:100%;height:100%;top:0;left:0;position:absolute"),a.setAttribute("class","vjs-tech");var b=document.createElement("div");if(b.appendChild(a),!h&&!this.options_.ytControls){var c=document.createElement("div");c.setAttribute("class","vjs-iframe-blocker"),c.setAttribute("style","position:absolute;top:0;left:0;width:100%;height:100%"),c.onclick=function(){this.pause()}.bind(this),b.appendChild(c)}return b},initYTPlayer:function(){var a={controls:0,modestbranding:1,rel:0,showinfo:0,loop:this.options_.loop?1:0};"undefined"!=typeof this.options_.autohide&&(a.autohide=this.options_.autohide),"undefined"!=typeof this.options_.cc_load_policy&&(a.cc_load_policy=this.options_.cc_load_policy),"undefined"!=typeof this.options_.ytControls&&(a.controls=this.options_.ytControls),"undefined"!=typeof this.options_.disablekb&&(a.disablekb=this.options_.disablekb),"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.color&&(a.color=this.options_.color),a.controls?"undefined"!=typeof this.options_.fs&&(a.fs=this.options_.fs):a.fs=0,"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.hl?a.hl=this.options_.hl:"undefined"!=typeof this.options_.language&&(a.hl=this.options_.language.substr(0,2)),"undefined"!=typeof this.options_.iv_load_policy&&(a.iv_load_policy=this.options_.iv_load_policy),"undefined"!=typeof this.options_.list?a.list=this.options_.list:this.url&&"undefined"!=typeof this.url.listId&&(a.list=this.url.listId),"undefined"!=typeof this.options_.listType&&(a.listType=this.options_.listType),"undefined"!=typeof this.options_.modestbranding&&(a.modestbranding=this.options_.modestbranding),"undefined"!=typeof this.options_.playlist&&(a.playlist=this.options_.playlist),"undefined"!=typeof this.options_.playsinline&&(a.playsinline=this.options_.playsinline),"undefined"!=typeof this.options_.rel&&(a.rel=this.options_.rel),"undefined"!=typeof this.options_.showinfo&&(a.showinfo=this.options_.showinfo),"undefined"!=typeof this.options_.start&&(a.start=this.options_.start),"undefined"!=typeof this.options_.theme&&(a.theme=this.options_.theme),this.activeVideoId=this.url?this.url.videoId:null,this.activeList=a.list,this.ytPlayer=new YT.Player(this.options_.techId,{videoId:this.activeVideoId,playerVars:a,events:{onReady:this.onPlayerReady.bind(this),onPlaybackQualityChange:this.onPlayerPlaybackQualityChange.bind(this),onStateChange:this.onPlayerStateChange.bind(this),onError:this.onPlayerError.bind(this)}})},onPlayerReady:function(){this.playerReady_=!0,this.triggerReady(),this.playOnReady?this.play():this.cueOnReady&&(this.ytPlayer.cueVideoById(this.url.videoId),this.activeVideoId=this.url.videoId)},onPlayerPlaybackQualityChange:function(){},onPlayerStateChange:function(a){var b=a.data;if(b!==this.lastState&&!this.errorNumber)switch(this.lastState=b,b){case-1:this.trigger("loadstart"),this.trigger("loadedmetadata"),this.trigger("durationchange");break;case YT.PlayerState.ENDED:this.trigger("ended");break;case YT.PlayerState.PLAYING:this.trigger("timeupdate"),this.trigger("durationchange"),this.trigger("playing"),this.trigger("play"),this.isSeeking&&this.onSeeked();break;case YT.PlayerState.PAUSED:this.trigger("canplay"),this.isSeeking?this.onSeeked():this.trigger("pause");break;case YT.PlayerState.BUFFERING:this.player_.trigger("timeupdate"),this.player_.trigger("waiting")}},onPlayerError:function(a){this.errorNumber=a.data,this.trigger("error"),this.ytPlayer.stopVideo()},error:function(){switch(this.errorNumber){case 5:return{code:"Error while trying to play the video"};case 2:case 100:return{code:"Unable to find the video"};case 101:case 150:return{code:"Playback on other Websites has been disabled by the video owner."}}return{code:"YouTube unknown error ("+this.errorNumber+")"}},src:function(a){return a&&this.setSrc({src:a}),this.source},poster:function(){return h?null:this.poster_},setPoster:function(a){this.poster_=a},setSrc:function(a){a&&a.src&&(delete this.errorNumber,this.source=a,this.url=g.parseUrl(a.src),this.options_.poster||this.url.videoId&&(this.poster_="https://img.youtube.com/vi/"+this.url.videoId+"/0.jpg",this.trigger("posterchange"),this.checkHighResPoster()),this.options_.autoplay&&!h?this.isReady_?this.play():this.playOnReady=!0:this.activeVideoId!==this.url.videoId&&(this.isReady_?(this.ytPlayer.cueVideoById(this.url.videoId),this.activeVideoId=this.url.videoId):this.cueOnReady=!0))},autoplay:function(){return this.options_.autoplay},setAutoplay:function(a){this.options_.autoplay=a},loop:function(){return this.options_.loop},setLoop:function(a){this.options_.loop=a},play:function(){this.url&&this.url.videoId&&(this.wasPausedBeforeSeek=!1,this.isReady_?(this.url.listId&&(this.activeList===this.url.listId?this.ytPlayer.playVideo():(this.ytPlayer.loadPlaylist(this.url.listId),this.activeList=this.url.listId)),this.activeVideoId===this.url.videoId?this.ytPlayer.playVideo():(this.ytPlayer.loadVideoById(this.url.videoId),this.activeVideoId=this.url.videoId)):(this.trigger("waiting"),this.playOnReady=!0))},pause:function(){this.ytPlayer&&this.ytPlayer.pauseVideo()},paused:function(){return!this.ytPlayer||this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING},currentTime:function(){return this.ytPlayer?this.ytPlayer.getCurrentTime():0},setCurrentTime:function(a){this.lastState===YT.PlayerState.PAUSED&&(this.timeBeforeSeek=this.currentTime()),this.isSeeking||(this.wasPausedBeforeSeek=this.paused()),this.ytPlayer.seekTo(a,!0),this.trigger("timeupdate"),this.trigger("seeking"),this.isSeeking=!0,this.lastState===YT.PlayerState.PAUSED&&this.timeBeforeSeek!==a&&(clearInterval(this.checkSeekedInPauseInterval),this.checkSeekedInPauseInterval=setInterval(function(){this.lastState===YT.PlayerState.PAUSED&&this.isSeeking?this.currentTime()!==this.timeBeforeSeek&&(this.trigger("timeupdate"),this.onSeeked()):clearInterval(this.checkSeekedInPauseInterval)}.bind(this),250))},seeking:function(){return this.isSeeking},seekable:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return{length:0,start:function(){throw new Error("This TimeRanges object is empty")},end:function(){throw new Error("This TimeRanges object is empty")}};var a=this.ytPlayer.getDuration();return{length:this.ytPlayer.getDuration(),start:function(){return 0},end:function(){return a}}},onSeeked:function(){clearInterval(this.checkSeekedInPauseInterval),this.isSeeking=!1,this.wasPausedBeforeSeek&&this.pause(),this.trigger("seeked")},playbackRate:function(){return this.ytPlayer?this.ytPlayer.getPlaybackRate():1},setPlaybackRate:function(a){this.ytPlayer&&(this.ytPlayer.setPlaybackRate(a),this.trigger("ratechange"))},duration:function(){return this.ytPlayer?this.ytPlayer.getDuration():0},currentSrc:function(){return this.source&&this.source.src},ended:function(){return!!this.ytPlayer&&this.lastState===YT.PlayerState.ENDED},volume:function(){return this.ytPlayer?this.ytPlayer.getVolume()/100:1},setVolume:function(a){this.ytPlayer&&(this.ytPlayer.setVolume(100*a),this.setTimeout(function(){this.trigger("volumechange")},50))},muted:function(){return!!this.ytPlayer&&this.ytPlayer.isMuted()},setMuted:function(a){this.ytPlayer&&(this.muted(!0),a?this.ytPlayer.mute():this.ytPlayer.unMute(),this.setTimeout(function(){this.trigger("volumechange")},50))},buffered:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return{length:0,start:function(){throw new Error("This TimeRanges object is empty")},end:function(){throw new Error("This TimeRanges object is empty")}};var a=this.ytPlayer.getVideoLoadedFraction()*this.ytPlayer.getDuration();return{length:this.ytPlayer.getDuration(),start:function(){return 0},end:function(){return a}}},preload:function(){},load:function(){},reset:function(){},supportsFullScreen:function(){return!0},checkHighResPoster:function(){var a="https://img.youtube.com/vi/"+this.url.videoId+"/maxresdefault.jpg";try{var b=new Image;b.onload=function(){if("naturalHeight"in b){if(b.naturalHeight<=90||b.naturalWidth<=120)return}else if(b.height<=90||b.width<=120)return;this.poster_=a,this.trigger("posterchange")}.bind(this),b.onerror=function(){},b.src=a}catch(c){}}});g.isSupported=function(){return!0},g.canPlaySource=function(a){return g.canPlayType(a.type)},g.canPlayType=function(a){return"video/youtube"===a};var h=a.browser.IS_IOS||e();g.parseUrl=function(a){var b={videoId:null},c=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,d=a.match(c);d&&11===d[2].length&&(b.videoId=d[2]);var e=/[?&]list=([^#\&\?]+)/;return d=a.match(e),d&&d[1]&&(b.listId=d[1]),b},g.apiReadyQueue=[],c("https://www.youtube.com/iframe_api",b),d(),"undefined"!=typeof a.registerTech?a.registerTech("Youtube",g):a.registerComponent("Youtube",g)}); \ No newline at end of file diff --git a/media/player/videojs/amd/build/Youtube.min.js b/media/player/videojs/amd/build/Youtube.min.js deleted file mode 100644 index 785b901c0c5..00000000000 --- a/media/player/videojs/amd/build/Youtube.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("video.js")):"function"==typeof define&&define.amd?define(["media_videojs/video"],function(c){return a.Youtube=b(c)}):a.Youtube=b(a.videojs)}(this,function(a){"use strict";function b(){YT.ready(function(){g.isApiReady=!0;for(var a=0;a0}var f=a.getComponent("Tech"),g=a.extend(f,{constructor:function(a,b){f.call(this,a,b),this.setPoster(a.poster),this.setSrc(this.options_.source,!0),setTimeout(function(){this.el_.parentNode.className+=" vjs-youtube",h&&(this.el_.parentNode.className+=" vjs-youtube-mobile"),g.isApiReady?this.initYTPlayer():g.apiReadyQueue.push(this)}.bind(this))},dispose:function(){if(this.ytPlayer)this.ytPlayer.stopVideo(),this.ytPlayer.destroy();else{var a=g.apiReadyQueue.indexOf(this);a!==-1&&g.apiReadyQueue.splice(a,1)}this.ytPlayer=null,this.el_.parentNode.className=this.el_.parentNode.className.replace(" vjs-youtube","").replace(" vjs-youtube-mobile",""),this.el_.remove(),f.prototype.dispose.call(this)},createEl:function(){var a=document.createElement("div");a.setAttribute("id",this.options_.techId),a.setAttribute("style","width:100%;height:100%;top:0;left:0;position:absolute"),a.setAttribute("class","vjs-tech");var b=document.createElement("div");if(b.appendChild(a),!h&&!this.options_.ytControls){var c=document.createElement("div");c.setAttribute("class","vjs-iframe-blocker"),c.setAttribute("style","position:absolute;top:0;left:0;width:100%;height:100%"),c.onclick=function(){this.pause()}.bind(this),b.appendChild(c)}return b},initYTPlayer:function(){var a={controls:0,modestbranding:1,rel:0,showinfo:0,loop:this.options_.loop?1:0};"undefined"!=typeof this.options_.autohide&&(a.autohide=this.options_.autohide),"undefined"!=typeof this.options_.cc_load_policy&&(a.cc_load_policy=this.options_.cc_load_policy),"undefined"!=typeof this.options_.ytControls&&(a.controls=this.options_.ytControls),"undefined"!=typeof this.options_.disablekb&&(a.disablekb=this.options_.disablekb),"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.color&&(a.color=this.options_.color),a.controls?"undefined"!=typeof this.options_.fs&&(a.fs=this.options_.fs):a.fs=0,"undefined"!=typeof this.options_.end&&(a.end=this.options_.end),"undefined"!=typeof this.options_.hl?a.hl=this.options_.hl:"undefined"!=typeof this.options_.language&&(a.hl=this.options_.language.substr(0,2)),"undefined"!=typeof this.options_.iv_load_policy&&(a.iv_load_policy=this.options_.iv_load_policy),"undefined"!=typeof this.options_.list?a.list=this.options_.list:this.url&&"undefined"!=typeof this.url.listId&&(a.list=this.url.listId),"undefined"!=typeof this.options_.listType&&(a.listType=this.options_.listType),"undefined"!=typeof this.options_.modestbranding&&(a.modestbranding=this.options_.modestbranding),"undefined"!=typeof this.options_.playlist&&(a.playlist=this.options_.playlist),"undefined"!=typeof this.options_.playsinline&&(a.playsinline=this.options_.playsinline),"undefined"!=typeof this.options_.rel&&(a.rel=this.options_.rel),"undefined"!=typeof this.options_.showinfo&&(a.showinfo=this.options_.showinfo),"undefined"!=typeof this.options_.start&&(a.start=this.options_.start),"undefined"!=typeof this.options_.theme&&(a.theme=this.options_.theme),this.activeVideoId=this.url?this.url.videoId:null,this.activeList=a.list,this.ytPlayer=new YT.Player(this.options_.techId,{videoId:this.activeVideoId,playerVars:a,events:{onReady:this.onPlayerReady.bind(this),onPlaybackQualityChange:this.onPlayerPlaybackQualityChange.bind(this),onStateChange:this.onPlayerStateChange.bind(this),onError:this.onPlayerError.bind(this)}})},onPlayerReady:function(){this.playerReady_=!0,this.triggerReady(),this.playOnReady?this.play():this.cueOnReady&&(this.ytPlayer.cueVideoById(this.url.videoId),this.activeVideoId=this.url.videoId)},onPlayerPlaybackQualityChange:function(){},onPlayerStateChange:function(a){var b=a.data;if(b!==this.lastState&&!this.errorNumber)switch(this.lastState=b,b){case-1:this.trigger("loadstart"),this.trigger("loadedmetadata"),this.trigger("durationchange");break;case YT.PlayerState.ENDED:this.trigger("ended");break;case YT.PlayerState.PLAYING:this.trigger("timeupdate"),this.trigger("durationchange"),this.trigger("playing"),this.trigger("play"),this.isSeeking&&this.onSeeked();break;case YT.PlayerState.PAUSED:this.trigger("canplay"),this.isSeeking?this.onSeeked():this.trigger("pause");break;case YT.PlayerState.BUFFERING:this.player_.trigger("timeupdate"),this.player_.trigger("waiting")}},onPlayerError:function(a){this.errorNumber=a.data,this.trigger("error"),this.ytPlayer.stopVideo()},error:function(){switch(this.errorNumber){case 5:return{code:"Error while trying to play the video"};case 2:case 100:return{code:"Unable to find the video"};case 101:case 150:return{code:"Playback on other Websites has been disabled by the video owner."}}return{code:"YouTube unknown error ("+this.errorNumber+")"}},src:function(a){return a&&this.setSrc({src:a}),this.source},poster:function(){return h?null:this.poster_},setPoster:function(a){this.poster_=a},setSrc:function(a){a&&a.src&&(delete this.errorNumber,this.source=a,this.url=g.parseUrl(a.src),this.options_.poster||this.url.videoId&&(this.poster_="https://img.youtube.com/vi/"+this.url.videoId+"/0.jpg",this.trigger("posterchange"),this.checkHighResPoster()),this.options_.autoplay&&!h?this.isReady_?this.play():this.playOnReady=!0:this.activeVideoId!==this.url.videoId&&(this.isReady_?(this.ytPlayer.cueVideoById(this.url.videoId),this.activeVideoId=this.url.videoId):this.cueOnReady=!0))},autoplay:function(){return this.options_.autoplay},setAutoplay:function(a){this.options_.autoplay=a},loop:function(){return this.options_.loop},setLoop:function(a){this.options_.loop=a},play:function(){this.url&&this.url.videoId&&(this.wasPausedBeforeSeek=!1,this.isReady_?(this.url.listId&&(this.activeList===this.url.listId?this.ytPlayer.playVideo():(this.ytPlayer.loadPlaylist(this.url.listId),this.activeList=this.url.listId)),this.activeVideoId===this.url.videoId?this.ytPlayer.playVideo():(this.ytPlayer.loadVideoById(this.url.videoId),this.activeVideoId=this.url.videoId)):(this.trigger("waiting"),this.playOnReady=!0))},pause:function(){this.ytPlayer&&this.ytPlayer.pauseVideo()},paused:function(){return!this.ytPlayer||this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING},currentTime:function(){return this.ytPlayer?this.ytPlayer.getCurrentTime():0},setCurrentTime:function(a){this.lastState===YT.PlayerState.PAUSED&&(this.timeBeforeSeek=this.currentTime()),this.isSeeking||(this.wasPausedBeforeSeek=this.paused()),this.ytPlayer.seekTo(a,!0),this.trigger("timeupdate"),this.trigger("seeking"),this.isSeeking=!0,this.lastState===YT.PlayerState.PAUSED&&this.timeBeforeSeek!==a&&(clearInterval(this.checkSeekedInPauseInterval),this.checkSeekedInPauseInterval=setInterval(function(){this.lastState===YT.PlayerState.PAUSED&&this.isSeeking?this.currentTime()!==this.timeBeforeSeek&&(this.trigger("timeupdate"),this.onSeeked()):clearInterval(this.checkSeekedInPauseInterval)}.bind(this),250))},seeking:function(){return this.isSeeking},seekable:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return{length:0,start:function(){throw new Error("This TimeRanges object is empty")},end:function(){throw new Error("This TimeRanges object is empty")}};var a=this.ytPlayer.getDuration();return{length:this.ytPlayer.getDuration(),start:function(){return 0},end:function(){return a}}},onSeeked:function(){clearInterval(this.checkSeekedInPauseInterval),this.isSeeking=!1,this.wasPausedBeforeSeek&&this.pause(),this.trigger("seeked")},playbackRate:function(){return this.ytPlayer?this.ytPlayer.getPlaybackRate():1},setPlaybackRate:function(a){this.ytPlayer&&(this.ytPlayer.setPlaybackRate(a),this.trigger("ratechange"))},duration:function(){return this.ytPlayer?this.ytPlayer.getDuration():0},currentSrc:function(){return this.source&&this.source.src},ended:function(){return!!this.ytPlayer&&this.lastState===YT.PlayerState.ENDED},volume:function(){return this.ytPlayer?this.ytPlayer.getVolume()/100:1},setVolume:function(a){this.ytPlayer&&(this.ytPlayer.setVolume(100*a),this.setTimeout(function(){this.trigger("volumechange")},50))},muted:function(){return!!this.ytPlayer&&this.ytPlayer.isMuted()},setMuted:function(a){this.ytPlayer&&(this.muted(!0),a?this.ytPlayer.mute():this.ytPlayer.unMute(),this.setTimeout(function(){this.trigger("volumechange")},50))},buffered:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction)return{length:0,start:function(){throw new Error("This TimeRanges object is empty")},end:function(){throw new Error("This TimeRanges object is empty")}};var a=this.ytPlayer.getVideoLoadedFraction()*this.ytPlayer.getDuration();return{length:this.ytPlayer.getDuration(),start:function(){return 0},end:function(){return a}}},preload:function(){},load:function(){},reset:function(){},supportsFullScreen:function(){return!0},checkHighResPoster:function(){var a="https://img.youtube.com/vi/"+this.url.videoId+"/maxresdefault.jpg";try{var b=new Image;b.onload=function(){if("naturalHeight"in b){if(b.naturalHeight<=90||b.naturalWidth<=120)return}else if(b.height<=90||b.width<=120)return;this.poster_=a,this.trigger("posterchange")}.bind(this),b.onerror=function(){},b.src=a}catch(c){}}});g.isSupported=function(){return!0},g.canPlaySource=function(a){return g.canPlayType(a.type)},g.canPlayType=function(a){return"video/youtube"===a};var h=a.browser.IS_IOS||e();g.parseUrl=function(a){var b={videoId:null},c=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,d=a.match(c);d&&11===d[2].length&&(b.videoId=d[2]);var e=/[?&]list=([^#\&\?]+)/;return d=a.match(e),d&&d[1]&&(b.listId=d[1]),b},g.apiReadyQueue=[],c("https://www.youtube.com/iframe_api",b),d(),"undefined"!=typeof a.registerTech?a.registerTech("Youtube",g):a.registerComponent("Youtube",g)}); \ No newline at end of file diff --git a/media/player/videojs/amd/build/loader.min.js b/media/player/videojs/amd/build/loader.min.js index 436b2da19cd..6c77c7f187d 100644 --- a/media/player/videojs/amd/build/loader.min.js +++ b/media/player/videojs/amd/build/loader.min.js @@ -1 +1 @@ -define(["jquery","media_videojs/video","core/event"],function(a,b,c){var d=function(){c.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,e)})},e=function(c,d){var e=".mediaplugin_videojs";d.find(e).addBack(e).find("audio, video").each(function(){var c=a(this).attr("id"),d=a(this).data("setup");b(c,d)})};return{setUp:d}}); \ No newline at end of file +define(["jquery","core/event"],function(a,b){var c,d=function(d){c=d,e(null,a("body")),b.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,e)})},e=function(b,d){var e=".mediaplugin_videojs";d.find(e).addBack(e).find("audio, video").each(function(){var b=a(this).attr("id"),d=a(this).data("setup"),e=["media_videojs/video-lazy"];d.techOrder&&d.techOrder.indexOf("youtube")!==-1&&e.push("media_videojs/Youtube-lazy"),require(e,function(a){c&&(c(a),c=null),a(b,d)})})};return{setUp:d}}); \ No newline at end of file diff --git a/media/player/videojs/amd/build/video.min.js b/media/player/videojs/amd/build/video-lazy.min.js similarity index 100% rename from media/player/videojs/amd/build/video.min.js rename to media/player/videojs/amd/build/video-lazy.min.js diff --git a/media/player/videojs/amd/src/Youtube.js b/media/player/videojs/amd/src/Youtube-lazy.js similarity index 99% rename from media/player/videojs/amd/src/Youtube.js rename to media/player/videojs/amd/src/Youtube-lazy.js index c2391da5637..571c6021bb5 100644 --- a/media/player/videojs/amd/src/Youtube.js +++ b/media/player/videojs/amd/src/Youtube-lazy.js @@ -24,7 +24,7 @@ THE SOFTWARE. */ if(typeof exports==='object' && typeof module!=='undefined') { module.exports = factory(require('video.js')); } else if(typeof define === 'function' && define.amd) { - define(['media_videojs/video'], function(videojs){ + define(['media_videojs/video-lazy'], function(videojs){ return (root.Youtube = factory(videojs)); }); } else { diff --git a/media/player/videojs/amd/src/loader.js b/media/player/videojs/amd/src/loader.js index be7a1f0e755..2601cf888fa 100644 --- a/media/player/videojs/amd/src/loader.js +++ b/media/player/videojs/amd/src/loader.js @@ -22,14 +22,23 @@ * @copyright 2016 Frédéric Massart - FMCorz.net * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'media_videojs/video', 'core/event'], function($, videojs, Event) { +define(['jquery', 'core/event'], function($, Event) { + + /** + * Stores the method we need to execute on the first load of videojs module. + */ + var onload; /** * Set-up. * * Adds the listener for the event to then notify video.js. + * @param {Function} executeonload function to execute when media_videojs/video is loaded */ - var setUp = function() { + var setUp = function(executeonload) { + onload = executeonload; + // Notify Video.js about the nodes already present on the page. + notifyVideoJS(null, $('body')); // We need to call popover automatically if nodes are added to the page later. Event.getLegacyEvents().done(function(events) { $(document).on(events.FILTER_CONTENT_UPDATED, notifyVideoJS); @@ -53,9 +62,20 @@ define(['jquery', 'media_videojs/video', 'core/event'], function($, videojs, Eve .addBack(selector) .find('audio, video').each(function() { var id = $(this).attr('id'), - config = $(this).data('setup'); + config = $(this).data('setup'), + modules = ['media_videojs/video-lazy']; - videojs(id, config); + if (config.techOrder && config.techOrder.indexOf('youtube') !== -1) { + // Add YouTube to the list of modules we require. + modules.push('media_videojs/Youtube-lazy'); + } + require(modules, function(videojs) { + if (onload) { + onload(videojs); + onload = null; + } + videojs(id, config); + }); }); }; diff --git a/media/player/videojs/amd/src/video.js b/media/player/videojs/amd/src/video-lazy.js similarity index 100% rename from media/player/videojs/amd/src/video.js rename to media/player/videojs/amd/src/video-lazy.js diff --git a/media/player/videojs/classes/plugin.php b/media/player/videojs/classes/plugin.php index ff82f98c6bb..f13352fe577 100644 --- a/media/player/videojs/classes/plugin.php +++ b/media/player/videojs/classes/plugin.php @@ -334,21 +334,19 @@ class media_videojs_plugin extends core_media_player_native { */ public function setup($page) { - // Load core video JS. + // Load dynamic loader. It will scan page for videojs media and load necessary modules. + // Loader will be loaded on absolutely every page, however the videojs will only be loaded + // when video is present on the page or added later to it in AJAX. $path = new moodle_url('/media/player/videojs/videojs/video-js.swf'); $contents = 'videojs.options.flash.swf = "' . $path . '";' . "\n"; $contents .= $this->find_language(current_language()); $page->requires->js_amd_inline(<<requires->js_amd_inline('require(["media_videojs/Youtube"])'); - - // Load dynamic loader. - $page->requires->js_call_amd('media_videojs/loader', 'setUp'); } } diff --git a/media/player/videojs/readme_moodle.txt b/media/player/videojs/readme_moodle.txt index ce8410933f0..4799afde0f3 100644 --- a/media/player/videojs/readme_moodle.txt +++ b/media/player/videojs/readme_moodle.txt @@ -5,7 +5,7 @@ https://github.com/videojs/video.js Instructions to import VideoJS player into Moodle: 1. Download the latest release from https://github.com/videojs/video.js/releases in a separate directory -2. copy 'dist/video.js' into 'amd/src/video.js' +2. copy 'dist/video.js' into 'amd/src/video-lazy.js' 3. copy 'dist/font/' into 'fonts/' folder 4. copy 'dist/video-js.css' into 'styles.css' Replace @@ -21,8 +21,8 @@ Instructions to import VideoJS player into Moodle: Import plugins: -1. Copy https://github.com/videojs/videojs-youtube/blob/master/dist/Youtube.js into 'amd/src/Youtube.js' +1. Copy https://github.com/videojs/videojs-youtube/blob/master/dist/Youtube.js into 'amd/src/Youtube-lazy.js' In the beginning of the js file replace define(['videojs'] with - define(['media_videojs/video'] + define(['media_videojs/video-lazy'] diff --git a/media/player/videojs/thirdpartylibs.xml b/media/player/videojs/thirdpartylibs.xml index de0b9bc1c3a..ff41fe9862f 100644 --- a/media/player/videojs/thirdpartylibs.xml +++ b/media/player/videojs/thirdpartylibs.xml @@ -1,12 +1,19 @@ - amd/src + amd/src/video-lazy.js VideoJS Apache 5.12.6 + + amd/src/Youtube-lazy.js + YouTube Playback Technology for Video.js + MIT + 2.1.1 + + videojs VideoJS support files