ntv-site/js/videojs-hls-quality-selector.min.js

7 lines
4.7 KiB
JavaScript
Raw Normal View History

2023-03-26 07:48:25 +00:00
/**
* tingtingan-videojs-hls-quality-selector
* @version 1.1.10
* @copyright 2022 Chris Boustead (chris@forgemotion.com)
* @license MIT
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],e):t.videojsHlsQualitySelector=e(t.videojs)}(this,function(o){"use strict";o=o&&o.hasOwnProperty("default")?o.default:o;var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function l(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function t(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function s(t,e){if(t)return!e||"object"!=typeof e&&"function"!=typeof e?t:e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}var e=o.getComponent("MenuButton"),n=o.getComponent("Menu"),u=o.getComponent("Component"),r=o.dom;t(c,a=e),c.prototype.createItems=function(){return[]},c.prototype.createMenu=function(){var t,e=new n(this.player_,{menuButton:this});if(e.addClass("hls-quality-button"),this.hideThreshold_=0,this.options_.title&&(t=r.createEl("li",{className:"vjs-menu-title",innerHTML:"string"!=typeof(t=this.options_.title)?t:t.charAt(0).toUpperCase()+t.slice(1),tabIndex:-1}),t=new u(this.player_,{el:t}),this.hideThreshold_+=1,e.addItem(t)),this.items=this.createItems(),this.items)for(var i=0;i<this.items.length;i++)e.addItem(this.items[i]);return e};var a,h=c;function c(t){return l(this,c),s(this,a.call(this,t,{title:t.localize("Quality"),name:"QualityButton"}))}var y,e=o.getComponent("MenuItem"),p=(t(f,y=e),f.prototype.handleClick=function(){for(var t=0;t<this.qualityButton.items.length;++t)this.qualityButton.items[t].selected(!1);this.plugin.setQuality(this.item.value),this.selected(!0)},f);function f(t,e,i,n){l(this,f);t=s(this,y.call(this,t,{label:e.label,selectable:!0,selected:e.selected||!1}));return t.item=e,t.qualityButton=i,t.plugin=n,t}var d={},e=o.registerPlugin||o.plugin,m=(v.prototype.getHls=function(){return this.player.tech({IWillNotUseThisInPlugins:!0}).vhs},v.prototype.bindPlayerEvents=function(){this.player.qualityLevels().on("addqualitylevel",this.onAddQualityLevel.bind(this))},v.prototype.createQualityButton=function(){var t=this.player,e=(this._qualityButton=new h(t),t.controlBar.children().length-2),t=t.controlBar.addChild(this._qualityButton,{componentClass:"qualitySelector"},this.config.placementIndex||e);t.addClass("vjs-quality-selector"),this.config.displayCurrentQuality?this.setButtonInnerText(this.player.localize("Auto")):(e=" "+(this.config.vjsIconClass||"vjs-icon-hd"),t.menuButton_.$(".vjs-icon-placeholder").className+=e),t.removeClass("vjs-hidden")},v.prototype.setButtonInnerText=function(t){this._qualityButton.menuButton_.$(".vjs-icon-placeholder").innerHTML=t},v.prototype.getQualityMenuItem=function(t){var e=this.player;return new p(e,t,this._qualityButton,this)},v.prototype.onAddQualityLevel=function(){for(var n=this,t=this.player,o=t.qualityLevels().levels_||[],l=[],e=0;e<o.length;++e)!function(t){var t=o[t],e=t.width,t=t.height,i=t<e?t:e;if(!i)return;l.filter(function(t){return t.item&&t.item.value===i}).length||(t=n.getQualityMenuItem.call(n,{label:i+"p",value:i}),l.push(t))}(e);l.sort(function(t,e){return"object"!==(void 0===t?"undefined":i(t))||"object"!==(void 0===e?"undefined":i(e))||t.item.value<e.item.value?-1:t.item.value>e.item.value?1:0}),l.push(this.getQualityMenuItem.call(this,{label:t.localize("Auto"),value:"auto",selected:!0})),this._qualityButton&&(this._qualityButton.createItems=function(){return l},this._qualityButton.update())},v.prototype.setQuality=function(t){var e=this.player.qualityLevels();this._currentQuality=t,this.config.displayCurrentQuality&&this.setButtonInnerText("auto"===t?this.player.localize("Auto"):t+"p");for(var i=0;i<e.lengt