Skip to content

Commit 037dfed

Browse files
committed
Fix speed plugin always controlling the first player on the page via keyboard when multiple players exist
1 parent a54f0b5 commit 037dfed

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

dist/speed/speed.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ Object.assign(MediaElementPlayer.prototype, {
100100
radios = player.speedButton.querySelectorAll('input[type="radio"]'),
101101
labels = player.speedButton.querySelectorAll('.' + t.options.classPrefix + 'speed-selector-label');
102102

103-
/**
104-
* Store a reference to the radio buttons to prevent a scope bug in keyboard events
105-
* with multiple MediaElement players are on the same page. Otherwise these keyboard
106-
* events would always control the first speed button instance on the page.
107-
*/
108-
player.speedRadioButtons = radios;
109-
110103
for (var _i2 = 0, _total2 = inEvents.length; _i2 < _total2; _i2++) {
111104
player.speedButton.addEventListener(inEvents[_i2], function () {
112105
mejs.Utils.removeClass(player.speedSelector, t.options.classPrefix + 'offscreen');
@@ -161,10 +154,9 @@ Object.assign(MediaElementPlayer.prototype, {
161154
action: function action(player, media, key, event) {
162155
if (event.key != '<') return;
163156

164-
const _radios = player.speedRadioButtons;
165-
for (var _i7 = 0; _i7 < _radios.length - 1; _i7++) {
166-
if (_radios[_i7].checked) {
167-
var nextRadio = _radios[_i7 + 1];
157+
for (var _i7 = 0; _i7 < radios.length - 1; _i7++) {
158+
if (radios[_i7].checked) {
159+
var nextRadio = radios[_i7 + 1];
168160
nextRadio.dispatchEvent(mejs.Utils.createEvent('click', nextRadio));
169161
break;
170162
}
@@ -175,10 +167,9 @@ Object.assign(MediaElementPlayer.prototype, {
175167
action: function action(player, media, key, event) {
176168
if (event.key != '>') return;
177169

178-
const _radios = player.speedRadioButtons;
179-
for (var _i8 = 1; _i8 < _radios.length; _i8++) {
180-
if (_radios[_i8].checked) {
181-
var prevRadio = _radios[_i8 - 1];
170+
for (var _i8 = 1; _i8 < radios.length; _i8++) {
171+
if (radios[_i8].checked) {
172+
var prevRadio = radios[_i8 - 1];
182173
prevRadio.dispatchEvent(mejs.Utils.createEvent('click', prevRadio));
183174
break;
184175
}

src/speed/speed.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ Object.assign(MediaElementPlayer.prototype, {
141141
labels = player.speedButton.querySelectorAll(`.${t.options.classPrefix}speed-selector-label`)
142142
;
143143

144+
/**
145+
* Store a reference to the radio buttons to prevent a scope bug in keyboard events
146+
* with multiple MediaElement players are on the same page. Otherwise these keyboard
147+
* events would always control the first speed button instance on the page.
148+
*/
149+
player.speedRadioButtons = radios;
150+
144151
// hover or keyboard focus
145152
for (let i = 0, total = inEvents.length; i < total; i++) {
146153
player.speedButton.addEventListener(inEvents[i], () => {
@@ -202,9 +209,10 @@ Object.assign(MediaElementPlayer.prototype, {
202209
if (event.key != '<')
203210
return;
204211

205-
for (let i = 0; i < radios.length - 1; i++) {
206-
if (radios[i].checked) {
207-
const nextRadio = radios[i+1];
212+
const _radios = player.speedRadioButtons;
213+
for (let i = 0; i < _radios.length - 1; i++) {
214+
if (_radios[i].checked) {
215+
const nextRadio = _radios[i+1];
208216
nextRadio.dispatchEvent(mejs.Utils.createEvent('click', nextRadio));
209217
break;
210218
}
@@ -216,9 +224,10 @@ Object.assign(MediaElementPlayer.prototype, {
216224
if (event.key != '>')
217225
return;
218226

219-
for (let i = 1; i < radios.length; i++) {
220-
if (radios[i].checked) {
221-
const prevRadio = radios[i-1];
227+
const _radios = player.speedRadioButtons;
228+
for (let i = 1; i < _radios.length; i++) {
229+
if (_radios[i].checked) {
230+
const prevRadio = _radios[i-1];
222231
prevRadio.dispatchEvent(mejs.Utils.createEvent('click', prevRadio));
223232
break;
224233
}

0 commit comments

Comments
 (0)