<commit_before>jQuery.noConflict();
(function($) {
  $.plugin('card_editor', (function() {
    var baseUrl = "/api/v2/projects/";
    var cardElement;
    function card_uri() {
      return baseUrl + window.mingleProject + "/cards/" + window.number + '.xml';
    }
    function card_attachments_url() {
      return baseUrl + window.mingleProject + "/cards/" + window.number + "/attachments.xml";
    }
    function ajaxErrorHandler(x) {
      console.log(x);
      cardElement.card_editor('status', 'error');
    }
    var upload_dropfile = function(wikimateElement) {
      var dialog, progressbar;
      return {
        post_url: card_attachments_url(),
        field_name: 'file',
        start: function(xhr, file) {
          progressbar = $('<div/>').progressbar({ value: 0 });
          dialog = $('<div/>').append(progressbar).dialog({
            title: "Uploading",
            modal: true
          });
          xhr.upload.addEventListener("progress", function (e) {
            if (e.lengthComputable) {
              var loaded = Math.ceil((e.loaded / e.total) * 100);
              progressbar.progressbar("value", loaded);
            }
          }, false);
        },
        complete: function(result, file) {
          if (dialog) {
            dialog.dialog('close');
            dialog.remove();
            dialog = null;
            var file_name = file.name.replace(/ /g, '_');
            var item = (/image/i).test(file.type) ? {type: 'image', text: "!" + file_name + "!"} : {type: 'paragraph', text: "[[" + file_name + "]]"};
            wikimateElement.wikimate("newItem", item).story_item('save');
          }
        }
      };
    }

    return {
      init: function(card) {
        window.mingleProject = card.project;
        window.number = card.number;
        cardElement = this;
        this.card_editor('status', 'loading');
        var $this = this.addClass('card_editor');
        $.ajax({
          url: card_uri(),
          dataType: 'xml',
          success: function(xmlDoc) {
            $this.card_editor('initWikiMate', xmlDoc);
            $this.card_editor('defaultStoryItemTypeConfiguration');
            $this.card_editor('status', 'idle');
          },
          failure: ajaxErrorHandler
        });
        return this;
      },

      initWikiMate: function(cardDoc) {
        var editingCard = $(cardDoc);<commit_msg>fix attachment file name used in image and attachment content: parse it out from response after uploaded successfully<commit_after>jQuery.noConflict();
(function($) {
  $.plugin('card_editor', (function() {
    var baseUrl = "/api/v2/projects/";
    var cardElement;
    function card_uri() {
      return baseUrl + window.mingleProject + "/cards/" + window.number + '.xml';
    }
    function card_attachments_url() {
      return baseUrl + window.mingleProject + "/cards/" + window.number + "/attachments.xml";
    }
    function ajaxErrorHandler(x) {
      console.log(x);
      cardElement.card_editor('status', 'error');
    }
    var upload_dropfile = function(wikimateElement) {
      var dialog, progressbar;
      return {
        post_url: card_attachments_url(),
        field_name: 'file',
        start: function(xhr, file) {
          progressbar = $('<div/>').progressbar({ value: 0 });
          dialog = $('<div/>').append(progressbar).dialog({
            title: "Uploading",
            modal: true
          });
          xhr.upload.addEventListener("progress", function (e) {
            if (e.lengthComputable) {
              var loaded = Math.ceil((e.loaded / e.total) * 100);
              progressbar.progressbar("value", loaded);
            }
          }, false);
        },
        complete: function(result, file) {
          if (dialog) {
            dialog.dialog('close');
            dialog.remove();
            dialog = null;
            var created_location = result.target.getResponseHeader('Location');
            var file_name = _.last(created_location.split("/"));
            var item = (/image/i).test(file.type) ? {type: 'image', text: "!" + file_name + "!"} : {type: 'paragraph', text: "[[" + file_name + "]]"};
            wikimateElement.wikimate("newItem", item).story_item('save');
          }
        }
      };
    }

    return {
      init: function(card) {
        window.mingleProject = card.project;
        window.number = card.number;
        cardElement = this;
        this.card_editor('status', 'loading');
        var $this = this.addClass('card_editor');
        $.ajax({
          url: card_uri(),
          dataType: 'xml',
          success: function(xmlDoc) {
            $this.card_editor('initWikiMate', xmlDoc);
            $this.card_editor('defaultStoryItemTypeConfiguration');
            $this.card_editor('status', 'idle');
          },
          failure: ajaxErrorHandler
        });
        return this;
      },

      initWikiMate: function(cardDoc) {
        var editingCard = $(cardDoc);
{'fraction_non_alphanumeric': 0.14938346472609662, 'fraction_numerical': 0.002021427127552052, 'mean_word_length': 2.1139081183134047, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '3586668', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1386, 'n_words': 274}