From 9424bef30f5e2012f31b5ce5ecbbb9c395b293cb Mon Sep 17 00:00:00 2001 From: Pong Date: Tue, 27 Nov 2018 11:00:47 +0800 Subject: [PATCH 1/8] sync naming of setting menu items --- .../videojs-plus.audio-track.min.js | 2 +- .../videojs-plus.picture-in-picture.min.js | 2 +- dist/playlist/videojs-plus.playlist.min.js | 2 +- .../videojs-plus.quality-hls.min.js | 2 +- dist/quality/videojs-plus.quality.min.js | 2 +- dist/subtitles/videojs-plus.subtitles.min.js | 2 +- dist/videojs-plus.cjs.min.js | 2 +- dist/videojs-plus.min.js | 2 +- examples/setting-menu.html | 4 +- guide/SettingMenu.md | 4 +- .../SettingMenu/Item/SettingItem.js | 23 --- .../SettingMenu/Item/SettingMenuItem.js | 137 ++---------------- .../SettingMenu/Item/SettingOnOffItem.js | 4 +- .../SettingMenu/Item/SettingOptionalItem.js | 130 +++++++++++++++++ .../SettingMenu/Item/SettingSubMenuItem.js | 4 +- .../SettingMenu/Item/SettingSubMenuTitle.js | 4 +- .../SettingMenu/SettingMenuButton.js | 4 +- source/Plugin/AudioTrack/AudioSettingItem.js | 12 +- .../PictureInPicture/PictureInPicture.js | 6 +- source/Plugin/Quality/Quality.js | 2 +- .../{QualityItem.js => QualitySettingItem.js} | 12 +- source/Plugin/QualityHls/QualityHls.js | 2 +- ...ityHlsItem.js => QualityHlsSettingItem.js} | 12 +- ...tlesItem.js => SubtitleSettingMenuItem.js} | 12 +- source/Plugin/Subtitles/Subtitles.js | 6 +- 25 files changed, 195 insertions(+), 199 deletions(-) delete mode 100644 source/Components/SettingMenu/Item/SettingItem.js create mode 100644 source/Components/SettingMenu/Item/SettingOptionalItem.js rename source/Plugin/Quality/{QualityItem.js => QualitySettingItem.js} (64%) rename source/Plugin/QualityHls/{QualityHlsItem.js => QualityHlsSettingItem.js} (87%) rename source/Plugin/Subtitles/{SubtitlesItem.js => SubtitleSettingMenuItem.js} (62%) diff --git a/dist/audio-track/videojs-plus.audio-track.min.js b/dist/audio-track/videojs-plus.audio-track.min.js index ddaf3b3..d637001 100644 --- a/dist/audio-track/videojs-plus.audio-track.min.js +++ b/dist/audio-track/videojs-plus.audio-track.min.js @@ -1 +1 @@ -!function(e){"use strict";function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var i=e.getComponent("SettingMenuItem"),o=function(e){function i(t,i){var o;o=e.call(this,t,Object.assign(i,{name:"AudioSettingItem",label:"Audio",icon:"vjs-icon-audiotrack",entries:i.quality||[]}))||this,o.addClass("vjs-setting-audio");var r,a=function(e){"hls-audio-change"===e.name?(clearTimeout(r),r=setTimeout(o.handleAudioChangeEvent.bind(n(n(o))),10)):"hls-alternate-audio"===e.name&&o.onAlternateAudio()};return t.tech().on("usage",a),t.on("dispose",function(){t.tech().off("usage",a)}),t.on("loadstart",function(){o.hide()}),o}t(i,e);var o=i.prototype;return o.update=function(t){e.prototype.update.call(this,t),this.player_.audio().pick(t.value.index)},o.onAlternateAudio=function(){var e=this.player_.audio().values(),t=e.map(function(e,t){return{id:e.id,kind:e.kind,label:e.label,language:e.language,index:t}});this.player_.trigger("before-audio-setup",t),this.setEntries(t),this.show(),this.player_.trigger("audio",t)},o.handleAudioChangeEvent=function(){var e=this,t=this.player_.audio().values(),n=t.reduce(function(t,n,i){return n.enabled&&(t=e.entries[i]),t},{});this.player_.trigger("audiochange",n)},i}(i);e.getComponent("SettingMenuButton").prototype.options_.entries.push("AudioSettingItem"),e.registerComponent("AudioSettingItem",o);var r=function(e){function n(t,n){var i;return void 0===n&&(n={}),i=e.call(this,t,n)||this,i.current=i.values().find(function(e){return e.enabled}),t.on("audiochange",function(e,t){var n=t.index;i.current=i.values()[n]}),i}t(n,e);var i=n.prototype;return i.values=function(){for(var e=this.player.audioTracks(),t=[],n=0;n\n \n \n \n \n \n '});return this.path=e.querySelector("path"),e},i.handleClick=function(){this.player_.getChild("BeforePlayNextLayer").timeup()},n}(o);a.prototype.controlText_="PlayNext",t.registerComponent("PlayNextSpinner",a);var l=t.getComponent("Component"),s=function(i){function o(t,e){var o;o=i.call(this,t,e)||this,o.addChild("PlayNextSpinner",{},2),o.addChild("CancelPlayNextEl",{text:"✕",className:"vjs-cancel-playnext-cross"},{},2),o.addChild("CancelPlayNextEl",{text:"Cancel",className:"vjs-cancel-playnext-button"},{},2),o.originPoster=t.poster()||t.playlist.current().poster,t.poster(o.getNext().poster);var a=o.dispose.bind(n(n(o))),l=["timeupdate","loadstart"];return t.one(l,a),o.on("dispose",function(){t.off(l,a),t.removeClass("vjs-play-next-ready")}),o.countdown(t.options_.playNextCountDown),t.addClass("vjs-play-next-ready"),o}e(o,i);var a=o.prototype;return a.getNext=function(){var t=this.player_.playlist;return this.next=t.values[t.calc(1)],this.next},a.createEl=function(){var e=this.getNext().title,n=t.dom.createEl("div",{className:"vjs-before-playnext"});return this.contentEl_=t.dom.createEl("div",{className:"vjs-before-playnext-content",innerHTML:'\n
'+this.localize("Up Next")+'
\n
\n
'+e+"
\n
\n "}),n.appendChild(this.contentEl_),n},a.countdown=function(t){if(void 0===t&&(t=10),0==t)return this.timeup(),!1;var e=this,n=0,i=Math.PI,o=t;o=o/360*1e3,function t(){n++,n%=360;var a=n*i/180,l=125*Math.sin(a),s=-125*Math.cos(a),r=n>180?1:0,p="M 0 0 v -125 A 125 125 1 "+r+" 1 "+l+" "+s+" z";e.getChild("PlayNextSpinner").path.setAttribute("d",p),0===n?e.timeup():e.timer=setTimeout(t,o)}()},a.timeup=function(){this.player_.playlist.next(),this.player_.playlist.play(),this.dispose()},a.cancel=function(){return this.player_.poster(this.originPoster),this},a.dispose=function(){clearTimeout(this.timer),this.player_.removeChild(this),i.prototype.dispose.call(this)},o}(l),r=function(){var t=this.player_,e=t.playlist,n=e.loop()||!e.ended();if(e.autoPlayNext()&&n){var i=t.getChild("ControlBar"),o=t.children().indexOf(i)-1;t.addChild("BeforePlayNextLayer",{},o)}else t.poster(e.current().poster||"")};t.registerPlugin("playNext",r),t.registerComponent("BeforePlayNextLayer",s);var p=t.getComponent("SettingMenuButton"),c=t.getComponent("SettingOnOffItem"),u=function(t){function n(e,n){var i;return i=t.call(this,e,{name:"ToggleAutoPlayNext",label:"Autoplay",icon:"vjs-icon-next-item"})||this,i.menu=n.menu,i.updateVisibility(),i.addClass("vjs-setting-autoplay"),e.on("playlist",function(){i.updateVisibility(),i.update(e.playlist.autoPlayNext_)}),i}e(n,t);var i=n.prototype;return i.updateVisibility=function(){var t=this.player_.playlist;t&&t.values.length>1?this.show():this.hide()},i.update=function(e){t.prototype.update.call(this,e),this.player_.playlist.autoPlayNext(this.active)},n}(c);t.registerComponent("ToggleAutoPlayNext",u),p.prototype.options_.entries.splice(0,0,"ToggleAutoPlayNext");var h=t.getComponent("Button"),d=function(t){function i(e,i){var o;return o=t.call(this,e,i)||this,o.updateVisibility(),o.controlText(i.controlText),e.on("playlist",o.updateVisibility.bind(n(n(o)))),o}e(i,t);var o=i.prototype;return o.buildCSSClass=function(){return this.options_.className+" "+t.prototype.buildCSSClass.call(this)},o.updateVisibility=function(){var t=this.player_.playlist;t&&t.values.length>1?this.show():this.hide()},o.createEl=function(e,n,i){return t.prototype.createEl.call(this,e,{innerHTML:''},i)},o.handleClick=function(){var t=this.options_.controlText.toLowerCase();this.player_.playlist[t](),this.player_.playlist.play()},i}(h),y=t.getComponent("ControlBar"),v=y.prototype.options_.children,x=v.indexOf("PlayToggle");-1!==x&&(v.splice(0,0,{name:"PrevNextButton",className:"vjs-prev-control",icon:"vjs-icon-previous-item",controlText:"Prev"}),v.splice(x+2,0,{name:"PrevNextButton",className:"vjs-next-control",icon:"vjs-icon-next-item",controlText:"Next"})),t.registerComponent("PrevNextButton",d);var f=t.getComponent("ClickableComponent"),g=function(t){function n(e,n){var i;return i=t.call(this,e,n)||this,i.el_.querySelector(".vjs-icon-placeholder").innerHTML=i.localize(n.text),i}e(n,t);var i=n.prototype;return i.buildCSSClass=function(){return"vjs-cancel-playnext "+this.options_.className},i.handleClick=function(){this.player_.getChild("BeforePlayNextLayer").cancel().dispose()},n}(f);g.prototype.controlText_="Cancel PlayNext",t.registerComponent("CancelPlayNextEl",g);var m=function(t){function n(e,n,i){var o;return void 0===i&&(i=0),o=t.call(this,n,i)||this,o.player=e,o.loadPoster_=!0,o.autoPlayNext_=!0,o.play(i),e.off("ended",e.playNext),e.on("ended",e.playNext),o}e(n,t);var i=n.prototype;return i.autoPlayNext=function(t){if(void 0===t)return this.autoPlayNext_;this.autoPlayNext_=!!t},i.play=function(t){void 0!==t&&this.index(t);var e=this.current(),n=e.poster,i=e.sources,o=e.title,a=this.player,l=function(){a.poster(n||"")};a.title(""),a.poster(""),this.loadPoster_?(this.loadPoster_=!1,a.autoplay()?a.one("autoplay-failure",l):l()):a.one("loadedmetadata",function(){a.play()}),"none"!==a.preload()&&(a.addClass("vjs-waiting"),a.one("loadedmetadata",function(){a.removeClass("vjs-waiting")})),a.src(i),a.title(o||""),a.trigger("playlistchange",Object.assign(this.current(),{index:this.index()}))},n}(i);t.registerPlugin("setPlayList",function(t){var e=this.player_;e.playlist=new m(e,t),e.trigger("playlist")}),t.hook("setup",function(t){var e=t.options_.playlist||[];e.length&&t.setPlayList(e)})}(videojs); +!function(t){"use strict";function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function n(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var i=function(){function t(t,e){this.values=t.slice(0),this.index_=e||0,this.loop_=!0}var e=t.prototype;return e.index=function(t){if(void 0===t)return this.index_;this.index_=Math.max(0,Math.min(t,this.values.length-1))},e.loop=function(t){if(void 0===t)return this.loop_;this.loop_=!!t},e.calc=function(t){var e=this.index_+t,n=this.values.length;return this.loop_?(n+e)%n:Math.max(0,Math.min(e,n-1))},e.step=function(t){return this.index_=this.calc(t),this.values[this.index_]},e.current=function(){return this.values[this.index_]},e.next=function(){return this.step(1)},e.prev=function(){return this.step(-1)},e.ended=function(){return this.index_===this.values.length-1},t}(),o=t.getComponent("ClickableComponent"),a=function(t){function n(){return t.apply(this,arguments)||this}e(n,t);var i=n.prototype;return i.buildCSSClass=function(){return"vjs-playnext-spinner"},i.createEl=function(){var e=t.prototype.createEl.call(this,"div",{innerHTML:'\n
\n \n \n \n \n \n '});return this.path=e.querySelector("path"),e},i.handleClick=function(){this.player_.getChild("BeforePlayNextLayer").timeup()},n}(o);a.prototype.controlText_="PlayNext",t.registerComponent("PlayNextSpinner",a);var l=t.getComponent("Component"),s=function(i){function o(t,e){var o;o=i.call(this,t,e)||this,o.addChild("PlayNextSpinner",{},2),o.addChild("CancelPlayNextEl",{text:"✕",className:"vjs-cancel-playnext-cross"},{},2),o.addChild("CancelPlayNextEl",{text:"Cancel",className:"vjs-cancel-playnext-button"},{},2),o.originPoster=t.poster()||t.playlist.current().poster,t.poster(o.getNext().poster);var a=o.dispose.bind(n(n(o))),l=["timeupdate","loadstart"];return t.one(l,a),o.on("dispose",function(){t.off(l,a),t.removeClass("vjs-play-next-ready")}),o.countdown(t.options_.playNextCountDown),t.addClass("vjs-play-next-ready"),o}e(o,i);var a=o.prototype;return a.getNext=function(){var t=this.player_.playlist;return this.next=t.values[t.calc(1)],this.next},a.createEl=function(){var e=this.getNext().title,n=t.dom.createEl("div",{className:"vjs-before-playnext"});return this.contentEl_=t.dom.createEl("div",{className:"vjs-before-playnext-content",innerHTML:'\n
'+this.localize("Up Next")+'
\n
\n
'+e+"
\n
\n "}),n.appendChild(this.contentEl_),n},a.countdown=function(t){if(void 0===t&&(t=10),0==t)return this.timeup(),!1;var e=this,n=0,i=Math.PI,o=t;o=o/360*1e3,function t(){n++,n%=360;var a=n*i/180,l=125*Math.sin(a),s=-125*Math.cos(a),r=n>180?1:0,p="M 0 0 v -125 A 125 125 1 "+r+" 1 "+l+" "+s+" z";e.getChild("PlayNextSpinner").path.setAttribute("d",p),0===n?e.timeup():e.timer=setTimeout(t,o)}()},a.timeup=function(){this.player_.playlist.next(),this.player_.playlist.play(),this.dispose()},a.cancel=function(){return this.player_.poster(this.originPoster),this},a.dispose=function(){clearTimeout(this.timer),this.player_.removeChild(this),i.prototype.dispose.call(this)},o}(l),r=function(){var t=this.player_,e=t.playlist,n=e.loop()||!e.ended();if(e.autoPlayNext()&&n){var i=t.getChild("ControlBar"),o=t.children().indexOf(i)-1;t.addChild("BeforePlayNextLayer",{},o)}else t.poster(e.current().poster||"")};t.registerPlugin("playNext",r),t.registerComponent("BeforePlayNextLayer",s);var p=t.getComponent("SettingMenuButton"),c=t.getComponent("SettingOnOffItem"),u=function(t){function n(e,n){var i;return i=t.call(this,e,{name:"ToggleAutoPlayNext",label:"Autoplay",icon:"vjs-icon-next-item"})||this,i.updateVisibility(),i.addClass("vjs-setting-autoplay"),e.on("playlist",function(){i.updateVisibility(),i.update(e.playlist.autoPlayNext_)}),e.on("autoplaynext",function(t,e){i.update(e)}),i}e(n,t);var i=n.prototype;return i.updateVisibility=function(){var t=this.player_.playlist;t&&t.values.length>1?this.show():this.hide()},i.update=function(e){t.prototype.update.call(this,e),this.player_.playlist.autoPlayNext_!==this.active&&this.player_.playlist.autoPlayNext(this.active)},n}(c);t.registerComponent("ToggleAutoPlayNext",u),p.prototype.options_.entries.splice(0,0,"ToggleAutoPlayNext");var h=t.getComponent("Button"),d=function(t){function i(e,i){var o;return o=t.call(this,e,i)||this,o.updateVisibility(),o.controlText(i.controlText),e.on("playlist",o.updateVisibility.bind(n(n(o)))),o}e(i,t);var o=i.prototype;return o.buildCSSClass=function(){return this.options_.className+" "+t.prototype.buildCSSClass.call(this)},o.updateVisibility=function(){var t=this.player_.playlist;t&&t.values.length>1?this.show():this.hide()},o.createEl=function(e,n,i){return t.prototype.createEl.call(this,e,{innerHTML:''},i)},o.handleClick=function(){var t=this.options_.controlText.toLowerCase();this.player_.playlist[t](),this.player_.playlist.play()},i}(h),y=t.getComponent("ControlBar"),v=y.prototype.options_.children,x=v.indexOf("PlayToggle");-1!==x&&(v.splice(0,0,{name:"PrevNextButton",className:"vjs-prev-control",icon:"vjs-icon-previous-item",controlText:"Prev"}),v.splice(x+2,0,{name:"PrevNextButton",className:"vjs-next-control",icon:"vjs-icon-next-item",controlText:"Next"})),t.registerComponent("PrevNextButton",d);var f=t.getComponent("ClickableComponent"),_=function(t){function n(e,n){var i;return i=t.call(this,e,n)||this,i.el_.querySelector(".vjs-icon-placeholder").innerHTML=i.localize(n.text),i}e(n,t);var i=n.prototype;return i.buildCSSClass=function(){return"vjs-cancel-playnext "+this.options_.className},i.handleClick=function(){this.player_.getChild("BeforePlayNextLayer").cancel().dispose()},n}(f);_.prototype.controlText_="Cancel PlayNext",t.registerComponent("CancelPlayNextEl",_);var g=function(t){function n(e,n,i){var o;return void 0===i&&(i=0),o=t.call(this,n,i)||this,o.player_=e,o.loadPoster_=!0,o.autoPlayNext_=!0,o.play(i),e.off("ended",e.playNext),e.on("ended",e.playNext),o}e(n,t);var i=n.prototype;return i.autoPlayNext=function(t){if(void 0===t)return this.autoPlayNext_;this.autoPlayNext_=!!t,this.player_.trigger("autoplaynext",this.autoPlayNext_)},i.play=function(t){void 0!==t&&this.index(t);var e=this.current(),n=e.poster,i=e.sources,o=e.title,a=this.player_,l=function(){a.poster(n||"")};a.title(""),a.poster(""),this.loadPoster_?(this.loadPoster_=!1,a.autoplay()?a.one("autoplay-failure",l):l()):a.one("loadedmetadata",function(){a.play()}),"none"!==a.preload()&&(a.addClass("vjs-waiting"),a.one("loadedmetadata",function(){a.removeClass("vjs-waiting")})),a.src(i),a.title(o||""),a.trigger("playlistchange",Object.assign(this.current(),{index:this.index()}))},n}(i);t.registerPlugin("setPlayList",function(t){var e=this.player_;e.playlist=new g(e,t),e.trigger("playlist")}),t.hook("setup",function(t){var e=t.options_.playlist||[];e.length&&t.setPlayList(e)})}(videojs); diff --git a/dist/quality-hls/videojs-plus.quality-hls.min.js b/dist/quality-hls/videojs-plus.quality-hls.min.js index 3af0245..e2c217b 100644 --- a/dist/quality-hls/videojs-plus.quality-hls.min.js +++ b/dist/quality-hls/videojs-plus.quality-hls.min.js @@ -1 +1 @@ -!function(e){"use strict";function t(){return t=Object.assign||function(e){for(var t=1;t-1&&(ControlBar.prototype.options_.children=[{name:"ControlSeparator",className:"top",children:[]},{name:"ControlSeparator",className:"middle",children:n.splice(0,i+1)},{name:"ControlSeparator",className:"bottom",children:n}]),t}),video_js.hook("setup",function(e){var t=!1!==e.options_.mobileView;(function(e){return window.matchMedia?window.matchMedia("(max-width: "+e+"px)").matches:window.innerWidth<=e})(480)&&t&&(e.controlBar.hide(),e.one("playing",function(){var t=["mouseover","userinactive","touchstart"];e.one(t,function n(){e.off(t,n),e.controlBar.show()}),e.one("touchend",function(){e.userActive(!0)})}),e.addClass("vjs-mobile-view"))});var SeekBar=video_js.getComponent("SeekBar");SeekBar.prototype.getPercent=function(){var e=this.player_.currentTime(),t=e/this.player_.duration();return t>=1?1:t},SeekBar.prototype.handleMouseMove=function(e){var t=this.player_;if(video_js.dom.isSingleLeftClick(e)){var n=this.calculateDistance(e)*t.duration();n===t.duration()&&(n-=.1),t.currentTime(n),this.update()}},video_js.getComponent("ControlBar").prototype.options_.children=["PlayToggle","CustomControlSpacer","VolumePanel","CurrentTimeDisplay","TimeDivider","DurationDisplay","ProgressControl","CustomControlSpacer","SettingMenuButton","FullscreenToggle"],video_js.hook("setup",function(e){e.on("mouseleave",function(){e.userActive(!1)}),e.ready(function(){e.controls(!1!==e.options_.controls)})});var Title=function(e){function t(t,n){var i;return i=e.call(this,t,n)||this,i.title_=n.playerOptions.title||"",i.update(i.title_),i}_inheritsLoose(t,e);var n=t.prototype;return n.createEl=function(){var t=e.prototype.createEl.call(this,"div",{className:"vjs-title"});return this.contentEl_=video_js.dom.createEl("div",{className:"vjs-title-field"}),t.appendChild(this.contentEl_),t},n.update=function(e){e?this.show():this.hide(),this.player_.cache_.title=this.title_,this.title_=e,this.contentEl_.innerHTML=e},t}(video_js.getComponent("Component")),title=function(e){var t=this.player_.getChild("VideoTitle");if(void 0===e)return t.title_;t.update(e)};video_js.registerPlugin("title",title),video_js.registerComponent("VideoTitle",Title),video_js.getComponent("Player").prototype.options_.children.splice(2,0,"VideoTitle");var PlayToggleButton=video_js.getComponent("PlayToggle"),ClickableComponent=video_js.getComponent("ClickableComponent"),PlayToggleLayer=function(e){function t(t,n){return e.call(this,t,n)||this}_inheritsLoose(t,e);var n=t.prototype;return n.createEl=function(){return video_js.dom.createEl("div",{className:"vjs-play-toggle-layer"})},n.handleClick=function(e){(this.player_.userActive()||this.player_.paused())&&PlayToggleButton.prototype.handleClick.call(this,e)},t}(ClickableComponent);video_js.registerComponent("PlayToggleLayer",PlayToggleLayer);var playerChildren=video_js.getComponent("Player").prototype.options_.children,loadSpinnerIndex=playerChildren.indexOf("loadingSpinner");playerChildren.splice(loadSpinnerIndex,0,"PlayToggleLayer");var MenuItem=video_js.getComponent("MenuItem"),ContextMenuItem=function(e){function t(t,n){var i;return i=e.call(this,t,_extends({},n,{selectable:!0}))||this,i.addClass("vjs-context-menu-item"),i.controlText(n.label),i}_inheritsLoose(t,e);var n=t.prototype;return n.createEl=function(){for(var t,n=arguments.length,i=new Array(n),o=0;o