Skip to content

Commit

Permalink
install viewer integration script when inside the player
Browse files Browse the repository at this point in the history
  • Loading branch information
Enriqe committed Feb 10, 2020
1 parent 7ac50af commit 4f26d11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 15 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ export class AmpStory extends AMP.BaseElement {
.then(() => {
this.markStoryAsLoaded_();
this.initializeLiveStory_();
this.initializeStoryPlayer_();
});

// Story is being prerendered: resolve the layoutCallback when the first
Expand Down Expand Up @@ -1290,6 +1291,20 @@ export class AmpStory extends AMP.BaseElement {
activePage.next(opt_isAutomaticAdvance);
}

/**
* Installs amp-viewer-integration script in case story is inside an
* amp-story-player.
*/
initializeStoryPlayer_() {
if (this.viewer_.getParam('storyPlayer') !== 'v0') {
return;
}
Services.extensionsFor(this.getAmpDoc().win).installExtensionForDoc(
this.getAmpDoc(),
'amp-viewer-integration'
);
}

/**
* Handles EventType.NO_NEXT_PAGE events.
* @private
Expand Down
9 changes: 3 additions & 6 deletions src/amp-story-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ export class AmpStoryPlayer {
this.initializeLoadingListeners_(iframeEl);
this.rootEl_.appendChild(iframeEl);

// TODO(#26308): enable messaging when multiple documents are supported.
return;

this.initializeHandshake_(story, iframeEl).then(
messaging => {
const iframeIdx = findIndex(
Expand Down Expand Up @@ -206,10 +203,9 @@ export class AmpStoryPlayer {
* @private
*/
layoutIframe_(story, iframe) {
// TODO(#26308): enable messaging when multiple documents are supported.
// const {href} = this.getEncodedLocation_(story.href);
const {href} = this.getEncodedLocation_(story.href);

iframe.setAttribute('src', story.href);
iframe.setAttribute('src', href);
}

/**
Expand All @@ -226,6 +222,7 @@ export class AmpStoryPlayer {
'amp_js_v': '0.1',
'visibilityState': 'inactive',
'origin': url.origin,
'storyPlayer': 'v0',
});

const fragmentParam = getFragment(href);
Expand Down

0 comments on commit 4f26d11

Please sign in to comment.