extensions/amp-story-interactive/0.1/amp-story-interactive-abstract.js
/**
   * Reads the element attributes prefixed with option- and returns them as a list.
   * eg: [
   *      {optionIndex: 0, text: 'Koala'},
   *      {optionIndex: 1, text: 'Developers', correct: ''}
   *    ]
   * @protected
   * @return {?Array<!OptionConfigType>}
   */
Reads the element attributes prefixed with option- and returns them as a list.
Reads the element attributes prefixed with option - and returns them as a list .
parseOptions_() {
    const options = [];
    toArray(this.element.attributes).forEach((attr) => {
      if (attr.name.match(/^option-\d+(-\w+)+$/)) {
        const splitParts = attr.name.split('-');
        const optionNumber = parseInt(splitParts[1], 10);
        while (options.length < optionNumber) {
          options.push({'optionIndex': options.length});
        }
        const key = splitParts.slice(2).join('');
        if (key === 'image') {
          options[optionNumber - 1][key] = maybeMakeProxyUrl(
            attr.value,
            this.getAmpDoc()
          );
        } else {
          options[optionNumber - 1][key] = attr.value;
        }
      }
    });
    if (
      options.length >= this.optionBounds_[0] &&
      options.length <= this.optionBounds_[1]
    ) {
      return options;
    }
    devAssert(
      options.length >= this.optionBounds_[0] &&
        options.length <= this.optionBounds_[1],
      `Improper number of options. Expected ${this.optionBounds_[0]} <= options <= ${this.optionBounds_[1]} but got ${options.length}.`
    );
    dev().error(
      TAG,
      `Improper number of options. Expected ${this.optionBounds_[0]} <= options <= ${this.optionBounds_[1]} but got ${options.length}.`
    );
  }
parseOptions_ ( ) { const options = [ ] ; toArray ( this . element . attributes ) . forEach ( ( attr ) => { if ( attr . name . match ( / ^option-\d+(-\w+)+$ / ) ) { const splitParts = attr . name . split ( '-' ) ; const optionNumber = parseInt ( splitParts [ 1 ] , 10 ) ; while ( options . length < optionNumber ) { options . push ( { 'optionIndex' : options . length } ) ; } const key = splitParts . slice ( 2 ) . join ( '' ) ; if ( key === 'image' ) { options [ optionNumber - 1 ] [ key ] = maybeMakeProxyUrl ( attr . value , this . getAmpDoc ( ) ) ; } else { options [ optionNumber - 1 ] [ key ] = attr . value ; } } } ) ; if ( options . length >= this . optionBounds_ [ 0 ] && options . length <= this . optionBounds_ [ 1 ] ) { return options ; } devAssert ( options . length >= this . optionBounds_ [ 0 ] && options . length <= this . optionBounds_ [ 1 ] , ` ${ this . optionBounds_ [ 0 ] } ${ this . optionBounds_ [ 1 ] } ${ options . length } ` ) ; dev ( ) . error ( TAG , ` ${ this . optionBounds_ [ 0 ] } ${ this . optionBounds_ [ 1 ] } ${ options . length } ` ) ; }
Reads the element attributes prefixed with option- and returns them as a list.
Reads the element attributes prefixed with option - and returns them as a list .
// Match 'option-#-type' (eg: option-1-text, option-2-image, option-3-correct...) // Add all options in order on the array with correct index.