mirror of
https://github.com/iv-org/videojs-quality-selector.git
synced 2025-04-25 17:59:16 -04:00
refactor: Use ES6 classes instead of videojs.extend
This commit is contained in:
parent
a40e9a6803
commit
68eb394cb7
@ -10,12 +10,12 @@ module.exports = function(videojs) {
|
|||||||
* @class QualityOption
|
* @class QualityOption
|
||||||
* @extends videojs.MenuItem
|
* @extends videojs.MenuItem
|
||||||
*/
|
*/
|
||||||
return videojs.extend(MenuItem, {
|
return class QualityOption extends MenuItem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
constructor: function(player, options) {
|
constructor(player, options) {
|
||||||
var source = options.source;
|
var source = options.source;
|
||||||
|
|
||||||
if (!_.isObject(source)) {
|
if (!_.isObject(source)) {
|
||||||
@ -27,18 +27,17 @@ module.exports = function(videojs) {
|
|||||||
label: source.label,
|
label: source.label,
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
MenuItem.call(this, player, options);
|
super(player, options);
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
handleClick: function(event) {
|
handleClick(event) {
|
||||||
MenuItem.prototype.handleClick.call(this, event);
|
super.handleClick(event);
|
||||||
this.player().trigger(events.QUALITY_REQUESTED, this.source);
|
this.player().trigger(events.QUALITY_REQUESTED, this.source);
|
||||||
},
|
}
|
||||||
|
};
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
@ -5,8 +5,7 @@ var _ = require('underscore'),
|
|||||||
|
|
||||||
module.exports = function(videojs) {
|
module.exports = function(videojs) {
|
||||||
var MenuButton = videojs.getComponent('MenuButton'),
|
var MenuButton = videojs.getComponent('MenuButton'),
|
||||||
QualityOption = qualityOptionFactory(videojs),
|
QualityOption = qualityOptionFactory(videojs);
|
||||||
QualitySelector;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A component for changing video resolutions
|
* A component for changing video resolutions
|
||||||
@ -14,13 +13,13 @@ module.exports = function(videojs) {
|
|||||||
* @class QualitySelector
|
* @class QualitySelector
|
||||||
* @extends videojs.Button
|
* @extends videojs.Button
|
||||||
*/
|
*/
|
||||||
QualitySelector = videojs.extend(MenuButton, {
|
class QualitySelector extends MenuButton {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
constructor: function(player, options) {
|
constructor(player, options) {
|
||||||
MenuButton.call(this, player, options);
|
super(player, options);
|
||||||
|
|
||||||
// Update interface instantly so the user's change is acknowledged
|
// Update interface instantly so the user's change is acknowledged
|
||||||
player.on(events.QUALITY_REQUESTED, function(event, newSource) {
|
player.on(events.QUALITY_REQUESTED, function(event, newSource) {
|
||||||
@ -50,14 +49,14 @@ module.exports = function(videojs) {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.controlText('Open quality selector menu');
|
this.controlText('Open quality selector menu');
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the source that is selected in the menu
|
* Updates the source that is selected in the menu
|
||||||
*
|
*
|
||||||
* @param source {object} player source to display as selected
|
* @param source {object} player source to display as selected
|
||||||
*/
|
*/
|
||||||
setSelectedSource: function(source) {
|
setSelectedSource(source) {
|
||||||
var src = (source ? source.src : undefined);
|
var src = (source ? source.src : undefined);
|
||||||
|
|
||||||
if (this.selectedSrc !== src) {
|
if (this.selectedSrc !== src) {
|
||||||
@ -66,12 +65,12 @@ module.exports = function(videojs) {
|
|||||||
item.selected(item.source.src === src);
|
item.selected(item.source.src === src);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
createItems: function() {
|
createItems() {
|
||||||
var player = this.player(),
|
var player = this.player(),
|
||||||
sources = player.currentSources();
|
sources = player.currentSources();
|
||||||
|
|
||||||
@ -85,16 +84,15 @@ module.exports = function(videojs) {
|
|||||||
selected: source.src === this.selectedSrc,
|
selected: source.src === this.selectedSrc,
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
buildWrapperCSSClass: function() {
|
buildWrapperCSSClass() {
|
||||||
return 'vjs-quality-selector ' + MenuButton.prototype.buildWrapperCSSClass.call(this);
|
return 'vjs-quality-selector ' + super.buildWrapperCSSClass();
|
||||||
},
|
}
|
||||||
|
}
|
||||||
});
|
|
||||||
|
|
||||||
videojs.registerComponent('QualitySelector', QualitySelector);
|
videojs.registerComponent('QualitySelector', QualitySelector);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user