<commit_before>(function($)
{
  var methods =
  {
    update: function()
    {
      methods.loadPage.apply(this, [0]);
    },
    nextPage: function()
    {
      var page = parseInt($(this).data("options").tail, 10);
      var library = this;

      methods.loadPage.apply(this, [page + 1])
        .done(function(images)
        {
          if(images.length > 0)
          {
            $(library).data("options").tail++;
          }
        });
    },
    loadPage: function(page)
    {
      var f = $(this).data("options").onLoad;

      if(f)
      {
        var library = this;

        return f(page, $(library).data("options").pageSize)
          .done(function(images)
          {
            $(images).each(function()
            {
              methods.touch.apply(library, [this, true]);
            });
          });
      }

      return null;
    },
    touch: function(image, insert)
    {
      // test if image has already been inserted:
      var li = $(this).find('li[data-source="' + image["source"] + '"]').first();

      if(li.get(0))
      {
        // update details of already inserted image:
        $(li).find('p[data-field="comments"]').html('<strong>Comments:</strong> ' + image["comments_n"]);
        $(li).find('p[data-field="score"]').html('<strong>Score:</strong> ' + image["score"]["up"] + ' up, ' + image["score"]["down"] + ' down');
      }
      else
      {
        var compare = $(this).data("options").onCompare;

        // insert new image:
        var html = '<li data-source="' + image["source"] + '" data-timestamp="' + image["created_on"]["$date"] + '">' +
                   '<a href="#"><img data-source="' + image["source"] + '"src="images/image-loader.gif" alt="">' +
                   '<h2>' + image["source"] + '</h2>' +
                   '<p data-field="timestamp"><strong>Created on:</strong> ' + new Date(image["created_on"]["$date"]).toLocaleString() + '</p>' +
                   '<p data-field="comments"><strong>Comments:</strong> ' + image["comments_n"] + '</p>' +
                   '<p data-field="score"><strong>Score:</strong> ' + image["score"]["up"] + ' up, ' + image["score"]["down"] + ' down</p>' +
                   '</a></li>';

        var inserted = false;

        if(compare)
        {
          $(this).find("li").each(function()
          {
            if(compare(image, $(this)))
            {
              $(html).insertBefore(this);
              inserted = true;
            }
          });
        }

        if(!inserted)
        {
          $(this).append(html);
        }
      }

      $(this).listview("refresh");

      // load thumbnail:
      var client = new MeatStore().createClient();

      client.getThumbnail(image["source"])
        .success(function(thumbnail)
        {
          $('img[data-source="' + image["source"] + '"]').attr("src", thumbnail);
        })
        .fail(function(r)
        {
          $('img[data-source="' + image["source"] + '"]').attr("src", "images/image-missing.png");
        });
    },
    clear: function()
    {
      $(this).find("li").remove();
      $(this).listview("refresh");
    }
  };

  function createLibrary(obj, options)
  {
    $(obj).data("options", $.extend({pageSize: 10, tail: 0, onLoad: null, onCompare: null}, options));
    $(obj).data("images", new Array());
  }

  $.fn.library = function(args)
  {
    if(methods[args])
    {
      this.each(function()
      {
        return methods[args].apply(this, Array.prototype.slice.call(arguments, 1));
      });
    }
    else if(typeof args === 'object' || !args)
    {
      return this.each(function()
      {
        createLibrary(this, args);
      });
    }
  }
}(jQuery));
<commit_msg>show number of favorites in jquery.library<commit_after>(function($)
{
  var methods =
  {
    update: function()
    {
      methods.loadPage.apply(this, [0]);
    },
    nextPage: function()
    {
      var page = parseInt($(this).data("options").tail, 10);
      var library = this;

      methods.loadPage.apply(this, [page + 1])
        .done(function(images)
        {
          if(images.length > 0)
          {
            $(library).data("options").tail++;
          }
        });
    },
    loadPage: function(page)
    {
      var f = $(this).data("options").onLoad;

      if(f)
      {
        var library = this;

        return f(page, $(library).data("options").pageSize)
          .done(function(images)
          {
            $(images).each(function()
            {
              methods.touch.apply(library, [this, true]);
            });
          });
      }

      return null;
    },
    touch: function(image, insert)
    {
      // test if image has already been inserted:
      var li = $(this).find('li[data-source="' + image["source"] + '"]').first();

      if(li.get(0))
      {
        // update details of already inserted image:
        $(li).find('p[data-field="comments"]').html('<strong>Comments:</strong> ' + image["comments_n"]);
        $(li).find('p[data-field="score"]').html('<strong>Score:</strong> ' + image["score"]["up"] + ' up, ' + image["score"]["down"] + ' down, ' + image["score"]["fav"] + ' favs');
      }
      else
      {
        var compare = $(this).data("options").onCompare;

        // insert new image:
        var html = '<li data-source="' + image["source"] + '" data-timestamp="' + image["created_on"]["$date"] + '">' +
                   '<a href="#"><img data-source="' + image["source"] + '"src="images/image-loader.gif" alt="">' +
                   '<h2>' + image["source"] + '</h2>' +
                   '<p data-field="timestamp"><strong>Created on:</strong> ' + new Date(image["created_on"]["$date"]).toLocaleString() + '</p>' +
                   '<p data-field="comments"><strong>Comments:</strong> ' + image["comments_n"] + '</p>' +
                   '<p data-field="score"><strong>Score:</strong> ' + image["score"]["up"] + ' up, ' + image["score"]["down"] + ' down, ' + image["score"]["fav"] + ' favs</p>' +
                   '</a></li>';

        var inserted = false;

        if(compare)
        {
          $(this).find("li").each(function()
          {
            if(compare(image, $(this)))
            {
              $(html).insertBefore(this);
              inserted = true;
            }
          });
        }

        if(!inserted)
        {
          $(this).append(html);
        }
      }

      $(this).listview("refresh");

      // load thumbnail:
      var client = new MeatStore().createClient();

      client.getThumbnail(image["source"])
        .success(function(thumbnail)
        {
          $('img[data-source="' + image["source"] + '"]').attr("src", thumbnail);
        })
        .fail(function(r)
        {
          $('img[data-source="' + image["source"] + '"]').attr("src", "images/image-missing.png");
        });
    },
    clear: function()
    {
      $(this).find("li").remove();
      $(this).listview("refresh");
    }
  };

  function createLibrary(obj, options)
  {
    $(obj).data("options", $.extend({pageSize: 10, tail: 0, onLoad: null, onCompare: null}, options));
    $(obj).data("images", new Array());
  }

  $.fn.library = function(args)
  {
    if(methods[args])
    {
      this.each(function()
      {
        return methods[args].apply(this, Array.prototype.slice.call(arguments, 1));
      });
    }
    else if(typeof args === 'object' || !args)
    {
      return this.each(function()
      {
        createLibrary(this, args);
      });
    }
  }
}(jQuery));

{'fraction_non_alphanumeric': 0.20901694010937708, 'fraction_numerical': 0.003201280512204882, 'mean_word_length': 1.9742165807219358, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, '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': '7084065', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2271, 'n_words': 367}