<commit_before>(function () {
  'use strict';

  moj.Modules.ConditionalSubfields = {
    el: '[data-controlled-by]',

    init: function() {
      this.cacheEls();
      this.bindEvents();
      this.setInitialState();
      this.replaceLabels();
    },

    setInitialState: function() {
      var self = this;

      this.conditionalFields
        .each(function() {
          var $fields = $('[name="' + $(this).data('controlled-by') + '"]');

          $fields = $fields.filter(function() {
            // Unchecked checkbox or checked radio button
            return this.type === 'checkbox' || $(this).is(':checked');
          });

          $fields.each($.proxy(self.handleVisibility, self));
        });
    },

    replaceLabels: function() {
      if(!window.CONDITIONAL_LABELS) {
        return;
      }

      $.each(window.CONDITIONAL_LABELS, function(key, value) {
        $('#field-' + key + '')<commit_msg>Add comment explaining JS conditional subfield usage<commit_after>(function () {
  'use strict';

  moj.Modules.ConditionalSubfields = {
    el: '[data-controlled-by]',

    init: function() {
      this.cacheEls();
      this.bindEvents();
      this.setInitialState();
      this.replaceLabels();
    },

    setInitialState: function() {
      var self = this;

      this.conditionalFields
        .each(function() {
          var $fields = $('[name="' + $(this).data('controlled-by') + '"]');

          $fields = $fields.filter(function() {
            // Unchecked checkbox or checked radio button
            return this.type === 'checkbox' || $(this).is(':checked');
          });

          $fields.each($.proxy(self.handleVisibility, self));
        });
    },

    // If CONDITIONAL_LABELS constant exists its contents will be used to
    // replace fields on page load.

    // e.g. If non-JS page has a label "If Yes, how many?" (referring to previous field)
    // Adding `CONDITIONAL_LABELS['applicant_name'] = 'Your name'` would change label to 'Your name'
    // when JS kicks in.
    replaceLabels: function() {
      if(!window.CONDITIONAL_LABELS) {
        return;
      }

      $.each(window.CONDITIONAL_LABELS, function(key, value) {
        $('#field-' + key + '')
{'fraction_non_alphanumeric': 0.15906009941256213, 'fraction_numerical': 0.0, 'mean_word_length': 2.359635811836115, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6614711', 'n_tokens_mistral': 663, 'n_tokens_neox': 637, 'n_words': 142}