From 7da6fd37df097f47e7e412ac43b604974662891b Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Mon, 20 Nov 2017 14:51:01 -0500 Subject: [PATCH] Use `selected = false`, over `_.omit` to deselect a source From a basic functionality standpoint, this accomplishes the same purpose as the previous implementation using `_.omit`. However, rather than removing the `selected` attribute from the sources, this will keep the structure the same by only altering the value of the source. If your usage of this plugin requires a stable source format, e.g. for comparing sources to see if the source changed, please provide the `selected` attribute when programmatically setting the player source. At this time, we don't have a simple way to standardize the `selected` attribute on initial source load. (i.e. It's up to the programmer to set the initial format on the sources before giving them to the player) --- src/js/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/index.js b/src/js/index.js index 478999b..8155d0c 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -19,7 +19,11 @@ module.exports = function(videojs) { isPaused = player.paused(), selectedSource; - sources = _.map(sources, _.partial(_.omit, _, 'selected')); + // Clear out any previously selected sources (see: #11) + _.each(sources, function(source) { + source.selected = false; + }); + selectedSource = _.findWhere(sources, { src: newSource.src }); // Note: `_.findWhere` returns a reference to an object. Thus the // following updates the original object in `sources`.