<commit_before>jQuery.fn.rest_in_place = function() {
  var e = this;
  var url, objectName, attributeName;
  // Try parent supplied info
  e.parents().each(function(){
    url           = jQuery(this).attr("data-url");
    objectName    = jQuery(this).attr("data-object");
    attributeName = jQuery(this).attr("data-attribute");
  });
  // Try Rails-id based if parents did not explicitly supply something
  e.parents().each(function(){
    var res;
    if (res = this.id.match(/^(\w+)_(\d+)$/i)) {
      objectName = objectName || res[1];
    }
  });
  // Load own attributes (overrides all others)
  url           = e.attr("data-url")       || url    || document.location.pathname;
  objectName    = e.attr("data-object")    || objectName;
  attributeName = e.attr("data-attribute") || attributeName;
  
  function clickFunction() {
    var oldValue = e.html();
    e.html('<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + oldValue + '"></form>')
      .find("input")[0]
        .select();
    e.unbind('click', clickFunction)
      .find("input").blur(function inputBlurHandler(){
        e.html(oldValue)
          .click(clickFunction);
      })
    e.find("form").submit(function submitHandler(){
      var value = e.find("input").val();
      e.html("saving...");
      jQuery.ajax({
        "url" : url,
        "type" : "post",
        "dataType" : "text",
        "beforeSend"  : function(xhr){ xhr.setRequestHeader("Accept", "application/json"); },
        "data" : "_method=put&"+objectName+'['+attributeName+']='+encodeURIComponent(value)+(window.rails_authenticity_token ? "&authenticity_token="+encodeURIComponent(window.rails_authenticity_token) : ''),
        "success" : function saveSuccessCallback(data, textStatus){
          jQuery.ajax({
            "url" : url,
            "beforeSend"  : function(xhr){ xhr.setRequestHeader("Accept", "application/json"); },
            "success" : function loadSuccessCallback(data){
              if (jQuery.fn.jquery < "1.4") {
                data = eval('(' + data + ')' );
              }
              e.html(data[objectName][attributeName]);
              e.click(clickFunction);
            }
          });
        }
      });
      return false;
    })
  }
  this.click(clickFunction);
  return this;
}<commit_msg>Code cleanup<commit_after>var rest_in_place = {
  "main" :  function() {
    var e = this;
    var options = rest_in_place.resolveOptionsFor(e)

    function clickHandler() {
      var oldValue = e.html();
      e.html('<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + oldValue + '"></form>')
      e.find("input")[0].select();
      e.unbind('click', clickHandler)
      e.find("input").blur(function inputBlurHandler(){
        e.html(oldValue).click(clickHandler);
      })
      e.find("form").submit(function submitHandler(){
        jQuery.ajax({
          "url"        : options.url,
          "type"       : "post",
          "dataType"   : "text",
          "beforeSend" : function(xhr){ xhr.setRequestHeader("Accept", "application/json"); },
          "data"       : rest_in_place.requestData(options, e.find("input").val()),
          "success"    : function saveSuccessCallback(data, textStatus){
            jQuery.ajax({
              "url"        : options.url,
              "beforeSend" : function(xhr){ xhr.setRequestHeader("Accept", "application/json"); },
              "success"    : function loadSuccessCallback(data){
                if (jQuery.fn.jquery < "1.4") data = eval('(' + data + ')' );
                e.html(data[options.objectName][options.attributeName]);
                e.click(clickHandler);
              }
            });
          }
        });
        e.html("saving...");
        return false;
      })
    }
    this.click(clickHandler);
    return this;
  },

  "resolveOptionsFor" :  function(e){
    var url, objectName, attributeName;
    // Try parent supplied info
    e.parents().each(function(){
      url           = jQuery(this).attr("data-url");
      objectName    = jQuery(this).attr("data-object");
      attributeName = jQuery(this).attr("data-attribute");
    });
    // Try Rails-id based if parents did not explicitly supply something
    e.parents().each(function(){
      var res;
      if (res = this.id.match(/^(\w+)_(\d+)$/i)) {
        objectName = objectName || res[1];
      }
    });
    // Load own attributes (overrides all others)
    url           = e.attr("data-url")       || url    || document.location.pathname;
    objectName    = e.attr("data-object")    || objectName;
    attributeName = e.attr("data-attribute") || attributeName;

    return {"url"     : url,
      "objectName"    : objectName,
      "attributeName" : attributeName};
  },
  
  "requestData" : function(options, value) {
    var data = {};
    data["_method"] = "put";
    data[options.objectName] = {};
    data[options.objectName][options.attributeName] = value;
    if (window.rails_authenticity_token) {
      data["authenticity_token"] = window.rails_authenticity_token;
    }
    return data;
  }
}

jQuery.fn.rest_in_place = rest_in_place.main;
{'fraction_non_alphanumeric': 0.16818269789045867, 'fraction_numerical': 0.0019353590090961873, 'mean_word_length': 2.477792732166891, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4993262', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1541, 'n_words': 272}