<commit_before>(function($)
{
  var buildListItem = function(image)
  {
     return $('<li data-guid="' + image["guid"] + '" data-source="' + image["source"].escapeQuotes() + '" data-timestamp="' + image["created_on"]["$date"] + '">' +
              '<a href="#"><img data-source="' + image["source"].escapeQuotes() + '"src="images/image-loader.gif" alt="">' +
              '<h2>' + image["source"].escapeHTML() + '</h2>' +
              '<p><strong>Created on: </strong>' +
              '<span data-field="date">' + new Date(image["created_on"]["$date"]).toLocaleString() + '</span></p>' +
              '<p><strong>Comments: </strong>' +
              '<span data-field="comments_n">' + image["comments_n"] + '</span></p>' +
              '<p><strong>Score: </strong>' +
              '<span data-field="up">' + image["score"]["up"] + '</span> up, ' +
              '<span data-field="down">' + image["score"]["down"] + '</span> down, ' +
              '<span data-field="fav">' + image["score"]["fav"] + '</span> favorite(s)</p>' +
              '</a></li>');
  }

  var bindEvents = function(library, li)
  {
    var onSelect = $(library).data("jquery.library.options").onSelect;

    if(onSelect)
    {
      $(li).on("click", function()
      {
        onSelect($(this).data("guid"));

        $(library).data("jquery.library.selected", li);
      });
    }
  }

  var findGUID = function(a, guid)
  {
    var length = a.length;

    for(var i = 0; i < length; i++)
    {
      if(a[i]["guid"] == guid)
      {
        return i;
      }
    }

    return -1;
  }

  var methods =
  {
    update: function()
    {
      var lastUpdate = $(this).data("lastUpdate");

      if(lastUpdate == null || (new Date().getTime() - lastUpdate) / 1000 > $(this).data("jquery.library.options").requestLimit)
      {
        var opts = $(this).data("jquery.library.options");

        if(!opts.silent)
        {
          setTimeout(function() { $.mobile.loading("show"); }, 1);
        }

        methods.loadPage.apply(this, [0])
          .always(function()
          {
            if(!opts.silent)
            {
              setTimeout(function() { $.mobile.loading("hide"); }, 1);
            }
          });

        $(this).data("lastUpdate", new Date().getTime());
      }
    },
    nextPage: function(triggerNext)
    {
      var library = this;
      var page = $(library).data("jquery.library.tail");
      var opts = $(library).data("jquery.library.options");

      if(triggerNext && !opts.silent)
      {
        setTimeout(function() { $.mobile.loading("show"); }, 1);
      }

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

      if(f)
      {
        var library = this;

        return f(page, $(this).data("jquery.library.options").pageSize)
          .done(function(images)
          {
            if(images && images.length > 0)
            {
              $(images).each(function()
              {
                methods.touch.apply(library, [this, true, false, true]);
              });

              if(opts.onCompare)
              {
                methods.sort.apply(library);
              }
              else
              {
                methods.refresh.apply(library);
              }

              if(triggerNext)
              {
                if(!opts.silent)
                {
                  setTimeout(function() { $.mobile.loading("hide"); }, 1);
                }

                methods.next.apply(library);
              }
            }
          })
          .fail(function()
          {
            if(!opts.silent)
            {
              navigator.notification.alert("Couldn't load images, please try again.", null, "Request failed", "Ok");
            }
          });
      }

      return null;
    },
    touch: function(image, insert, sort, noRefresh)
    {
      var opts = $(this).data("jquery.library.options");
      var objects = $(this).data("jquery.library.objects");
      var m = $(this).data("jquery.library.map");

      // test if image has already been inserted:
      var inserted = false;
      var li = m[image["guid"]];

      if(li)
      {
        var index = findGUID(objects, image["guid"]);
        var old = objects[index];

        // image found => update details (if necessary):
        if(old["comments_n"] != image["comments_n"]       ||
           old["score"]["up"] != image["score"]["up"]     ||
           old["score"]["down"] != image["score"]["down"] ||
           old["score"]["fav"] != image["score"]["fav"])
        {
          $(li).find('span[data-field="comments_n"]').html(image["comments_n"]);
          $(li).find('span[data-field="up"]').html(image["score"]["up"]);
          $(li).find('span[data-field="down"]').html(image["score"]["down"]);
          $(li).find('span[data-field="fav"]').html(image["score"]["fav"]);
        }
      }
      else if(insert)
      {
        // insert new image:
        objects.push(image);

        if(!sort)<commit_msg>update model in jquery.library widget when calling touch() method with an updated image<commit_after>(function($)
{
  var buildListItem = function(image)
  {
     return $('<li data-guid="' + image["guid"] + '" data-source="' + image["source"].escapeQuotes() + '" data-timestamp="' + image["created_on"]["$date"] + '">' +
              '<a href="#"><img data-source="' + image["source"].escapeQuotes() + '"src="images/image-loader.gif" alt="">' +
              '<h2>' + image["source"].escapeHTML() + '</h2>' +
              '<p><strong>Created on: </strong>' +
              '<span data-field="date">' + new Date(image["created_on"]["$date"]).toLocaleString() + '</span></p>' +
              '<p><strong>Comments: </strong>' +
              '<span data-field="comments_n">' + image["comments_n"] + '</span></p>' +
              '<p><strong>Score: </strong>' +
              '<span data-field="up">' + image["score"]["up"] + '</span> up, ' +
              '<span data-field="down">' + image["score"]["down"] + '</span> down, ' +
              '<span data-field="fav">' + image["score"]["fav"] + '</span> favorite(s)</p>' +
              '</a></li>');
  }

  var bindEvents = function(library, li)
  {
    var onSelect = $(library).data("jquery.library.options").onSelect;

    if(onSelect)
    {
      $(li).on("click", function()
      {
        onSelect($(this).data("guid"));

        $(library).data("jquery.library.selected", li);
      });
    }
  }

  var findGUID = function(a, guid)
  {
    var length = a.length;

    for(var i = 0; i < length; i++)
    {
      if(a[i]["guid"] == guid)
      {
        return i;
      }
    }

    return -1;
  }

  var methods =
  {
    update: function()
    {
      var lastUpdate = $(this).data("lastUpdate");

      if(lastUpdate == null || (new Date().getTime() - lastUpdate) / 1000 > $(this).data("jquery.library.options").requestLimit)
      {
        var opts = $(this).data("jquery.library.options");

        if(!opts.silent)
        {
          setTimeout(function() { $.mobile.loading("show"); }, 1);
        }

        methods.loadPage.apply(this, [0])
          .always(function()
          {
            if(!opts.silent)
            {
              setTimeout(function() { $.mobile.loading("hide"); }, 1);
            }
          });

        $(this).data("lastUpdate", new Date().getTime());
      }
    },
    nextPage: function(triggerNext)
    {
      var library = this;
      var page = $(library).data("jquery.library.tail");
      var opts = $(library).data("jquery.library.options");

      if(triggerNext && !opts.silent)
      {
        setTimeout(function() { $.mobile.loading("show"); }, 1);
      }

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

      if(f)
      {
        var library = this;

        return f(page, $(this).data("jquery.library.options").pageSize)
          .done(function(images)
          {
            if(images && images.length > 0)
            {
              $(images).each(function()
              {
                methods.touch.apply(library, [this, true, false, true]);
              });

              if(opts.onCompare)
              {
                methods.sort.apply(library);
              }
              else
              {
                methods.refresh.apply(library);
              }

              if(triggerNext)
              {
                if(!opts.silent)
                {
                  setTimeout(function() { $.mobile.loading("hide"); }, 1);
                }

                methods.next.apply(library);
              }
            }
          })
          .fail(function()
          {
            if(!opts.silent)
            {
              navigator.notification.alert("Couldn't load images, please try again.", null, "Request failed", "Ok");
            }
          });
      }

      return null;
    },
    touch: function(image, insert, sort, noRefresh)
    {
      var opts = $(this).data("jquery.library.options");
      var objects = $(this).data("jquery.library.objects");
      var m = $(this).data("jquery.library.map");

      // test if image has already been inserted:
      var inserted = false;
      var li = m[image["guid"]];

      if(li)
      {
        var index = findGUID(objects, image["guid"]);
        var old = objects[index];

        // image found => update details (if necessary):
        if(old["comments_n"] != image["comments_n"]       ||
           old["score"]["up"] != image["score"]["up"]     ||
           old["score"]["down"] != image["score"]["down"] ||
           old["score"]["fav"] != image["score"]["fav"])
        {
          $(li).find('span[data-field="comments_n"]').html(image["comments_n"]);
          $(li).find('span[data-field="up"]').html(image["score"]["up"]);
          $(li).find('span[data-field="down"]').html(image["score"]["down"]);
          $(li).find('span[data-field="fav"]').html(image["score"]["fav"]);

          objects[index] = image;
        }
      }
      else if(insert)
      {
        // insert new image:
        objects.push(image);

        if(!sort)
{'fraction_non_alphanumeric': 0.19547113315242817, 'fraction_numerical': 0.003181435388790119, 'mean_word_length': 1.824524312896406, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 69, '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': '1319822', 'n_tokens_mistral': 3189, 'n_tokens_neox': 3161, 'n_words': 519}