Skip to content

Commit 6fc4076

Browse files
committed
minor change
1 parent 65248c5 commit 6fc4076

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

extensions/amp-connatix-player/0.1/amp-connatix-player.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
9999

100100
/** @private {boolean} */
101101
this.muted_ = true;
102+
103+
/** @private {?MutationObserver} */
104+
this.mutationObserver_ = null;
102105
}
103106

104107
/**
@@ -330,29 +333,32 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
330333
// bind to amp consent and send consent info to the iframe content and propagate to player
331334
this.bindToAmpConsent_();
332335

336+
if (!this.mutationObserver_) {
337+
const mutationObserverCallback = (mutationList) => {
338+
for (const mutation of mutationList) {
339+
if (
340+
mutation.type === 'attributes' &&
341+
mutation.attributeName === 'class'
342+
) {
343+
this.sendCommand_(
344+
mutation.target.classList.contains('i-amphtml-video-docked')
345+
? 'dock'
346+
: 'undock'
347+
);
348+
}
349+
}
350+
};
351+
352+
this.mutationObserver_ = new MutationObserver(mutationObserverCallback);
353+
}
354+
333355
const mutationObserverConfig = {
334356
attributes: true,
335357
childList: false,
336358
subtree: false,
337359
};
338360

339-
const callback = (mutationList) => {
340-
for (const mutation of mutationList) {
341-
if (
342-
mutation.type === 'attributes' &&
343-
mutation.attributeName === 'class'
344-
) {
345-
this.sendCommand_(
346-
mutation.target.classList.contains('i-amphtml-video-docked')
347-
? 'dock'
348-
: 'undock'
349-
);
350-
}
351-
}
352-
};
353-
354-
const observer = new MutationObserver(callback);
355-
observer.observe(this.iframe_, mutationObserverConfig);
361+
this.mutationObserver_.observe(this.iframe_, mutationObserverConfig);
356362

357363
observeContentSize(this.element, this.onResized_);
358364
this.pauseHelper_.updatePlaying(true);
@@ -396,6 +402,7 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
396402
this.playerReadyResolver_ = deferred.resolve;
397403

398404
unobserveContentSize(this.element, this.onResized_);
405+
this.mutationObserver_.disconnect();
399406
this.pauseHelper_.updatePlaying(false);
400407

401408
return true;

0 commit comments

Comments
 (0)