Skip to content

Commit

Permalink
Wait for ampdoc to fully load before creating default element. (#19778)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepand Parhami committed Dec 11, 2018
1 parent 0ccf9ca commit 132b26e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions extensions/amp-lightbox-gallery/0.1/amp-lightbox-gallery.js
Expand Up @@ -1446,15 +1446,19 @@ export class AmpLightboxGallery extends AMP.BaseElement {
* @return {!Promise<undefined>}
*/
export function installLightboxGallery(ampdoc) {
return ampdoc.whenBodyAvailable().then(body => {
const existingGallery = elementByTag(ampdoc.getRootNode(), TAG);
if (!existingGallery) {
const gallery = ampdoc.win.document.createElement(TAG);
gallery.setAttribute('layout', 'nodisplay');
gallery.setAttribute('id', DEFAULT_GALLERY_ID);
body.appendChild(gallery);
}
});
// Make sure to wait for the ampdoc to finish loading, see:
// https://github.com/ampproject/amphtml/issues/19728#issuecomment-446033966
return ampdoc.whenReady()
.then(() => ampdoc.getBody())
.then(body => {
const existingGallery = elementByTag(ampdoc.getRootNode(), TAG);
if (!existingGallery) {
const gallery = ampdoc.win.document.createElement(TAG);
gallery.setAttribute('layout', 'nodisplay');
gallery.setAttribute('id', DEFAULT_GALLERY_ID);
body.appendChild(gallery);
}
});
}

/**
Expand Down

0 comments on commit 132b26e

Please sign in to comment.