Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

icon with the label of the currently selected source.

#### Providing initialization options via `require()`

If requiring this plugin via NPM, any desired initialization options can be supplied to
the constructor function exported by the module. For example:

```js
require('@silvermine/videojs-quality-selector')(videojs, { showQualitySelectionLabelInControlBar: true });
```

#### Providing initialization options via `<script>`

If using the prebuilt JS, the initialization options can be provided via
`window.SILVERMINE_VIDEOJS_QUALITY_SELECTOR_CONFIG`. Note that these options need to be set
before the `<script>` tag to include the plugin.

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

### Providing video sources

Sources can be provided with either the `<source>` tag or via the `src` function on the
Expand Down
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/js/components/QualitySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var _ = require('underscore'),
qualityOptionFactory = require('./QualityOption'),
QUALITY_CHANGE_CLASS = 'vjs-quality-changing';

module.exports = function(videojs) {
var MenuButton = videojs.getComponent('MenuButton'),
module.exports = function(videojs, userOpts) {
var userOptions = _.defaults(_.extend({}, userOpts), { showQualitySelectionLabelInControlBar: false }),
MenuButton = videojs.getComponent('MenuButton'),
QualityOption = qualityOptionFactory(videojs),
QualitySelector;

Expand All @@ -22,6 +23,8 @@ module.exports = function(videojs) {
* @inheritdoc
*/
constructor: function(player, options) {
var qualitySelectMenuButton = this.children_[0].controlTextEl_.previousSibling;

MenuButton.call(this, player, options);

// Update interface instantly so the user's change is acknowledged
Expand All @@ -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

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) {

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.

} 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.

}
}.bind(this));

// Since it's possible for the player to get a source before the selector is
Expand Down
4 changes: 2 additions & 2 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ var _ = require('underscore'),
sourceInterceptorFactory = require('./middleware/SourceInterceptor'),
SafeSeek = require('./util/SafeSeek');

module.exports = function(videojs) {
module.exports = function(videojs, userOpts) {
videojs = videojs || window.videojs;

qualitySelectorFactory(videojs);
qualitySelectorFactory(videojs, userOpts);
sourceInterceptorFactory(videojs);

videojs.hook('setup', function(player) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/standalone.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

require('./index')();
require('./index')(undefined, window.SILVERMINE_VIDEOJS_QUALITY_SELECTOR_CONFIG);
2 changes: 1 addition & 1 deletion src/sass/quality-selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
height: 100%;
width: 100%;
}
.vjs-icon-placeholder {
.vjs-quality-selector-icon {
// From video.js font: https://github.com/videojs/font
font-family: 'VideoJS';
font-weight: normal;
Expand Down