<commit_before>$(".document-input").change(documentsChanged);
$("#post_title_en").change(updateFileUrls);
$("#page_title").change(updateFileUrls);
function convertToSlug(Text)
{
    return Text
        .toLowerCase()
        .replace(/[^\w ]+/g,'')
        .replace(/ +/g,'-')
        ;
}
function documentsChanged(){
  updateFileUrls();
}
function updateFileUrls(){
  var div = document.getElementById("documents_container");
  var elements = div.getElementsByTagName("input");
  var fileList = []
  for (var i = 0; i < elements.length; i += 1) {
    for (var j = 0; j < elements[i].files.length; j += 1) {
      fileList.push(elements[i].files[j]);
    }
  }

  var ul = document.getElementById("list-document-urls");
  var trans = I18n.t("activerecord.attributes.post.title");
  $('.document-url').remove()
  if(document.getElementById("post_title_en") != null){
    var slug = convertToSlug(document.getElementById("post_title_en").value);
    var model = "post";
  }else if (document.getElementById("page_title") != null) {
    var slug = convertToSlug(document.getElementById("page_title").value);
    var model = "page";
  }
  for(var i=0,file;file=fileList[i];i++) {
      var li = document.createElement("li");
      var outString = "["+trans+"](http://"+window.location.host+"/uploads/"+model+"/documents/"+ slug +"/"+file.name+")";
      li.appendChild(document.createTextNode(outString));
      li.className += "document-url";
      ul.appendChild(li);
  }
}
function addFileInput(){
  element = `
  <div class="documents-input-container">
    <input type="file" name="document[]" class="document-input" multiple="multiple"/>
    <ul class="button-group even-2">
      <li><button type="button" class="rem-file-button tiny"onclick="removeFile(this);"><i class="fa fa-minus-circle" aria-hidden="true"></i></button></li>
      <li><button type="button" class="ui-button tiny add-file-button" onclick="addFileInput();"><i class="fa fa-plus-circle" aria-hidden="true"></i></button></li>
    </ul>
  </div>
  `;
  $("#documents_container").append(element);
  $(".document-input").change(documentsChanged);
}
function removeFile(element){
  $(element).parent().parent().parent().remove();
  updateFileUrls();
}
<commit_msg>fixed issue where titles weren't generated sometimes<commit_after>$(".document-input").change(documentsChanged);
$("#post_title_en").change(updateFileUrls);
$("#page_title").change(updateFileUrls);
function convertToSlug(Text)
{
    return Text
        .toLowerCase()
        .replace(/[^\w ]+/g,'')
        .replace(/ +/g,'-')
        ;
}
function documentsChanged(){
  updateFileUrls();
}
function updateFileUrls(){
  var div = document.getElementById("documents_container");
  var elements = div.getElementsByTagName("input");
  var fileList = []
  for (var i = 0; i < elements.length; i += 1) {
    for (var j = 0; j < elements[i].files.length; j += 1) {
      fileList.push(elements[i].files[j]);
    }
  }

  var ul = document.getElementById("list-document-urls");
  try {
    var trans = I18n.t("activerecord.attributes.post.title");
  } catch (e){
    var trans = "Title";
  }
  $('.document-url').remove()
  if(document.getElementById("post_title_en") != null){
    var slug = convertToSlug(document.getElementById("post_title_en").value);
    var model = "post";
  }else if (document.getElementById("page_title") != null) {
    var slug = convertToSlug(document.getElementById("page_title").value);
    var model = "page";
  }
  for(var i=0,file;file=fileList[i];i++) {
      var li = document.createElement("li");
      var outString = "["+trans+"](http://"+window.location.host+"/uploads/"+model+"/documents/"+ slug +"/"+file.name+")";
      li.appendChild(document.createTextNode(outString));
      li.className += "document-url";
      ul.appendChild(li);
  }
}
function addFileInput(){
  element = `
  <div class="documents-input-container">
    <input type="file" name="document[]" class="document-input" multiple="multiple"/>
    <ul class="button-group even-2">
      <li><button type="button" class="rem-file-button tiny"onclick="removeFile(this);"><i class="fa fa-minus-circle" aria-hidden="true"></i></button></li>
      <li><button type="button" class="ui-button tiny add-file-button" onclick="addFileInput();"><i class="fa fa-plus-circle" aria-hidden="true"></i></button></li>
    </ul>
  </div>
  `;
  $("#documents_container").append(element);
  $(".document-input").change(documentsChanged);
}
function removeFile(element){
  $(element).parent().parent().parent().remove();
  updateFileUrls();
}

{'fraction_non_alphanumeric': 0.2001757855416392, 'fraction_numerical': 0.0035157108327840037, 'mean_word_length': 4.38698224852071, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, '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': '1668480', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1439, 'n_words': 248}