Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions extensions/amp-story-shopping/0.1/amp-story-shopping-attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ export class AmpStoryShoppingAttachment extends AMP.BaseElement {
/** @private {?Element} */
this.attachmentEl_ = null;

/** @private {!Element} */
this.pageEl_ = this.element.closest('amp-story-page');
/** @private {?Element} */
this.pageEl_ = null;

/** @private {!Array<!Element>} */
this.shoppingTags_ = Array.from(
this.pageEl_.querySelectorAll('amp-story-shopping-tag')
);
/** @private {?Array<!Element>} */
this.shoppingTags_ = null;

/** @private @const {!Element} */
this.plpContainer_ = <div></div>;
Expand All @@ -53,6 +51,13 @@ export class AmpStoryShoppingAttachment extends AMP.BaseElement {

/** @override */
buildCallback() {
this.pageEl_ = this.element.closest('amp-story-page');
this.shoppingTags_ = Array.from(
this.pageEl_.querySelectorAll('amp-story-shopping-tag')
);
if (this.shoppingTags_.length === 0) {
Comment thread
processprocess marked this conversation as resolved.
return;
}
loadFonts(this.win, FONTS_TO_LOAD);
this.attachmentEl_ = (
<amp-story-page-attachment
Expand All @@ -74,6 +79,9 @@ export class AmpStoryShoppingAttachment extends AMP.BaseElement {

/** @override */
layoutCallback() {
if (this.shoppingTags_.length === 0) {
return;
}
this.storeService_.subscribe(
StateProperty.PAGE_ATTACHMENT_STATE,
(isOpen) => this.onPageAttachmentStateUpdate_(isOpen)
Expand Down
16 changes: 5 additions & 11 deletions extensions/amp-story/1.0/amp-story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export class AmpStoryPage extends AMP.BaseElement {

this.muteAllMedia();

this.renderOpenAttachmentUI_();
this.installPageAttachmentExtension_();

return Promise.all([
this.waitForMediaLayout_().then(() => this.markPageAsLoaded_()),
Expand Down Expand Up @@ -1523,21 +1523,15 @@ export class AmpStoryPage extends AMP.BaseElement {
}

/**
* Renders the open attachment UI affordance.
* Installs the page attachment extension.
* @private
*/
renderOpenAttachmentUI_() {
// AttachmentEl can be any component that extends draggable drawer.
const attachmentEl = this.element.querySelector(
installPageAttachmentExtension_() {
const elementsThatRequireExtension = this.element.querySelector(
'amp-story-page-attachment, amp-story-page-outlink, amp-story-shopping-attachment'
);

if (
!attachmentEl ||
(attachmentEl.tagName === 'AMP-STORY-SHOPPING-ATTACHMENT' &&
this.element.getElementsByTagName('amp-story-shopping-tag').length ===
0)
) {
if (!elementsThatRequireExtension) {
return;
}

Expand Down