<commit_before>var imageGenerator = {

  searchTagOnTumblr_: function(searchTerm){
      return 'http://api.tumblr.com/v2/tagged?' +
      'tag=' + encodeURIComponent(searchTerm) + '&' +
      'api_key=<KEY>&' +
      'limit=20'
      },


  /**
   * Sends an XHR GET request to grab search results for a tag on tumblr
   *
   * @public
   */
  requestTumblrTag: function(searchTerm) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", this.searchTagOnTumblr_(searchTerm), true);
    var stupidThis = this;
    xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
        // JSON.parse does not evaluate the attacker's scripts.
        var resp = JSON.parse(xhr.responseText);
        stupidThis.loadTumblrImages_(resp);
      }
    }
    xhr.send();
  },

  /**
   * Handle the 'onload' event of the Tumblr search request. This should parse
   * the JSON return object and load the image in the view
   */
  loadTumblrImages_: function(result) {
    // var resp = JSON.parse(result.responseText);
    var results = result.response;
    var rand = results[Math.floor(Math.random() * results.length)];
    if (rand.photos){
      var imgLink = rand.photos[0].alt_sizes[0].url;
    }
    if (imgLink){
      var img = document.createElement('img');
      img.src = imgLink;
      $('#test').append(img);
      $('#test').slideDown('fast');
    }
  }

};

// Run our kitten generation script as soon as the document's DOM is ready.
document.addEventListener('DOMContentLoaded', function () {
  var favorites = new Favorites();
  favorites.getFavorites(function(result){
    if (result) {
      for (var i=0;i<result.length;i++){
        $('.favorites').append('<img src='+result[i].image+'>');
      }
    }
  });
  $('#searchTerm').keyup(function(e){
    if(e.keyCode == 13)
    {
      $('#test').empty();
      imageGenerator.requestTumblrTag($('#searchTerm').val());
    }
  });

  // Copy To Clipboard
  $('img').on('click', function () {
      alert("click");
  });
});
<commit_msg>added delegate for copy to clipboard on image click<commit_after>var imageGenerator = {

  searchTagOnTumblr_: function(searchTerm){
      return 'http://api.tumblr.com/v2/tagged?' +
      'tag=' + encodeURIComponent(searchTerm) + '&' +
      'api_key=<KEY>&' +
      'limit=20'
      },


  /**
   * Sends an XHR GET request to grab search results for a tag on tumblr
   *
   * @public
   */
  requestTumblrTag: function(searchTerm) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", this.searchTagOnTumblr_(searchTerm), true);
    var stupidThis = this;
    xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
        // JSON.parse does not evaluate the attacker's scripts.
        var resp = JSON.parse(xhr.responseText);
        stupidThis.loadTumblrImages_(resp);
      }
    }
    xhr.send();
  },

  /**
   * Handle the 'onload' event of the Tumblr search request. This should parse
   * the JSON return object and load the image in the view
   */
  loadTumblrImages_: function(result) {
    // var resp = JSON.parse(result.responseText);
    var results = result.response;
    var rand = results[Math.floor(Math.random() * results.length)];
    if (rand.photos){
      var imgLink = rand.photos[0].alt_sizes[0].url;
    }
    if (imgLink){
      var img = document.createElement('img');
      img.src = imgLink;
      $('#test').append(img);
      $('#test').slideDown('fast');
    }
  },

  copyToClipboard: function(url) {
    console.log(url);
  }

};

// Run our kitten generation script as soon as the document's DOM is ready.
document.addEventListener('DOMContentLoaded', function () {
  var favorites = new Favorites();
  favorites.getFavorites(function(result){
    if (result) {
      for (var i=0;i<result.length;i++){
        $('.favorites').append('<img src='+result[i].image+'>');
      }
    }
  });
  $('#searchTerm').keyup(function(e){
    if(e.keyCode == 13)
    {
      $('#test').empty();
      imageGenerator.requestTumblrTag($('#searchTerm').val());
    }
  });

  // Copy To Clipboard Delegate
  $( "body" ).delegate( "img", "click", function() {
    imageGenerator.copyToClipboard($(this).attr('src'));
  });
});

{'fraction_non_alphanumeric': 0.16176118688681504, 'fraction_numerical': 0.004307250538406317, 'mean_word_length': 2.9065420560747666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '5027327', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1354, 'n_words': 297}