<commit_before>(function($) {


  var browse_data = function(element) {
    var data = $(element).data("facet_browse");

    if (data === undefined) {
      data = $(element).data("facet_browse", {})
    }

    return data;
  }


  //debounce taken from underscore library. 
  var debounce = function(func, wait, immediate) {
    var timeout, args, context, timestamp, result;
    return function() {
      context = this;
      args = arguments;
      timestamp = new Date();
      var later = function() {
        var last = (new Date()) - timestamp;
        if (last < wait) {
          timeout = setTimeout(later, wait - last);
        } else {
          timeout = null;
          if (!immediate) result = func.apply(context, args);
        }
      };
      var callNow = immediate && !timeout;
      if (!timeout) {
        timeout = setTimeout(later, wait);
      }
      if (callNow) result = func.apply(context, args);
      return result;
    };
  };
  
  var update = function(text_field) {
    var dom_data = browse_data(text_field);
    if (dom_data.updates_in_progress === undefined)
      dom_data.updates_in_progress = 0;


    var form     = $(text_field).closest("form");
    var uri      = form.attr("action");
    var q        = form.serialize();

    var ajax_uri = form.data("ajax-url");
    if (ajax_uri === "disabled") {
      // requested to do nothing please. 
      return;
    } else if (ajax_uri === undefined) {
      ajax_uri = uri;
    }

    $(this).closest("form").find(".facet-browse-loading").addClass("active")          

    console.log(logTime() + "fetching for " + q)

    dom_data.updates_in_progress++;

    $.ajax({
      url:      ajax_uri,
      data:     q,
      dataType: "html",
      success: function(response) {
        console.log(logTime() + "results in")

        var replace_content_selector = "*[data-instant-search=content]"

        // pull out just the div we want, using code copied from
        // jquery "load" function feature
        var partial_html = $("<div>").append( $.parseHTML( response ) ).find( replace_content_selector );


        // We need to attach our AJAX popup window behavior
        // to nav links in the new page we're loading. This is doing it for BL 3.5, sorry
        // will need something else in more recent Blacklight (or a patch to 
        // more recent BL to use jquery 'on') as well as more recnet
        // code for modals. 
        if (Blacklight !== undefined && 
            $.uiExt !== undefined &&
            $.uiExt.ajaxyDialog !== undefined) {

            partial_html.find("a.next_page, a.prev_page, a.sort_change").ajaxyDialog({
              width: $(window).width() / 2,  
              chainAjaxySelector: "a.next_page, a.prev_page, a.sort_change" 
            });      
        }

        form.closest(".facet_list").find(replace_content_selector).replaceWith(partial_html); 

        dom_data.updates_in_progress--;

        if (dom_data.updates_in_progress === 0)
          $(form).find(".facet-browse-loading").removeClass("active");
      },
      error: function(jqXHR, textStatus, errorThrown) {
        dom_data.updates_in_progress--;        
        if (dom_data.updates_in_progress === 0)
          $(form).find(".facet-browse-loading").removeClass("active");

        var replace_content_selector = "*[data-instant-search=content]"

        form.closest(".facet_list").find(replace_content_selector).html("Sorry, an error occured: " + textStatus + ' ' + errorThrown );
      }
    });
  };

<commit_msg>fix ajax preserving on more links<commit_after>(function($) {


  var browse_data = function(element) {
    var data = $(element).data("facet_browse");

    if (data === undefined) {
      data = $(element).data("facet_browse", {})
    }

    return data;
  }


  //debounce taken from underscore library. 
  var debounce = function(func, wait, immediate) {
    var timeout, args, context, timestamp, result;
    return function() {
      context = this;
      args = arguments;
      timestamp = new Date();
      var later = function() {
        var last = (new Date()) - timestamp;
        if (last < wait) {
          timeout = setTimeout(later, wait - last);
        } else {
          timeout = null;
          if (!immediate) result = func.apply(context, args);
        }
      };
      var callNow = immediate && !timeout;
      if (!timeout) {
        timeout = setTimeout(later, wait);
      }
      if (callNow) result = func.apply(context, args);
      return result;
    };
  };
  
  var update = function(text_field) {
    var dom_data = browse_data(text_field);
    if (dom_data.updates_in_progress === undefined)
      dom_data.updates_in_progress = 0;


    var form     = $(text_field).closest("form");
    var uri      = form.attr("action");
    var q        = form.serialize();

    var ajax_uri = form.data("ajax-url");
    if (ajax_uri === "disabled") {
      // requested to do nothing please. 
      return;
    } else if (ajax_uri === undefined) {
      ajax_uri = uri;
    }

    $(this).closest("form").find(".facet-browse-loading").addClass("active")          

    console.log(logTime() + "fetching for " + q)

    dom_data.updates_in_progress++;

    $.ajax({
      url:      ajax_uri,
      data:     q,
      dataType: "html",
      success: function(response) {
        console.log(logTime() + "results in")

        var replace_content_selector = "*[data-instant-search=content]"

        // pull out just the div we want, using code copied from
        // jquery "load" function feature
        var partial_html = $("<div>").append( $.parseHTML( response ) ).find( replace_content_selector );


        // We need to attach our AJAX popup window behavior
        // to nav links in the new page we're loading. This is doing it for BL 3.5, sorry
        // will need something else in more recent Blacklight (or a patch to 
        // more recent BL to use jquery 'on') as well as more recnet
        // code for modals. 
        if (Blacklight !== undefined && 
            $.uiExt !== undefined &&
            $.uiExt.ajaxyDialog !== undefined) {

            // For ajax loads in the sidebar, find any 'more' links
            // and make sure they will trigger load in modal. 
            partial_html.find("a.more_facets_link").ajaxyDialog({
              width: $(window).width() / 2,  
              chainAjaxySelector: "a.next_page, a.prev_page, a.sort_change"        
            });
            

            // For already being inside the modal, find next/previous/sort 
            // buttons and make sure they will trigger
            // load inside the modal. 
            partial_html.find("a.next_page, a.prev_page, a.sort_change").ajaxyDialog({
              width: $(window).width() / 2,  
              chainAjaxySelector: "a.next_page, a.prev_page, a.sort_change" 
            });      
        }

        form.closest(".facet_list").find(replace_content_selector).replaceWith(partial_html); 

        dom_data.updates_in_progress--;

        if (dom_data.updates_in_progress === 0)
          $(form).find(".facet-browse-loading").removeClass("active");
      },
      error: function(jqXHR, textStatus, errorThrown) {
        dom_data.updates_in_progress--;        
        if (dom_data.updates_in_progress === 0)
          $(form).find(".facet-browse-loading").removeClass("active");

        var replace_content_selector = "*[data-instant-search=content]"

        form.closest(".facet_list").find(replace_content_selector).html("Sorry, an error occured: " + textStatus + ' ' + errorThrown );
      }
    });
  };


{'fraction_non_alphanumeric': 0.13274569135640046, 'fraction_numerical': 0.0017103012761478752, 'mean_word_length': 2.21301775147929, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3402021', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2190, 'n_words': 557}