<commit_before> (function($, window) {

  var domReady = function() {
    var $title = $('#title')
      , $type = $('#job_type')
      , $locationId = $('#location__id')
      , $city = $('#location__city')
      , $country = $('#location__country_code')
      , $remote = $('#remote_work')
      , $contact = $('#contact_method')
      , $contactUrl = $('#contact_url')
      , $contactEmail = $('#contact_email')
      , $companyName = $('#company__name')
      , $companyWebsite = $('#company__website')
      , $recruiterName = $('#recruiter_name')
      , $recruiterEmail = $('#recruiter_email')
      , $tags = $('#tags');

    /*
     * HELPERS
     * -------
     */
    var findLocation = function(cityName) {
      var len = LOCATIONS.length
        , i, location;

      for (i = 0; i < len; i++) {
        location = LOCATIONS[i];
        if (location.city == cityName) return location;
      }
    };

    var updateCities = function(countryCode) {
      var selectize = $city.selectize()[0].selectize
        , existingCity = $city.val();

      selectize.clearOptions();

      $.each(LOCATIONS, function(index, location) {
        if (location.country_code !== countryCode) return;
        selectize.addOption(location);
      });

      selectize.refreshOptions(false);

      // If $city already has a *correct* value set (i.e we're in edit mode)
      // we restore it.
      var location = findLocation(existingCity);
      if (location != null && location.country_code === countryCode) {
        selectize.setValue(existingCity);
      }
    };

    var onLocationChange = function(cityName) {
      var location = findLocation(cityName);
      $locationId.val(location != null ? location.id : null);
      return location;
    };

    /*
     * JQUERY-PLACEHOLDER
     * ------------------
     */
    var placeholders = [
      $title,
      $companyName,
      $companyWebsite,
      $recruiterName,
      $recruiterEmail,
      $contactUrl,
      $contactEmail
    ];

    $.each(placeholders, function(i, $el) {
      $el.placeholder();
    });

    /*
     * SELECTIZE
     * ---------
     */
    $type.selectize();
    $remote.selectize();

    $city.selectize({
      maxItems: 1,
      valueField: 'city',
      labelField: 'city',
      searchField: ['city'],
      openOnFocus: true,
      create: true,
      onChange: function(value) {
        this.$input.attr('value', value);
        onLocationChange(value);
      }
    });

    $country.selectize({
      onInitialize: function(a) {
        updateCities(this.getValue());
      },
      onChange: function(value) {
        updateCities(value);
        onLocationChange();
      }
    });

    $contact.selectize({
      onInitialize: function(a) {
        if ($contactEmail.val()) {
          $contactUrl.toggle();
          $contactEmail.toggle();
        }
      },
      onChange: function(value) {
        $contactUrl.toggle();
        $contactEmail.toggle();<commit_msg>Auto-select first city for selected country<commit_after> (function($, window) {

  var domReady = function() {
    var $title = $('#title')
      , $type = $('#job_type')
      , $locationId = $('#location__id')
      , $city = $('#location__city')
      , $country = $('#location__country_code')
      , $remote = $('#remote_work')
      , $contact = $('#contact_method')
      , $contactUrl = $('#contact_url')
      , $contactEmail = $('#contact_email')
      , $companyName = $('#company__name')
      , $companyWebsite = $('#company__website')
      , $recruiterName = $('#recruiter_name')
      , $recruiterEmail = $('#recruiter_email')
      , $tags = $('#tags');

    /*
     * HELPERS
     * -------
     */
    var findLocation = function(cityName) {
      var len = LOCATIONS.length
        , i, location;

      for (i = 0; i < len; i++) {
        location = LOCATIONS[i];
        if (location.city == cityName) return location;
      }
    };

    var updateCities = function(countryCode) {
      var selectize = $city.selectize()[0].selectize
        , existingCity = $city.val()
        , replCandidates = [];

      selectize.clearOptions();

      $.each(LOCATIONS, function(index, location) {
        if (location.country_code !== countryCode) return;
        selectize.addOption(location);
        replCandidates.push(location)
      });

      selectize.refreshOptions(false);

      // If $city already has a *correct* value set (i.e we're in edit mode)
      // we restore it, otherwise we set it to the first value in the
      // replacement candidate array.
      var location = findLocation(existingCity);
      if (location == null || location.country_code != countryCode) {
        existingCity = (replCandidates[0] || {}).city;
      }

      selectize.setValue(existingCity);
    };

    var onLocationChange = function(cityName) {
      var location = findLocation(cityName);
      $locationId.val(location != null ? location.id : null);
      return location;
    };

    /*
     * JQUERY-PLACEHOLDER
     * ------------------
     */
    var placeholders = [
      $title,
      $companyName,
      $companyWebsite,
      $recruiterName,
      $recruiterEmail,
      $contactUrl,
      $contactEmail
    ];

    $.each(placeholders, function(i, $el) {
      $el.placeholder();
    });

    /*
     * SELECTIZE
     * ---------
     */
    $type.selectize();
    $remote.selectize();

    $city.selectize({
      maxItems: 1,
      valueField: 'city',
      labelField: 'city',
      searchField: ['city'],
      create: true,
      onChange: function(value) {
        this.$input.attr('value', value);
        onLocationChange(value);
      }
    });

    $country.selectize({
      onInitialize: function(a) {
        updateCities(this.getValue());
      },
      onChange: function(value) {
        updateCities(value);
        onLocationChange();
      }
    });

    $contact.selectize({
      onInitialize: function(a) {
        if ($contactEmail.val()) {
          $contactUrl.toggle();
          $contactEmail.toggle();
        }
      },
      onChange: function(value) {
        $contactUrl.toggle();
        $contactEmail.toggle();
{'fraction_non_alphanumeric': 0.16172638436482084, 'fraction_numerical': 0.0011400651465798045, 'mean_word_length': 2.155704008221994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2849404', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1789, 'n_words': 352}