diff --git a/extensions/amp-story/0.1/amp-story.js b/extensions/amp-story/0.1/amp-story.js index a8da5791c3cfb..a4ff1aa3a70d5 100644 --- a/extensions/amp-story/0.1/amp-story.js +++ b/extensions/amp-story/0.1/amp-story.js @@ -171,9 +171,6 @@ export class AmpStory extends AMP.BaseElement { this.lockBody_(); } - this.element.appendChild( - this.systemLayer_.build(this.getRealChildren().length)); - this.initializeListeners_(); this.initializeListenersForDev_(); @@ -193,6 +190,16 @@ export class AmpStory extends AMP.BaseElement { } + /** + * Builds the system layer DOM. This is dependent on the pages_ array having + * been initialized, so it cannot happen at build time. + * @private + */ + buildSystemLayer_() { + this.element.appendChild(this.systemLayer_.build(this.getPageCount())); + } + + /** @private */ initializeListeners_() { this.element.addEventListener(EventType.EXIT_FULLSCREEN, () => { @@ -350,6 +357,7 @@ export class AmpStory extends AMP.BaseElement { 'Story must have at least one page.'); return this.initializePages_() + .then(() => this.buildSystemLayer_()) .then(() => { this.pages_.forEach(page => { page.setActive(false);