extensions/amp-story/1.0/amp-story.js
/**
   * Renders the layout for the story.
   * @return {!Promise} A promise that is resolved when the story layout is
   *       loaded
   * @private
   */
Renders the layout for the story.
@return {!Promise} A promise that is resolved when the story layout is
loaded
@private
Renders the layout for the story . @return { !Promise } A promise that is resolved when the story layout is loaded @private
layoutStory_() {
    const initialPageId = this.getInitialPageId_();
    this.buildSystemLayer_(initialPageId);
    this.setThemeColor_();
    const storyLayoutPromise = Promise.all([
      this.getAmpDoc().whenFirstVisible(), 
      this.initializePages_(),
    ])
      .then(() => {
        this.handleConsentExtension_();
        this.initializeStoryAccess_();
        this.pages_.forEach((page, index) => {
          page.setState(PageState.NOT_ACTIVE);
          this.upgradeCtaAnchorTagsForTracking_(page, index);
        });
        this.initializeStoryNavigationPath_();
        if (this.storeService_.get(StateProperty.CAN_SHOW_PAGINATION_BUTTONS)) {
          new PaginationButtons(this);
        }
      })
      .then(() =>
        this.switchTo_(this.getInitialPageId_(), NavigationDirection.NEXT)
      )
      .then(() => {
        const shouldReOpenAttachmentForPageId = getHistoryState(
          this.win,
          HistoryState.ATTACHMENT_PAGE_ID
        );
        if (shouldReOpenAttachmentForPageId === this.activePage_.element.id) {
          this.activePage_.openAttachment(false );
        }
        if (
          shouldShowStoryUrlInfo(devAssert(this.viewer_), this.storeService_)
        ) {
          const infoDialog = new InfoDialog(this.win, this.element);
          infoDialog.build();
        }
      });
    this.whenInitialContentLoaded_(INITIAL_CONTENT_LOAD_TIMEOUT_MS).then(() => {
      this.markStoryAsLoaded_();
      this.initializeLiveStory_();
    });
    this.maybeLoadStoryEducation_();
    const initialPageEl = this.element.querySelector(
      `amp-story-page#${escapeCssSelectorIdent(initialPageId)}`
    );
    if (!this.getAmpDoc().hasBeenVisible()) {
      return whenUpgradedToCustomElement(initialPageEl).then(() => {
        return initialPageEl.build();
      });
    }
    return storyLayoutPromise;
  }
layoutStory_ ( ) { const initialPageId = this . getInitialPageId_ ( ) ; this . buildSystemLayer_ ( initialPageId ) ; this . setThemeColor_ ( ) ; const storyLayoutPromise = Promise . all ( [ this . getAmpDoc ( ) . whenFirstVisible ( ) , this . initializePages_ ( ) , ] ) . then ( ( ) => { this . handleConsentExtension_ ( ) ; this . initializeStoryAccess_ ( ) ; this . pages_ . forEach ( ( page , index ) => { page . setState ( PageState . NOT_ACTIVE ) ; this . upgradeCtaAnchorTagsForTracking_ ( page , index ) ; } ) ; this . initializeStoryNavigationPath_ ( ) ; if ( this . storeService_ . get ( StateProperty . CAN_SHOW_PAGINATION_BUTTONS ) ) { new PaginationButtons ( this ) ; } } ) . then ( ( ) => this . switchTo_ ( this . getInitialPageId_ ( ) , NavigationDirection . NEXT ) ) . then ( ( ) => { const shouldReOpenAttachmentForPageId = getHistoryState ( this . win , HistoryState . ATTACHMENT_PAGE_ID ) ; if ( shouldReOpenAttachmentForPageId === this . activePage_ . element . id ) { this . activePage_ . openAttachment ( false ) ; } if ( shouldShowStoryUrlInfo ( devAssert ( this . viewer_ ) , this . storeService_ ) ) { const infoDialog = new InfoDialog ( this . win , this . element ) ; infoDialog . build ( ) ; } } ) ; this . whenInitialContentLoaded_ ( INITIAL_CONTENT_LOAD_TIMEOUT_MS ) . then ( ( ) => { this . markStoryAsLoaded_ ( ) ; this . initializeLiveStory_ ( ) ; } ) ; this . maybeLoadStoryEducation_ ( ) ; const initialPageEl = this . element . querySelector ( ` ${ escapeCssSelectorIdent ( initialPageId ) } ` ) ; if ( ! this . getAmpDoc ( ) . hasBeenVisible ( ) ) { return whenUpgradedToCustomElement ( initialPageEl ) . then ( ( ) => { return initialPageEl . build ( ) ; } ) ; } return storyLayoutPromise ; }
Renders the layout for the story.
Renders the layout for the story .
// Pauses execution during prerender. // Build pagination buttons if they can be displayed. // We need to call this.getInitialPageId_() again because the initial // page could've changed between the start of layoutStory_ and here. /** shouldAnimate */ // Do not block the layout callback on the completion of these promises, as // that prevents descendents from being laid out (and therefore loaded). // Story is being prerendered: resolve the layoutCallback when the active // page is built. Other pages will only build if the document becomes // visible. // Will resolve when all pages are built.