Skip to content

Commit

Permalink
Build only first time lightbox is opened (ampproject#5941)
Browse files Browse the repository at this point in the history
Build only first time lightbox is opened.
  • Loading branch information
chenshay authored and Vanessa Pasque committed Dec 22, 2016
1 parent ac1dfa6 commit a85e662
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions extensions/amp-lightbox/0.1/amp-lightbox.js
Expand Up @@ -47,8 +47,15 @@ class AmpLightbox extends AMP.BaseElement {
return layout == Layout.NODISPLAY;
}

/** @override */
buildCallback() {
/**
* Lazily builds the lightbox DOM on the first open.
* @private
*/
initialize_() {
if (this.container_) {
return;
}

st.setStyles(this.element, {
position: 'fixed',
zIndex: 1000,
Expand Down Expand Up @@ -86,6 +93,7 @@ class AmpLightbox extends AMP.BaseElement {
if (this.active_) {
return;
}
this.initialize_();
this.boundCloseOnEscape_ = this.closeOnEscape_.bind(this);
this.win.document.documentElement.addEventListener(
'keydown', this.boundCloseOnEscape_);
Expand Down

0 comments on commit a85e662

Please sign in to comment.