builtins/amp-img.js
/**
   * Create the actual image element and set up instance variables.
   * Called lazily in the first `#layoutCallback`.
   */
Create the actual image element and set up instance variables.
Called lazily in the first `#layoutCallback`.
Create the actual image element and set up instance variables . Called lazily in the first ` #layoutCallback ` .
initialize_() {
    if (this.img_) {
      return;
    }
    if (!this.srcset_) {
      this.srcset_ = srcsetFromElement(this.element);
    }
    this.allowImgLoadFallback_ = true;
    if (this.element.hasAttribute('fallback')) {
      this.allowImgLoadFallback_ = false;
    }
    this.img_ = new Image();
    if (this.element.id) {
      this.img_.setAttribute('amp-img-id', this.element.id);
    }
    if (this.element.getAttribute('role') == 'img') {
      this.element.removeAttribute('role');
      this.user().error(
          'AMP-IMG', 'Setting role=img on amp-img elements breaks ' +
        'screen readers please just set alt or ARIA attributes, they will ' +
        'be correctly propagated for the underlying <img> element.');
    }
    this.propagateAttributes(ATTRIBUTES_TO_PROPAGATE, this.img_);
    this.applyFillContent(this.img_, true);
    this.element.appendChild(this.img_);
  }
initialize_ ( ) { if ( this . img_ ) { return ; } if ( ! this . srcset_ ) { this . srcset_ = srcsetFromElement ( this . element ) ; } this . allowImgLoadFallback_ = true ; if ( this . element . hasAttribute ( 'fallback' ) ) { this . allowImgLoadFallback_ = false ; } this . img_ = new Image ( ) ; if ( this . element . id ) { this . img_ . setAttribute ( 'amp-img-id' , this . element . id ) ; } if ( this . element . getAttribute ( 'role' ) == 'img' ) { this . element . removeAttribute ( 'role' ) ; this . user ( ) . error ( 'AMP-IMG' , 'Setting role=img on amp-img elements breaks ' + 'screen readers please just set alt or ARIA attributes, they will ' + 'be correctly propagated for the underlying <img> element.' ) ; } this . propagateAttributes ( ATTRIBUTES_TO_PROPAGATE , this . img_ ) ; this . applyFillContent ( this . img_ , true ) ; this . element . appendChild ( this . img_ ) ; }
Create the actual image element and set up instance variables.
Create the actual image element and set up instance variables .
// If this amp-img IS the fallback then don't allow it to have its own // fallback to stop from nested fallback abuse. // Remove role=img otherwise this breaks screen-readers focus and // only read "Graphic" when using only 'alt'.