mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove event listeners if controls are removed
This commit is contained in:
parent
ef02196dd8
commit
ef5ded943c
1 changed files with 11 additions and 6 deletions
|
@ -80,11 +80,9 @@
|
||||||
// Get the instance of the host of these controls.
|
// Get the instance of the host of these controls.
|
||||||
this.media = this.controls.host;
|
this.media = this.controls.host;
|
||||||
|
|
||||||
this.shutthingDown = false;
|
|
||||||
this.mutationObserver = new MutationObserver(() => {
|
this.mutationObserver = new MutationObserver(() => {
|
||||||
// We can only get here if the `controls` attribute is removed.
|
// We can only get here if the `controls` attribute is removed.
|
||||||
this.shutthingDown = true;
|
this.cleanup();
|
||||||
this.mutationObserver.disconnect();
|
|
||||||
});
|
});
|
||||||
this.mutationObserver.observe(this.media, {
|
this.mutationObserver.observe(this.media, {
|
||||||
attributeFilter: ["controls"]
|
attributeFilter: ["controls"]
|
||||||
|
@ -208,15 +206,22 @@
|
||||||
this.onStateChange(null);
|
this.onStateChange(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
this.mutationObserver.disconnect();
|
||||||
|
this.mediaEvents.forEach(event => {
|
||||||
|
this.media.removeEventListener(event, this);
|
||||||
|
});
|
||||||
|
this.controlEvents.forEach(({ el, type }) => {
|
||||||
|
el.removeEventListener(type, this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// State change handler
|
// State change handler
|
||||||
onStateChange(from) {
|
onStateChange(from) {
|
||||||
this.render(from);
|
this.render(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
render(from = this.state) {
|
render(from = this.state) {
|
||||||
if (this.shutthingDown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const isAudioOnly = this.media.localName == "audio";
|
const isAudioOnly = this.media.localName == "audio";
|
||||||
if (!isAudioOnly) {
|
if (!isAudioOnly) {
|
||||||
// XXX This should ideally use clientHeight/clientWidth,
|
// XXX This should ideally use clientHeight/clientWidth,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue