Skip to content

Commit 1069e7f

Browse files
guided1gkatsev
authored andcommitted
refactor: move seekbar event handler bindings into a function (videojs#5097)
Makes it easier to extend the seekbar and change the default event handlers. If you extend the seekbar component you can choose to override setEventHandlers_ or keep it default. If you do override setEventHandlers_ and call super() in the constructor, you get your own event handlers + the functionality provided by Slider.
1 parent d0b03a3 commit 1069e7f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/js/control-bar/progress-control/seek-bar.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,25 @@ class SeekBar extends Slider {
3838
*/
3939
constructor(player, options) {
4040
super(player, options);
41+
this.setEventHandlers_();
42+
}
4143

44+
/**
45+
* Sets the event handlers
46+
*
47+
* @private
48+
*/
49+
setEventHandlers_() {
4250
this.update = Fn.throttle(Fn.bind(this, this.update), UPDATE_REFRESH_INTERVAL);
4351

44-
this.on(player, 'timeupdate', this.update);
45-
this.on(player, 'ended', this.handleEnded);
52+
this.on(this.player_, 'timeupdate', this.update);
53+
this.on(this.player_, 'ended', this.handleEnded);
4654

4755
// when playing, let's ensure we smoothly update the play progress bar
4856
// via an interval
4957
this.updateInterval = null;
5058

51-
this.on(player, ['playing'], () => {
59+
this.on(this.player_, ['playing'], () => {
5260
this.clearInterval(this.updateInterval);
5361

5462
this.updateInterval = this.setInterval(() =>{
@@ -58,11 +66,11 @@ class SeekBar extends Slider {
5866
}, UPDATE_REFRESH_INTERVAL);
5967
});
6068

61-
this.on(player, ['ended', 'pause', 'waiting'], () => {
69+
this.on(this.player_, ['ended', 'pause', 'waiting'], () => {
6270
this.clearInterval(this.updateInterval);
6371
});
6472

65-
this.on(player, ['timeupdate', 'ended'], this.update);
73+
this.on(this.player_, ['timeupdate', 'ended'], this.update);
6674
}
6775

6876
/**

0 commit comments

Comments
 (0)