Skip to content

Commit

Permalink
Provide unlayout callback for amp-dailymotion (ampproject#33588)
Browse files Browse the repository at this point in the history
* Provide unlayout callback for amp-dailymotion

* fix spelling
  • Loading branch information
Dima Voytenko authored and rochapablo committed Aug 30, 2021
1 parent 6f9212d commit 006594e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions extensions/amp-dailymotion/0.1/amp-dailymotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ class AmpDailymotion extends AMP.BaseElement {
return this.loadPromise(this.iframe_);
}

/** @override */
unlayoutCallback() {
const iframe = this.iframe_;
if (iframe) {
this.element.removeChild(iframe);
this.iframe_ = null;
}
return true;
}

/**
* @param {!Event} event
* @private
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-dailymotion/0.1/test/test-amp-dailymotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,17 @@ describes.realWin(
);
});
});

it('unlayout and relayout', async () => {
const dailymotion = await getDailymotion('x2m8jpp');
expect(dailymotion.querySelector('iframe')).to.exist;

const unlayoutResult = dailymotion.unlayoutCallback();
expect(unlayoutResult).to.be.true;
expect(dailymotion.querySelector('iframe')).to.not.exist;

await dailymotion.layoutCallback();
expect(dailymotion.querySelector('iframe')).to.exist;
});
}
);

0 comments on commit 006594e

Please sign in to comment.