<commit_before>= form_for @post, :html => { :class => "internal" } do |f|
  -if @post.errors.any?
    #error_explanation
      %h2= "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:"
      %ul
        - @post.errors.full_messages.each do |msg|
          %li= msg

  = f.text_field :title, :placeholder => "Post Title"
  = f.text_area :body, :placeholder => "Post Content"
  %p.graytext{:style => "font-size:15px"} Drag an image from your desktop into the text area to upload it to Imgur. 
  = f.submit "Save"
%script(type="text/javascript")
  $(document).ready(function(e) {

  var area = document.getElementById('post_body');

  function readFiles(files) {
  var fr = new FileReader();
  fr.onload = function(event) {
  var bsfData = event.target.result.slice(event.target.result.search(/\,/)+1,event.target.result.length);
  var dat = {
  image:bsfData,
  type:'base64'
  };
  $.ajax({
  type:"POST",
  data:dat,
  url:'https://api.imgur.com/3/image',
  headers: {
  Authorization: "Client-ID 6e0f35eb9a323aa"
  },
  dataType: "json",
  success:function(msg) {
  area.value += "<img src='"+msg.data.link+"'>";
  },
  error:function(errormsg) {
  console.log(errormsg);
  alert("Sorry, there was an error uploading the image." + errormsg.responseText);
  }});
  }
  fr.readAsDataURL(files[0]);
  }

  area.ondragover = function(e) {
  e.preventDefault();
  $(this).addClass('hover');
  }
  area.ondragend = function(e) {
  e.preventDefault();
  $(this).removeClass('hover');
  }
  area.ondrop = function(e) {
  if ($(this).hasClass('hover')) $(this).removeClass('hover')
  e.preventDefault();
  readFiles(e.dataTransfer.files);
  }
  });<commit_msg>Improved error catching and ui<commit_after>= form_for @post, :html => { :class => "internal" } do |f|
  -if @post.errors.any?
    #error_explanation
      %h2= "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:"
      %ul
        - @post.errors.full_messages.each do |msg|
          %li= msg

  = f.text_field :title, :placeholder => "Post Title"
  = f.text_area :body, :placeholder => "Post Content"
  %p.graytext{:style => "font-size:15px;"} 
    %span#supportIndicator Drag an image from your desktop 
    into the text area to upload it to 
    %span#uploadIndicator Imgur.
    %br/
    %span#message{:style => "display:none;font-size:10px;margin:5px"}
      Your browser supports drag and drop file uploads.
  = f.submit "Save"
  %script(type="text/javascript")
    $(document).ready(function(e) {
    var area = document.getElementById('post_body'); 
    var imgurIndicator = $('#uploadIndicator');
    var supportIndicator = $('#supportIndicator');
    var supported = true;

    var tests = {
    filereader:typeof FileReader != 'undefined',
    dnd:'draggable' in document.createElement('textarea'),
    formdata:!!window.FormData
    }

    function testSupport() {
    "filereader formdata".split(' ').forEach(function(api) {
    if (tests[api] === false) {
    supported = false;
    console.log(api)
    } 
    });
    if (!supported) {
    supportIndicator.css("color","#E04C7E");
    } else {
    supportIndicator.css("color","#00F000");
    }
    supportIndicator.css("cursor","help");
    }


    function readFiles(files) {
    var fr = new FileReader();
    fr.onload = function(event) {
    var bsfData = event.target.result.slice(event.target.result.search(/\,/)+1,event.target.result.length);
    var dat = {
    image:bsfData,
    type:'base64'
    };
    $.ajax({
    type:"POST",
    data:dat,
    url:'https://api.imgur.com/3/image',
    headers: {
    Authorization: "Client-ID <KEY>"
    },
    dataType: "json",
    success:function(msg) {
    handleStatus(msg,"success");
    },
    error:function(errormsg) {
    handleStatus(errormsg,"error");
    }
    });
    }
    fr.readAsDataURL(files[0]);
    }

    function handleStatus(msg,type) {
    if (type === "success") {
    imgurIndicator.css("color","#85bf25");
    area.value += "<img src='"+msg.data.link+"'>";
    }
    if (type === "error") {
    imgurIndicator.css("color","#E04C7E");
    console.log(msg);
    alert("Sorry, there was an error with your request:" + msg.responseText);
    }
    }

    area.ondragover = function(e) {
    e.preventDefault();
    $(this).addClass('hover');
    }
    area.ondragend = function(e) {
    e.preventDefault();
    $(this).removeClass('hover');
    }
    area.ondrop = function(e) {
    if ($(this).hasClass('hover')) $(this).removeClass('hover')
    e.preventDefault();
    readFiles(e.dataTransfer.files);
    }

    $('#supportIndicator').mouseover(function() {
    if (supported) {
    $('#message').text("Your browser supports drag and drop file uploads.");
    } else if (!supported) {
    $('#message').text("Your browser does not support drag and drop file uploads.");
    }
    $('#message').css("display","inline");
    });

    $('#supportIndicator').mouseout(function() {
    $('#message').css("display","none");
    });
    testSupport();
    });
{'fraction_non_alphanumeric': 0.17962037962037963, 'fraction_numerical': 0.008391608391608392, 'mean_word_length': 3.372052401746725, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '339239', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1664, 'n_words': 324}