Skip to content

Commit

Permalink
move listener removal from handleMouseUp() into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-barstow committed Mar 23, 2021
1 parent 0cc8684 commit 42cad3a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/js/control-bar/progress-control/progress-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class ProgressControl extends Component {

this.off(['mousedown', 'touchstart'], this.handleMouseDown);
this.off(this.el_, 'mousemove', this.handleMouseMove);
this.handleMouseUp();

this.removeListenersAddedOnMousedownAndTouchstart();

this.addClass('disabled');

Expand All @@ -161,6 +162,18 @@ class ProgressControl extends Component {
this.enabled_ = true;
}

/**
* Cleanup listeners after the user finishes interacting with the progress controls
*/
removeListenersAddedOnMousedownAndTouchstart() {
const doc = this.el_.ownerDocument;

this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchend', this.handleMouseUp);
}

/**
* Handle `mousedown` or `touchstart` events on the `ProgressControl`.
*
Expand Down Expand Up @@ -194,17 +207,13 @@ class ProgressControl extends Component {
* @listens mouseup
*/
handleMouseUp(event) {
const doc = this.el_.ownerDocument;
const seekBar = this.getChild('seekBar');

if (seekBar) {
seekBar.handleMouseUp(event);
}

this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchend', this.handleMouseUp);
this.removeListenersAddedOnMousedownAndTouchstart();
}
}

Expand Down

0 comments on commit 42cad3a

Please sign in to comment.