Skip to content

Commit

Permalink
Provide unlayoutCallback for amp-vine (ampproject#33597)
Browse files Browse the repository at this point in the history
* Provide unlayoutCallback for amp-vine

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

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

/** @override */
pauseCallback() {
if (this.iframe_ && this.iframe_.contentWindow) {
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-vine/0.1/test/test-amp-vine.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ describes.realWin(
/The data-vineid attribute is required for/
);
});

it('unlayout and relayout', async () => {
const vine = await getVine('MdKjXez002d', true);
expect(vine.querySelector('iframe')).to.exist;

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

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

0 comments on commit d15ac15

Please sign in to comment.