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

feat: Support toggling the select icon with the source label (#28) #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PrestonN
Copy link

User options can now be passed to the plugin. Options are passed upon initialization and use the following syntax:

require('@silvermine/videojs-quality-selector')(videojs, options);

If you're not using require, you can pass options using a window config:

<script>
   window.SILVERMINE_VIDEOJS_QUALITY_SELECTOR_CONFIG = {
      showQualitySelectionLabelInControlBar: true,
   };
</script>
<script src="path/to/silvermine-videojs-quality-selector.js"></script>

The options are sent from the constructor to /components/QualitySelector.js.

Currently only one option is available:

  • showQualitySelectionLabelInControlBar (default: false) - Enabling this flag will swap the selector icon with the label of the currently selected source.

More options should be possible by adding them to the object.

A class is added to the Menu Item (Item with class vjs-icon-placeholder is given the class vjs-quality-selector-icon) when the flag is disabled to include the icon. When enabled, basic HTML is simply included into the element.

Refs #28

…ine#28)

User options can now be passed to the plugin.  Options are passed upon initialization and use the following syntax:

require('@silvermine/videojs-quality-selector')(videojs, options);

If you're not using require, you can pass options using a window config:

<script>
   window.SILVERMINE_VIDEOJS_QUALITY_SELECTOR_CONFIG = {
      showQualitySelectionLabelInControlBar: true,
   };
</script>
<script src="path/to/silvermine-videojs-quality-selector.js"></script>

The options are sent from the constructor to `/components/QualitySelector.js`.

Currently only one option is available:

showQualitySelectionLabelInControlBar: (default: `false`) - Enabling this flag will swap the selector
icon with the label of the currently selected source.

More options should be possible by adding them to the object.

A class is added to the Menu Item (Has class vjs-icon-placeholder) when the flag is disabled to include the icon.  When enabled, basic HTML is simply included into the element.

Refs silvermine#28
Copy link
Contributor

@jimjenkins5 jimjenkins5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @PrestonN!

@clwy-cn
Copy link

clwy-cn commented Apr 22, 2020

@PrestonN! This is just what I need. Thanks

@jthomerson if this works fine, please merge it and npm publish

@PrestonN
Copy link
Author

Hello!

Is there any update on when this will be merged? I'd love to see this work merged so that I can start using this functionality with my own project. If you want any changes to be made to it then please let me know. Hope to hear back from you. :)

@syeopite
Copy link

syeopite commented Sep 13, 2021

Hi,
It looks like this PR has been sitting for more than a year now. Is there any chance it could get merged soon?

Thanks!

@Jazzman1976
Copy link

need this, too. Please merge it.

Copy link
Contributor

@yokuze yokuze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PrestonN Sorry for the delay. Thank you for the contribution. I added a few comments. When you address them, please don't use the "Commit suggestion" button since this creates separate commits for the fixes. Instead, please fix up the existing commits with the changes to keep the history clean.

This PR will also need a rebase against master since there are merge conflicts now.

@@ -64,6 +64,35 @@ var videojs = require('videojs');
require('@silvermine/videojs-quality-selector')(videojs);
```

### Initialization options

* **`showQualitySelectionLabelInControlBar`** (default: `false`) - Enabling this flag will swap the selector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **`showQualitySelectionLabelInControlBar`** (default: `false`) - Enabling this flag will swap the selector
* **`showQualitySelectionLabelInControlBar`** (default: `false`) - When `true`, the
quality selector menu button will display the label of the currently selected source.
When `false`, the quality selector menu button will display an icon.

@@ -42,6 +45,15 @@ module.exports = function(videojs) {
player.on(events.QUALITY_SELECTED, function(event, newSource) {
// Update the selected source with the source that was actually selected
this.setSelectedSource(newSource);

// Check for quality select label flag
if (userOptions.showQualitySelectionLabelInControlBar !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (userOptions.showQualitySelectionLabelInControlBar !== false) {
if (userOptions.showQualitySelectionLabelInControlBar) {

} else if (qualitySelectMenuButton.className.indexOf('vjs-quality-selector-icon') === -1) {
// Add class to show gear icon. Blank out innerHTML for safety precations.
qualitySelectMenuButton.className += ' vjs-quality-selector-icon';
qualitySelectMenuButton.innerHTML = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why blank out innerHTML here? We lose the vjs-control-text element, which is important for accessibility.


// Check for quality select label flag
if (userOptions.showQualitySelectionLabelInControlBar !== false) {
qualitySelectMenuButton.innerHTML = newSource.label;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting innerHTML here wipes out the vjs-control-text element, which is important for accessibility. One way we can avoid doing that is to add an element to the button that displays the label text:

if (!this._qualitySelectorLabel) {
   this._qualitySelectorLabel = document.createElement('span');
   this._qualitySelectorLabel.classList.add('vjs-quality-selector-label');
   qualitySelectMenuButton.prepend(this._qualitySelectorLabel);
}
this._qualitySelectorLabel.innerHTML = newSource.label;

and then add this bit of CSS:

// Hide the quality selector icon if there is a quality selector label present
.vjs-quality-selector-label ~ .vjs-quality-selector-icon {
   display: none;
}

This would also make the else if section unnecessary.

@@ -42,6 +45,15 @@ module.exports = function(videojs) {
player.on(events.QUALITY_SELECTED, function(event, newSource) {
// Update the selected source with the source that was actually selected
this.setSelectedSource(newSource);

// Check for quality select label flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check for quality select label flag
// Check for quality selector label flag

@PrestonN
Copy link
Author

PrestonN commented May 1, 2022

Hi @yokuze, thanks for taking the time to look at this!

While working on the fixes that you've mentioned, I've come across 2 different problems while applying the changes.

  • For some reason qualitySelectMenuButton doesn't initialize properly any more unless MenuButton.call() is called beforehand. Due to your linting rules, it doesn't seem like this is desirable.
  • The CSS you provided doesn't seem to work as intended. I'll admit I'm not too familiar with the ~ handler, however looking it up it seems that since the new span element we're creating is a child to .vjs-quality-selector-icon so this won't get grabbed with your snippet. I can solve this issue using a little bit of JS to hide the icon, but I'm going to guess you'd prefer a pure CSS approach to this (outside of the JS that's currently there).

Please advice on how you'd like for me to approach these issues, and I will push my changes to this branch. Thanks again for taking the time to look at this. I'm really looking forward to getting this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants