<commit_before>'use strict';

function Checkbox(l) {
  var labelElement = l;
  var checkboxElement = document.getElementById(
    labelElement.getAttribute('for'));
  checkboxElement.disabled = true;

  // Add additional elements
  var fakeCheckbox = document.createElement('span');
  fakeCheckbox.classList.add('Checkbox');
  fakeCheckbox.tabIndex = 0;
  if (checkboxElement.classList.contains('RippleEffect')) {
    checkboxElement.classList.add('RippleEffect--recentering');
    var rippleContainer = document.createElement('span');
    rippleContainer.classList.add('Checkbox-rippleContainer');
    rippleContainer.classList.add('RippleEffect');
    rippleContainer.classList.add('RippleEffect--recentering');
    var ripple = document.createElement('span');
    ripple.classList.add('Ripple');

    rippleContainer.appendChild(ripple);
    labelElement.insertBefore(rippleContainer,
      labelElement.firstChild);
  }
  labelElement.insertBefore(fakeCheckbox,
     labelElement.firstChild);

  fakeCheckbox.addEventListener('click', function(evt) {
    this.onCheckChange(evt);
  }.bind(this));
  labelElement.addEventListener('click', function(evt) {
    this.onCheckChange(evt);
  }.bind(this));
  fakeCheckbox.addEventListener('keypress', function(evt) {
    console.log('fakeCheckbox keypress');
    this.onKeyEvent(evt);
  }.bind(this));
  labelElement.addEventListener('keypress', function(evt) {
    this.onKeyEvent(evt);
  }.bind(this));

  this.getCheckboxElement = function() {
    return checkboxElement;
  };

  this.getFakeCheckboxElement = function() {
    return fakeCheckbox;
  };

  this.getRippleElement = function() {
    return rippleContainer;
  };
}

Checkbox.prototype.onCheckChange = function(evt) {
  evt.preventDefault();
  evt.stopPropagation();

  var checkboxElement = this.getCheckboxElement();
  var fakeCheckbox = this.getFakeCheckboxElement();
  var rippleContainer = this.getRippleElement();

  checkboxElement.checked = !checkboxElement.checked;
  if (checkboxElement.checked) {
    fakeCheckbox.classList.add('Checkbox-isChecked');
    rippleContainer.classList.add('Checkbox-isChecked');
  } else {
    fakeCheckbox.classList.remove('Checkbox-isChecked');
    rippleContainer.classList.remove('Checkbox-isChecked');
  }
};

Checkbox.prototype.onKeyEvent = function(evt) {
  var SPACE_KEY = 32;

  if (evt.keyCode === SPACE_KEY) {
    evt.stopPropagation();
    this.onCheckChange(evt);
  }
};

window.addEventListener('load', function() {
  var labels =  document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    new Checkbox(labels[i]);
  }
});<commit_msg>Bugfix to checkbox init.<commit_after>'use strict';

function Checkbox(l) {
  var labelElement = l;
  var checkboxElement = document.getElementById(
    labelElement.getAttribute('for'));
  checkboxElement.disabled = true;

  // Add additional elements
  var fakeCheckbox = document.createElement('span');
  fakeCheckbox.classList.add('Checkbox');
  fakeCheckbox.tabIndex = 0;
  if (checkboxElement.classList.contains('RippleEffect')) {
    checkboxElement.classList.add('RippleEffect--recentering');
    var rippleContainer = document.createElement('span');
    rippleContainer.classList.add('Checkbox-rippleContainer');
    rippleContainer.classList.add('RippleEffect');
    rippleContainer.classList.add('RippleEffect--recentering');
    var ripple = document.createElement('span');
    ripple.classList.add('Ripple');

    rippleContainer.appendChild(ripple);
    labelElement.insertBefore(rippleContainer,
      labelElement.firstChild);
  }
  labelElement.insertBefore(fakeCheckbox,
     labelElement.firstChild);

  fakeCheckbox.addEventListener('click', function(evt) {
    this.onCheckChange(evt);
  }.bind(this));
  labelElement.addEventListener('click', function(evt) {
    this.onCheckChange(evt);
  }.bind(this));
  fakeCheckbox.addEventListener('keypress', function(evt) {
    console.log('fakeCheckbox keypress');
    this.onKeyEvent(evt);
  }.bind(this));
  labelElement.addEventListener('keypress', function(evt) {
    this.onKeyEvent(evt);
  }.bind(this));

  this.getCheckboxElement = function() {
    return checkboxElement;
  };

  this.getFakeCheckboxElement = function() {
    return fakeCheckbox;
  };

  this.getRippleElement = function() {
    return rippleContainer;
  };
}

Checkbox.prototype.onCheckChange = function(evt) {
  evt.preventDefault();
  evt.stopPropagation();

  var checkboxElement = this.getCheckboxElement();
  var fakeCheckbox = this.getFakeCheckboxElement();
  var rippleContainer = this.getRippleElement();

  checkboxElement.checked = !checkboxElement.checked;
  if (checkboxElement.checked) {
    fakeCheckbox.classList.add('Checkbox-isChecked');
    rippleContainer.classList.add('Checkbox-isChecked');
  } else {
    fakeCheckbox.classList.remove('Checkbox-isChecked');
    rippleContainer.classList.remove('Checkbox-isChecked');
  }
};

Checkbox.prototype.onKeyEvent = function(evt) {
  var SPACE_KEY = 32;

  if (evt.keyCode === SPACE_KEY) {
    evt.stopPropagation();
    this.onCheckChange(evt);
  }
};

window.addEventListener('load', function() {
  var labels =  document.querySelectorAll('.Checkbox-label');
  for (var i = 0; i < labels.length; i++) {
    new Checkbox(labels[i]);
  }
});
{'fraction_non_alphanumeric': 0.13738866780367634, 'fraction_numerical': 0.0015160128861095318, 'mean_word_length': 4.857935627081021, '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': '4720657', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1607, 'n_words': 235}