<commit_before>/*
  Search-functions
*/

//Singleton application instance.
//Put search related methods into
//here (refactor).
app = new function Application() {
  var hymnBook = null
  var curHymnBook = "";
  var resultDivs  = new Array()
  var searchMethods = new Array()
 
  //Adds a search method. Associates the given
  //regular expression with the given HymnBook method. 
  function addSearchMethod(regex, funcname) {
    searchMethods.push({"regex":regex, "func":funcname})
  }

  //Adds a search result to the page 
  function addSearchResult(element)
  {
    resultDivs.push(element)
    
    var test  = element.getElementsByTagName("span");
    
    if (test.length > 0)
      for (var i = 0; i < test.length; i++)
        if (test[i].getAttribute("data-name") == "searchquery")
          test[i].innerHTML = "\"" + document.hymnform.searchquery.value + "\"";
    
    processSearchResults()
  }
  
  //Changes melody
  this.changeMelody = function(id, melody_id) {
    var audio = document.getElementById('audio_'+id)
    if (supports_audio())
    {
        audio.pause()
        var ext = get_audio_extension();
        audio.src= "hymns/" + ext + "/" + melody_id + "." + ext
        audio.load()
    }
    
    // Change download link
    var parent    = audio.parentNode.parentNode;
    var elements  = parent.getElementsByTagName("a");
    var midi_file = melody_id.substring(0, melody_id.indexOf(".")) + ".mid";
    
    for (var i = 0, found = false; i < elements.length && !found; i++)
    {
      if (elements[i].innerHTML === "D")
      {
        elements[i].href = "hymns/midi/" + midi_file;
        
        found = true;
      }
    }
  }
  
  this.clearSearchResults = function()
  {    
    var searchResults = document.getElementById("searchresults");
    if (searchResults)
    {
      var div  = searchResults.getElementsByTagName("div")[0];
      var sibling = div.nextSibling;
      
      while (resultDivs.length > 0)
      {
        this.removeSearchResult(div.id);
        div = sibling;
        
        if (sibling != null)
          sibling = div.nextSibling;
      }
    }<commit_msg>Fixed another midi bug<commit_after>/*
  Search-functions
*/

//Singleton application instance.
//Put search related methods into
//here (refactor).
app = new function Application() {
  var hymnBook = null
  var curHymnBook = "";
  var resultDivs  = new Array()
  var searchMethods = new Array()
 
  //Adds a search method. Associates the given
  //regular expression with the given HymnBook method. 
  function addSearchMethod(regex, funcname) {
    searchMethods.push({"regex":regex, "func":funcname})
  }

  //Adds a search result to the page 
  function addSearchResult(element)
  {
    resultDivs.push(element)
    
    var test  = element.getElementsByTagName("span");
    
    if (test.length > 0)
      for (var i = 0; i < test.length; i++)
        if (test[i].getAttribute("data-name") == "searchquery")
          test[i].innerHTML = "\"" + document.hymnform.searchquery.value + "\"";
    
    processSearchResults()
  }
  
  //Changes melody
  this.changeMelody = function(id, melody_id) {
    var audio = document.getElementById('audio_'+id)
    if (supports_audio())
    {
        audio.pause()
        var ext = get_audio_extension();
        audio.src= "hymns/" + ext + "/" + melody_id + "." + ext
        audio.load()
    }
    
    // Change download link
    var parent    = audio.parentNode.parentNode;
    var elements  = parent.getElementsByTagName("a");
    for (var i = 0, found = false; i < elements.length && !found; i++)
    {
      if (elements[i].innerHTML === "D")
      {
        elements[i].href = "hymns/midi/" + melody_id + ".mid";
        
        found = true;
      }
    }
  }
  
  this.clearSearchResults = function()
  {    
    var searchResults = document.getElementById("searchresults");
    if (searchResults)
    {
      var div  = searchResults.getElementsByTagName("div")[0];
      var sibling = div.nextSibling;
      
      while (resultDivs.length > 0)
      {
        this.removeSearchResult(div.id);
        div = sibling;
        
        if (sibling != null)
          sibling = div.nextSibling;
      }
    }
{'fraction_non_alphanumeric': 0.13282369804108934, 'fraction_numerical': 0.0026278069756330625, 'mean_word_length': 2.3848019401778497, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3567531', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1311, 'n_words': 305}