Skip to content

Commit

Permalink
✨ amp-connatix-player: add support for custom data param (#37332)
Browse files Browse the repository at this point in the history
* add support for custom data param

* fix lint
  • Loading branch information
gaborkalmar committed Feb 7, 2022
1 parent 8f24c06 commit ac061f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extensions/amp-connatix-player/0.1/amp-connatix-player.js
Expand Up @@ -3,7 +3,7 @@ import {
CONSENT_STRING_TYPE,
} from '#core/constants/consent-state';
import {Deferred} from '#core/data-structures/promise';
import {removeElement} from '#core/dom';
import {getDataParamsFromAttributes, removeElement} from '#core/dom';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {
observeContentSize,
Expand Down Expand Up @@ -272,6 +272,7 @@ export class AmpConnatixPlayer extends AMP.BaseElement {
'playerId': this.playerId_ || undefined,
'mediaId': this.mediaId_ || undefined,
'url': Services.documentInfoForDoc(element).sourceUrl,
...getDataParamsFromAttributes(element),
};
const iframeUrl = this.iframeDomain_ + '/amp-embed/index.html';
const src = addParamsToUrl(iframeUrl, urlParams);
Expand Down
Expand Up @@ -69,6 +69,18 @@ describes.realWin(
'https://cdm.elements.video/amp-embed/index.html?playerId=f721b0d8-7a79-42b6-b637-fa4e86138ed9&url=about%3Asrcdoc'
);
});
it('should pass data-param-* attributes to the iframe src', async () => {
const cnx = await getConnatixPlayer({
'data-player-id': 'f721b0d8-7a79-42b6-b637-fa4e86138ed9',
'data-param-my-param': 17,
});
const iframe = cnx.querySelector('iframe');
expect(iframe).to.not.be.null;
expect(iframe.tagName).to.equal('IFRAME');
expect(iframe.src).to.equal(
'https://cdm.connatix.com/amp-embed/index.html?playerId=f721b0d8-7a79-42b6-b637-fa4e86138ed9&url=about%3Asrcdoc&myParam=17'
);
});

it('fails if no playerId is specified', () => {
return allowConsoleError(() => {
Expand Down
4 changes: 4 additions & 0 deletions extensions/amp-connatix-player/amp-connatix-player.md
Expand Up @@ -38,6 +38,10 @@ Connatix management dashboard.
Connatix media id. This represents the unique ID of any media in your Library.
This can be found at the Library section in the Connatix management dashboard.

### data-param-\*

All `data-param-*` prefixed attributes are turned into URL parameters and passed to iframe src.

### Common attributes

This element includes [common attributes](https://amp.dev/documentation/guides-and-tutorials/learn/common_attributes)
Expand Down

0 comments on commit ac061f2

Please sign in to comment.