-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: master
Are you sure you want to change the base?
Conversation
…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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @PrestonN!
@PrestonN! This is just what I need. Thanks @jthomerson if this works fine, please merge it and |
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. :) |
Hi, Thanks! |
need this, too. Please merge it. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **`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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = ''; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check for quality select label flag | |
// Check for quality selector label flag |
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.
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! |
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:
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 classvjs-quality-selector-icon
) when the flag is disabled to include the icon. When enabled, basic HTML is simply included into the element.Refs #28