<commit_before>/** @jsx React.DOM */
(function() {
  var widgetClass = 'acusti-run-webpagetest-widget',
      WPTForm,
      WPTField,
      WPTCloseButton,
      removeWidget,
      fieldsData,
      fontFamily,
      colors,
      styles,
      container;

  // If widget already exists on the page, do nothing
  if (document.getElementsByClassName(widgetClass).length) {
      return;
  }

  // React components
  // ----------------
  WPTForm = React.createClass({
    // Default options
    fieldsDefaults: [
      {
        key: 'k',
        label: 'API Key',
        value: '',
        isRequired: true
      },
      {
        key: 'location',
        label: 'Location + browser',
        value: 'Dulles_MotoE',
        isRequired: true
      },
      {
        key: 'runs',
        label: 'Number of runs',
        value: 1,
        isRequired: true
      },
      {
        key: 'fvonly',
        label: 'First and repeat view?',
        type: 'radio',
        value: 0,
        options: [
          {
            value: 0,
            label: 'Yes'
          },
          {
            value: 1,
            label: 'No'
          }
        ],
      },
      {
        key: 'video',
        label: 'Video',
        value: 1
      },
      {
        key: 'url',
        label: 'URL to test',
        value: '',
        isRequired: true
      },
      {
        key: 'label',
        label: 'Label',
        value: '',
      }
    ],

    getInitialState: function() {
      var fieldsInitial = this.fieldsDefaults,
          i;

      // Initialize any options not stored in localStorage based on model
      for (i = 0; i < fieldsInitial.length; i++) {
        fieldsInitial[i].value = fieldsData.get(fieldsInitial[i].key) || fieldsInitial[i].value;
      }

      return {
        fields: fieldsInitial
      };
    },

    render: function() {
      var fieldNodes = this.state.fields.map(function(field) {
        return (
          <WPTField key={field.key} id={field.key} label={field.label} value={field.value} type={field.type} options={field.options} required={field.isRequired} />
        );
      });
      return (
        <form style={styles.form} onSubmit={this.handleSubmit} onChange={this.handleChange}>
          <WPTCloseButton />
          <h2 style={styles.h2}>
            Run WebPageTest for this page
          </h2>
          {fieldNodes}
          <button type="submit" style={styles.button}>Test it</button>
        </form>
      );
    },

    handleChange: function(evt) {
      fieldsData.set(event.target.name, event.target.value);
    },

    handleSubmit: function(evt) {
      var url_base = 'http://www.webpagetest.org/runtest.php?',
          query    = '',
          i;

      evt.preventDefault();

      for (i = 0; i < this.state.fields.length; i++) {
        query += '&' + this.state.fields[i].key + '=' + encodeURIComponent(this.state.fields[i].value);
      }
      window.open(url_base + query.substr(1));
      removeWidget();
    }
  });

  WPTField = React.createClass({
    getInitialState: function() {
      return {
        value: this.props.value
      };
    },
    handleChange: function(event) {
      this.setState({
        value: event.target.value
      });
    },
    render: function() {
      var type       = this.props.type || 'text',
          isRequired = !!this.props.isRequired,
          id         = this.props.id,
          name       = id,
          options    = this.props.options || [{
            value: this.state.value,
            label: this.props.label
          }],
          isRadio    = type === 'radio' && options.length > 1,
          optionNodes;

      optionNodes = options.map(function(option) {
        if (isRadio) {
          id = this.props.id + '[' + option.value + ']';
        }
        // Use defaultValue and defaultChecked for uncontrolled input components
        return (
          <label style={styles.label}>
            {!isRadio ? option.label : ''}
            <input type={type} onChange={this.handleChange} style={styles.input[type]} id={id} name={name} defaultValue={option.value} required={isRequired} defaultChecked={isRadio && parseInt(this.state.value, 10) === parseInt(option.value, 10)} />
            {isRadio ? option.label : ''}
          </label>
        );<commit_msg>Add React key to labels<commit_after>/** @jsx React.DOM */
(function() {
  var widgetClass = 'acusti-run-webpagetest-widget',
      WPTForm,
      WPTField,
      WPTCloseButton,
      removeWidget,
      fieldsData,
      fontFamily,
      colors,
      styles,
      container;

  // If widget already exists on the page, do nothing
  if (document.getElementsByClassName(widgetClass).length) {
      return;
  }

  // React components
  // ----------------
  WPTForm = React.createClass({
    // Default options
    fieldsDefaults: [
      {
        key: 'k',
        label: 'API Key',
        value: '',
        isRequired: true
      },
      {
        key: 'location',
        label: 'Location + browser',
        value: 'Dulles_MotoE',
        isRequired: true
      },
      {
        key: 'runs',
        label: 'Number of runs',
        value: 1,
        isRequired: true
      },
      {
        key: 'fvonly',
        label: 'First and repeat view?',
        type: 'radio',
        value: 0,
        options: [
          {
            value: 0,
            label: 'Yes'
          },
          {
            value: 1,
            label: 'No'
          }
        ],
      },
      {
        key: 'video',
        label: 'Video',
        value: 1
      },
      {
        key: 'url',
        label: 'URL to test',
        value: '',
        isRequired: true
      },
      {
        key: 'label',
        label: 'Label',
        value: '',
      }
    ],

    getInitialState: function() {
      var fieldsInitial = this.fieldsDefaults,
          i;

      // Initialize any options not stored in localStorage based on model
      for (i = 0; i < fieldsInitial.length; i++) {
        fieldsInitial[i].value = fieldsData.get(fieldsInitial[i].key) || fieldsInitial[i].value;
      }

      return {
        fields: fieldsInitial
      };
    },

    render: function() {
      var fieldNodes = this.state.fields.map(function(field) {
        return (
          <WPTField key={field.key} id={field.key} label={field.label} value={field.value} type={field.type} options={field.options} required={field.isRequired} />
        );
      });
      return (
        <form style={styles.form} onSubmit={this.handleSubmit} onChange={this.handleChange}>
          <WPTCloseButton />
          <h2 style={styles.h2}>
            Run WebPageTest for this page
          </h2>
          {fieldNodes}
          <button type="submit" style={styles.button}>Test it</button>
        </form>
      );
    },

    handleChange: function(evt) {
      fieldsData.set(event.target.name, event.target.value);
    },

    handleSubmit: function(evt) {
      var url_base = 'http://www.webpagetest.org/runtest.php?',
          query    = '',
          i;

      evt.preventDefault();

      for (i = 0; i < this.state.fields.length; i++) {
        query += '&' + this.state.fields[i].key + '=' + encodeURIComponent(this.state.fields[i].value);
      }
      window.open(url_base + query.substr(1));
      removeWidget();
    }
  });

  WPTField = React.createClass({
    getInitialState: function() {
      return {
        value: this.props.value
      };
    },
    handleChange: function(event) {
      this.setState({
        value: event.target.value
      });
    },
    render: function() {
      var type       = this.props.type || 'text',
          isRequired = !!this.props.isRequired,
          id         = this.props.id,
          name       = id,
          options    = this.props.options || [{
            value: this.state.value,
            label: this.props.label
          }],
          isRadio    = type === 'radio' && options.length > 1,
          optionNodes;

      optionNodes = options.map(function(option) {
        if (isRadio) {
          id = this.props.id + '[' + option.value + ']';
        }
        // Use defaultValue and defaultChecked for uncontrolled input components
        return (
          <label style={styles.label} key={id}>
            {!isRadio ? option.label : ''}
            <input type={type} onChange={this.handleChange} style={styles.input[type]} id={id} name={name} defaultValue={option.value} required={isRequired} defaultChecked={isRadio && parseInt(this.state.value, 10) === parseInt(option.value, 10)} />
            {isRadio ? option.label : ''}
          </label>
        );
{'fraction_non_alphanumeric': 0.1427244222506097, 'fraction_numerical': 0.003716176982928812, 'mean_word_length': 1.6979949874686717, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4988698', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2526, 'n_words': 525}