Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: move sortAscending and autoPlacement parameters into "defaults" #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import ConcreteButton from './ConcreteButton';
import ConcreteMenuItem from './ConcreteMenuItem';

// Default options for the plugin.
const defaults = {};
const defaults = {
sortAscending: false,
autoPlacement: 'top'
};

// Cross-compatibility for Video.js 5 and 6.
const registerPlugin = videojs.registerPlugin || videojs.plugin;
Expand Down Expand Up @@ -47,8 +50,7 @@ class HlsQualitySelectorPlugin {
* Binds listener for quality level changes.
*/
bindPlayerEvents() {
this.player.qualityLevels().on('addqualitylevel', this.onAddQualityLevel.bind(this,
this.config.sortAscending, this.config.autoPlacement));
this.player.qualityLevels().on('addqualitylevel', this.onAddQualityLevel.bind(this));
}

/**
Expand Down Expand Up @@ -102,17 +104,13 @@ class HlsQualitySelectorPlugin {

/**
* Executed when a quality level is added from HLS playlist.
*
* @param {boolean} sortAscending - sort quality levels, default is ascending.
* @param {string} autoPlacement - place the 'auto' menu item at the 'top' or
* 'bottom' (default).
*/
onAddQualityLevel(sortAscending = true, autoPlacement = 'bottom') {

onAddQualityLevel() {
const player = this.player;
const qualityList = player.qualityLevels();
const levels = qualityList.levels_ || [];
const levelItems = [];
const autoPlacement = this.config.autoPlacement;
const autoMenuItem = this.getQualityMenuItem.call(this, {
label: player.localize('Auto'),
value: 'auto',
Expand All @@ -133,7 +131,7 @@ class HlsQualitySelectorPlugin {
}

// sort the quality level values
if (sortAscending) {
if (this.config.sortAscending) {
levelItems.sort((current, next) => {
if ((typeof current !== 'object') || (typeof next !== 'object')) {
return -1;
Expand Down