<commit_before>/* add highlight function to jquery for search highlighting */
jQuery.fn.highlight=function(c){function e(b,c){var d=0;if(3==b.nodeType){var a=b.data.toUpperCase().indexOf(c),a=a-(b.data.substr(0,a).toUpperCase().length-b.data.substr(0,a).length);if(0<=a){d=document.createElement("span");d.className="highlight";a=b.splitText(a);a.splitText(c.length);var f=a.cloneNode(!0);d.appendChild(f);a.parentNode.replaceChild(d,a);d=1}}else if(1==b.nodeType&&b.childNodes&&!/(script|style)/i.test(b.tagName))for(a=0;a<b.childNodes.length;++a)a+=e(b.childNodes[a],c);return d} return this.length&&c&&c.length?this.each(function(){e(this,c.toUpperCase())}):this};
/* all credit goes to: http://johannburkard.de/ */

/* form elements */
$(function(){
  $('body').on('change', 'form input[type=file]', function(event) {
    var $fileInput = $(this),
      $formGroup = $(this).parents('.form-group'),
      $hiddenInput = $(event.target).next('input[type=hidden]');
    if (event.target.files && event.target.files.length) {
      var fileReader = new FileReader();
      fileReader.onload = function(e) {
        $hiddenInput.val(e.target.result);
        if ($formGroup.data('image-preview')) {
          var $container = $formGroup
            .find($formGroup.data('image-preview')),
            $img = $('<img>');
          $img.attr('src', e.target.result);
          $container
            .empty()
            .append($img);
        }
      };
      fileReader.readAsDataURL(event.target.files[0]);
    }
  });


  /* initilize pagination, search, sort and filter */
  if (window['_paginationPages']) {

    var pageNumber = 1,
      searchQuery = '',
      filterQuery = '',
      sortQuery = '';

    /* pagination, search, sort and filter call this
        function to refresh the page */
    function refreshPage () {
      $.get(location.href,
            {page: pageNumber,
            search: searchQuery,
            filter: filterQuery.filter,
            filterkey: filterQuery.filterkey,
            sort: sortQuery.sort,
            sortdirection: sortQuery.sortdirection},
            function (data) {
              /* display the new content */
              $('#content').html(data);

              /* highlight the search if there is any */
              if(searchQuery != ''){
                $('#content').highlight($searchInput.val());
              }

              console.log(pageNumber + ' / ' + window._pageCounter);
              /* update pagination */
              $('#page_selection').bootpag({
                total: window._pageCounter,
                page: pageNumber,
                maxVisible: 10
              });

              /* replace pagination text if in encyclopedia */
              if(window.location.pathname === "/encyclopedia"){
                replacePaginationText();
              }
            });
    }

    /* Pagination */
    $('#page_selection').bootpag({
      total: window._pageCounter || 1,<commit_msg>Fixed pagination bug<commit_after>/* add highlight function to jquery for search highlighting */
jQuery.fn.highlight=function(c){function e(b,c){var d=0;if(3==b.nodeType){var a=b.data.toUpperCase().indexOf(c),a=a-(b.data.substr(0,a).toUpperCase().length-b.data.substr(0,a).length);if(0<=a){d=document.createElement("span");d.className="highlight";a=b.splitText(a);a.splitText(c.length);var f=a.cloneNode(!0);d.appendChild(f);a.parentNode.replaceChild(d,a);d=1}}else if(1==b.nodeType&&b.childNodes&&!/(script|style)/i.test(b.tagName))for(a=0;a<b.childNodes.length;++a)a+=e(b.childNodes[a],c);return d} return this.length&&c&&c.length?this.each(function(){e(this,c.toUpperCase())}):this};
/* all credit goes to: http://johannburkard.de/ */

/* form elements */
$(function(){
  $('body').on('change', 'form input[type=file]', function(event) {
    var $fileInput = $(this),
      $formGroup = $(this).parents('.form-group'),
      $hiddenInput = $(event.target).next('input[type=hidden]');
    if (event.target.files && event.target.files.length) {
      var fileReader = new FileReader();
      fileReader.onload = function(e) {
        $hiddenInput.val(e.target.result);
        if ($formGroup.data('image-preview')) {
          var $container = $formGroup
            .find($formGroup.data('image-preview')),
            $img = $('<img>');
          $img.attr('src', e.target.result);
          $container
            .empty()
            .append($img);
        }
      };
      fileReader.readAsDataURL(event.target.files[0]);
    }
  });


  /* initilize pagination, search, sort and filter */
  if (window['_paginationPages']) {

    var pageNumber = 1,
      searchQuery = '',
      filterQuery = '',
      sortQuery = '';

    /* pagination, search, sort and filter call this
        function to refresh the page */
    function refreshPage () {
      $.get(location.href,
            {page: pageNumber,
            search: searchQuery,
            filter: filterQuery.filter,
            filterkey: filterQuery.filterkey,
            sort: sortQuery.sort,
            sortdirection: sortQuery.sortdirection},
            function (data) {
              
              /* if page is beyond the current max, reset */
              if(window._pageCounter > pageNumber)
                pageNumber = window._pageCounter;

              /* display the new content */
              $('#content').html(data);

              /* highlight the search if there is any */
              if(searchQuery != ''){
                $('#content').highlight($searchInput.val());
              }

              console.log(pageNumber + ' / ' + window._pageCounter);
              /* update pagination */
              $('#page_selection').bootpag({
                total: window._pageCounter,
                page: pageNumber,
                maxVisible: 10
              });

              /* replace pagination text if in encyclopedia */
              if(window.location.pathname === "/encyclopedia"){
                replacePaginationText();
              }
            });
    }

    /* Pagination */
    $('#page_selection').bootpag({
      total: window._pageCounter || 1,
{'fraction_non_alphanumeric': 0.16653087827928956, 'fraction_numerical': 0.004562489815870947, 'mean_word_length': 2.319632233639805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, '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': '4180523', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1772, 'n_words': 299}