Skip to content

Commit 2bbc6ca

Browse files
committed
Handling missing captions button better
There was a bug introduced in 86a53b4 that caused a dependency between existence of the captionsButton and the captionsMuted property. However, there are many cases where there is no visible captions button but the developer would like to control captions from another UI interaction/element/mechanism. This should fix that functionality
1 parent 1858f88 commit 2bbc6ca

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/container/plugins/CaptionsPlugin.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@
6565
*/
6666
this.captionsButton = document.querySelector(this.options.captionsButton);
6767

68-
if (null === this.captionsButton)
68+
if (null !== this.captionsButton)
6969
{
70-
return;
71-
}
72-
73-
this.captionsButtonClick = function()
74-
{
75-
this.captionsMuted = !this.captionsMuted;
76-
}.bind(this);
70+
this.captionsButtonClick = function()
71+
{
72+
this.captionsMuted = !this.captionsMuted;
73+
}.bind(this);
7774

78-
this.captionsButton.addEventListener('click', this.captionsButtonClick);
75+
this.captionsButton.addEventListener('click', this.captionsButtonClick);
76+
}
7977

8078
/**
8179
* Set the captions are enabled or not
@@ -194,8 +192,11 @@
194192
// Handle the features request
195193
this.on('features', function(features)
196194
{
197-
this.captionsButton.style.display = 'none';
198-
if (features.captions) this.captionsButton.style.display = 'inline-block';
195+
if (null !== this.captionsButton)
196+
{
197+
this.captionsButton.style.display = 'none';
198+
if (features.captions) this.captionsButton.style.display = 'inline-block';
199+
}
199200
});
200201

201202
//Set the defaults if we have none for the controls
@@ -207,35 +208,31 @@
207208

208209
plugin.opened = function()
209210
{
210-
if (null === this.captionsButton)
211+
if (null !== this.captionsButton)
211212
{
212-
return;
213+
this.captionsButton.classList.remove('disabled');
213214
}
214215

215-
this.captionsButton.classList.remove('disabled');
216216
this.captionsMuted = !!SavedData.read(CAPTIONS_MUTED);
217217
this.setCaptionsStyles(SavedData.read(CAPTIONS_STYLES));
218218
};
219219

220220
plugin.close = function()
221221
{
222-
if (null === this.captionsButton)
222+
if (null !== this.captionsButton)
223223
{
224-
return;
224+
this._disableButton(this.captionsButton);
225225
}
226-
227-
this._disableButton(this.captionsButton);
228226
};
229227

230228
plugin.teardown = function()
231229
{
232-
if (null === this.captionsButton)
230+
if (null !== this.captionsButton)
233231
{
234-
return;
232+
this.captionsButton.removeEventListener('click', this.captionsButtonClick);
233+
delete this.captionsButton;
235234
}
236235

237-
this.captionsButton.removeEventListener('click', this.captionsButtonClick);
238-
delete this.captionsButton;
239236
delete this._captionsStyles;
240237
delete this.getCaptionsStyles;
241238
delete this.setCaptionsStyles;

0 commit comments

Comments
 (0)