<commit_before>(function($)
{
  var methods =
  {
    update: function()
    {
      methods.loadPage.apply(this, [0]);

      return this;
    },
    nextPage: function()
    {
      var page = $(this).data("jquery.comments.options").tail;
      var comments = this;

      methods.loadPage.apply(this, [page + 1])
        .done(function(result)
        {
          if(result.length > 0)
          {
            $(comments).data("jquery.comments.options").tail++;
          }
        });

      return this;
    },
    loadPage: function(page)
    {
      var f = $(this).data("jquery.comments.options").onLoad;

      if(f)
      {
        var ul = this;
        var client = new MeatStore().createClient();
        var users = new Array();

        $.mobile.loading("show");

        return f(page, $(this).data("jquery.comments.options").pageSize)
          .done(function(comments)
          {
            // insert comments:
            $(comments).each(function(i, comment)
            {
              var li = $(ul).find('li[data-id="' + comment["id"] + '"]').first();

              if(!li.get(0))
              {
                var author = comment["user"]["username"];
                var el = $('<li data-id="' + comment["id"] + '" data-timestamp="' + comment["created_on"]["$date"] + '">' +
                           '<img data-source="' + author + '" src="images/image-loader.gif" alt="">' +
                           '<p>' + comment["text"] + '</p>' +
                           '<p>' +new Date(comment["created_on"]["$date"]).toLocaleString() + '</strong>' +
                           ' by <strong>' + author + '</strong></p>' +
                           '</li>');

                var inserted = false;

                $(ul).find("li").each(function(i, c)
                {
                  if(parseInt(comment["created_on"]["$date"], 10) > parseInt($(c).data("timestamp"), 10))
                  {
                    $(c).before(el);
                    inserted = true;
                  }

                  return !inserted;
                });

                if(!inserted)
                {
                  $(ul).append(el);
                }

                if($.inArray(author, users) == -1)
                {
                  users.push(author);
                }
              }
            });

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

            // load thumbnails:
            $(users).each(function(i, username)
            {
              client.getAvatar(username)
                .success(function(avatar)
                {
                  $(ul).find('img[data-source="' + username + '"]').attr("src", avatar);
                })
                .fail(function(r)
                {
                  $(ul).find('img[data-source="' + username + '"]').attr("src", "images/image-missing.png");
                });
            });
          })
          .always(function()
          {
            $.mobile.loading("hide");
          });
      }

      return null;
    }
  };

  function createComments(obj, options)
  {
    $(obj).data("jquery.comments", true);
    $(obj).data("jquery.comments.options", $.extend({pageSize: 10, tail: 0, onLoad: null}, options));

    $(obj).find("li").remove();
    $(obj).listview();
  }

  $.fn.comments = function(args)
  {
    if(methods[args])
    {
      var parameters = Array.prototype.slice.call(arguments, 1);

      return this.each(function()
      {
        if($(this).data("jquery.comments"))<commit_msg>don't request more old comments from server when the first comment has been delivered<commit_after>(function($)
{
  var methods =
  {
    update: function()
    {
      methods.loadPage.apply(this, [0]);

      return this;
    },
    nextPage: function()
    {
      var comments = this;

      if(!$(comments).data("jquery.comments.options").endOfStream)
      {
        var page = $(this).data("jquery.comments.options").tail;
        var comments = this;

        methods.loadPage.apply(this, [page + 1])
          .done(function(result)
          {
            if(result.length > 0)
            {
              $(comments).data("jquery.comments.options").tail++;
            }
            else
            {
              $(comments).data("jquery.comments.options").endOfStream = true;
            }
          });
      }

      return this;
    },
    loadPage: function(page)
    {
      var f = $(this).data("jquery.comments.options").onLoad;

      if(f)
      {
        var ul = this;
        var client = new MeatStore().createClient();
        var users = new Array();

        $.mobile.loading("show");

        return f(page, $(this).data("jquery.comments.options").pageSize)
          .done(function(comments)
          {
            // insert comments:
            $(comments).each(function(i, comment)
            {
              var li = $(ul).find('li[data-id="' + comment["id"] + '"]').first();

              if(!li.get(0))
              {
                var author = comment["user"]["username"];
                var el = $('<li data-id="' + comment["id"] + '" data-timestamp="' + comment["created_on"]["$date"] + '">' +
                           '<img data-source="' + author + '" src="images/image-loader.gif" alt="">' +
                           '<p>' + comment["text"] + '</p>' +
                           '<p>' +new Date(comment["created_on"]["$date"]).toLocaleString() + '</strong>' +
                           ' by <strong>' + author + '</strong></p>' +
                           '</li>');

                var inserted = false;

                $(ul).find("li").each(function(i, c)
                {
                  if(parseInt(comment["created_on"]["$date"], 10) > parseInt($(c).data("timestamp"), 10))
                  {
                    $(c).before(el);
                    inserted = true;
                  }

                  return !inserted;
                });

                if(!inserted)
                {
                  $(ul).append(el);
                }

                if($.inArray(author, users) == -1)
                {
                  users.push(author);
                }
              }
            });

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

            // load thumbnails:
            $(users).each(function(i, username)
            {
              client.getAvatar(username)
                .success(function(avatar)
                {
                  $(ul).find('img[data-source="' + username + '"]').attr("src", avatar);
                })
                .fail(function(r)
                {
                  $(ul).find('img[data-source="' + username + '"]').attr("src", "images/image-missing.png");
                });
            });
          })
          .always(function()
          {
            $.mobile.loading("hide");
          });
      }

      return null;
    }
  };

  function createComments(obj, options)
  {
    $(obj).data("jquery.comments", true);
    $(obj).data("jquery.comments.options", $.extend({pageSize: 10, tail: 0, endOfStream: false, onLoad: null}, options));

    $(obj).find("li").remove();
    $(obj).listview();
  }

  $.fn.comments = function(args)
  {
    if(methods[args])
    {
      var parameters = Array.prototype.slice.call(arguments, 1);

      return this.each(function()
      {
        if($(this).data("jquery.comments"))
{'fraction_non_alphanumeric': 0.17565359477124182, 'fraction_numerical': 0.003540305010893246, 'mean_word_length': 1.3816472114137484, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '6842664', 'n_tokens_mistral': 2095, 'n_tokens_neox': 1988, 'n_words': 321}