<commit_before>ImageUpload = {

  // construct the iframe object that will store the form result
  frame : function(c) {
    var n = 'f' + Math.floor(Math.random() * 99999);
    var i = new Element('iframe', { style: 'display:none', src: 'about:blank', id: n, name: n, onload: "ImageUpload.loaded('"+n+"')" });
    var d = new Element('div');
    d.appendChild(i);
    document.body.appendChild(d);

    if (c && typeof(c.onComplete) == 'function') {
      i.onComplete = c.onComplete;
    }

    return n;
  },

  // set target attribute to form, so that its result is loaded in the iframe,
  // keeping current page open
  form : function(f, name) {
    f.setAttribute('target', name);
  },

  // submit the form
  submit : function(f, c) {
    if (!ImageUpload.validateFilename()) {
      $('image_selection').down('.image_form_error').show();
      return false;
    }
    $('image_selection').down('.image_form_error').hide();
    var upload_id = ImageUpload.frame(c);
    ImageUpload.form(f, upload_id);
    if (c && typeof(c.onStart) == 'function') {
      return c.onStart(upload_id, f);
    } else {
      return true;
    }
  },

  // called when the iframe has finished loading
  loaded : function(id) {
    var i = $(id);
    var d;
    if (i.contentDocument) {
      d = i.contentDocument;
    } else if (i.contentWindow) {
      d = i.contentWindow.document;
    } else {
      d = window.frames[id].document;
    }

    if (d.location.href == 'about:blank') {
      return;
    }

    if (typeof(i.onComplete) == 'function') {
      i.onComplete(id, d.body.innerHTML);
    }
  },

  validateFilename : function() {
    var reg = /\.(png|jpeg|jpg|gif|svg)$/i;
    // test if file api is implemented
    if ($('image_file').files) {
      var files = $('image_file').files;
      if (files.length > 4) return false;
      for (var i = 0; i < files.length; i++) {
        if (!reg.test(files[i].name)) return false;
      }
      return true;
    } else {
      $name = $F('image_file');
      if (name == '') { return false; }
      return reg.test(name);
    }
  },

  validateImageForms : function(pe) {
    if ($('MB_content') === null) {
      pe.stop();<commit_msg>image upload for browser that don't support file api<commit_after>ImageUpload = {

  // construct the iframe object that will store the form result
  frame : function(c) {
    var n = 'f' + Math.floor(Math.random() * 99999);
    var i = new Element('iframe', { style: 'display:none', src: 'about:blank', id: n, name: n, onload: "ImageUpload.loaded('"+n+"')" });
    var d = new Element('div');
    d.appendChild(i);
    document.body.appendChild(d);

    if (c && typeof(c.onComplete) == 'function') {
      i.onComplete = c.onComplete;
    }

    return n;
  },

  // set target attribute to form, so that its result is loaded in the iframe,
  // keeping current page open
  form : function(f, name) {
    f.setAttribute('target', name);
  },

  // submit the form
  submit : function(f, c) {
    if (!ImageUpload.validateFilename()) {
      $('image_selection').down('.image_form_error').show();
      return false;
    }
    $('image_selection').down('.image_form_error').hide();
    var upload_id = ImageUpload.frame(c);
    ImageUpload.form(f, upload_id);
    if (c && typeof(c.onStart) == 'function') {
      return c.onStart(upload_id, f);
    } else {
      return true;
    }
  },

  // called when the iframe has finished loading
  loaded : function(id) {
    var i = $(id);
    var d;
    if (i.contentDocument) {
      d = i.contentDocument;
    } else if (i.contentWindow) {
      d = i.contentWindow.document;
    } else {
      d = window.frames[id].document;
    }

    if (d.location.href == 'about:blank') {
      return;
    }

    if (typeof(i.onComplete) == 'function') {
      i.onComplete(id, d.body.innerHTML);
    }
  },

  validateFilename : function() {
    var reg = /\.(png|jpeg|jpg|gif|svg)$/i;
    // test if file api is implemented
    if ($('image_file').files) {
      var files = $('image_file').files;
      if (files.length > 4) return false;
      for (var i = 0; i < files.length; i++) {
        if (!reg.test(files[i].name)) return false;
      }
      return true;
    } else {
      name = $F('image_file');
      if (name == '') { return false; }
      return reg.test(name);
    }
  },

  validateImageForms : function(pe) {
    if ($('MB_content') === null) {
      pe.stop();
{'fraction_non_alphanumeric': 0.167574931880109, 'fraction_numerical': 0.003178928247048138, 'mean_word_length': 2.5668016194331984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3196267', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1444, 'n_words': 367}