<commit_before>
/**
 * Module dependencies.
 */

var Emitter = require('emitter')
  , classes = require('classes')
  , Upload = require('upload')
  , events = require('events')

/**
 * Expose `Dropload`.
 */

module.exports = Dropload;

/**
 * Types.
 */

var typeMap = {
  'text/plain': 'text',
  'text/uri-list': 'url',
  'text/html': 'html'
};

/**
 * Initialize a drop point
 * on the given `el`.
 *
 * Emits:
 *
 *   - `error` on validation error
 *   - `upload` passing an `Upload`
 *
 * @param {Element} el
 * @api public
 */

function Dropload(el) {
  if (!(this instanceof Dropload)) return new Dropload(el);
  Emitter.call(this);
  this.el = el;
  this.classes = classes(el);
  this.events = events(el, this);
  this.events.bind('drop');
  this.events.bind('dragenter');
  this.events.bind('dragleave');
  this.events.bind('dragover');
}

/**
 * Mixin emitter.
 */

Emitter(Dropload.prototype);

/**
 * Unbind event handlers.
 *
 * @api public
 */

Dropload.prototype.unbind = function(){
  this.events.unbind();
};

/**
 * Dragenter handler.
 */

Dropload.prototype.ondragenter = function(e){
  this.classes.add('over');
};

/**
 * Dragover handler.
 */

Dropload.prototype.ondragover = function(e){
  e.preventDefault();
};

/**
 * Dragleave handler.
 */

Dropload.prototype.ondragleave = function(e){
  this.classes.remove('over');
};

/**
 * Drop handler.
 */

Dropload.prototype.ondrop = function(e){
  e.stopPropagation();
  e.preventDefault();
  this.classes.remove('over');
  var items = e.dataTransfer.items;
  var files = e.dataTransfer.files;
  if (items) this.drop(items);
  if (files) this.upload(files);
};

/**
 * Handle the given `items`.
 *
 * @param {DataTransferItemList}
 * @api private
 */

Dropload.prototype.drop = function(items){
  for (var i = 0; i < items.length; i++) {
    var item = items[i];
    if (item.webkitGetAsEntry) {
      this.walkEntry(item.webkitGetAsEntry());
    } else {
      this.dropItem(item);
    }
  }
};

/**
 * Walk file entry recursively.
 *
 * @param {FileEntry} item
 * @api private
 */

Dropload.prototype.walkEntry = function(item){
  var self = this;

  if (item.isFile) {
    return item.file(function(file){
      file.entry = item;
      self.upload([file]);
    });
  }

  if (item.isDirectory) {
    var dir = item.createReader();
    dir.readEntries(function(entries){
      for (var i = 0; i < entries.length; i++) {
        var name = entries[i].name;
        if ('.' == name[0]) continue;
        self.walkEntry(entries[i]);
      }
    })
  }
};

/**
 * Handle `item`.
 *
 * @param {Object} item
 * @api private
 */

Dropload.prototype.dropItem = function(item){
  var self = this;<commit_msg>rename a few methods<commit_after>
/**
 * Module dependencies.
 */

var Emitter = require('emitter')
  , classes = require('classes')
  , Upload = require('upload')
  , events = require('events')

/**
 * Expose `Dropload`.
 */

module.exports = Dropload;

/**
 * Types.
 */

var typeMap = {
  'text/plain': 'text',
  'text/uri-list': 'url',
  'text/html': 'html'
};

/**
 * Initialize a drop point
 * on the given `el`.
 *
 * Emits:
 *
 *   - `error` on validation error
 *   - `upload` passing an `Upload`
 *
 * @param {Element} el
 * @api public
 */

function Dropload(el) {
  if (!(this instanceof Dropload)) return new Dropload(el);
  Emitter.call(this);
  this.el = el;
  this.classes = classes(el);
  this.events = events(el, this);
  this.events.bind('drop');
  this.events.bind('dragenter');
  this.events.bind('dragleave');
  this.events.bind('dragover');
}

/**
 * Mixin emitter.
 */

Emitter(Dropload.prototype);

/**
 * Unbind event handlers.
 *
 * @api public
 */

Dropload.prototype.unbind = function(){
  this.events.unbind();
};

/**
 * Dragenter handler.
 */

Dropload.prototype.ondragenter = function(e){
  this.classes.add('over');
};

/**
 * Dragover handler.
 */

Dropload.prototype.ondragover = function(e){
  e.preventDefault();
};

/**
 * Dragleave handler.
 */

Dropload.prototype.ondragleave = function(e){
  this.classes.remove('over');
};

/**
 * Drop handler.
 */

Dropload.prototype.ondrop = function(e){
  e.stopPropagation();
  e.preventDefault();
  this.classes.remove('over');
  var items = e.dataTransfer.items;
  var files = e.dataTransfer.files;
  if (items) this.items(items);
  if (files) this.upload(files);
};

/**
 * Handle the given `items`.
 *
 * @param {DataTransferItemList}
 * @api private
 */

Dropload.prototype.items = function(items){
  for (var i = 0; i < items.length; i++) {
    var item = items[i];
    if (item.webkitGetAsEntry) {
      this.walkEntry(item.webkitGetAsEntry());
    } else {
      this.item(item);
    }
  }
};

/**
 * Walk file entry recursively.
 *
 * @param {FileEntry} item
 * @api private
 */

Dropload.prototype.walkEntry = function(item){
  var self = this;

  if (item.isFile) {
    return item.file(function(file){
      file.entry = item;
      self.upload([file]);
    });
  }

  if (item.isDirectory) {
    var dir = item.createReader();
    dir.readEntries(function(entries){
      for (var i = 0; i < entries.length; i++) {
        var name = entries[i].name;
        if ('.' == name[0]) continue;
        self.walkEntry(entries[i]);
      }
    })
  }
};

/**
 * Handle `item`.
 *
 * @param {Object} item
 * @api private
 */

Dropload.prototype.item = function(item){
  var self = this;
{'fraction_non_alphanumeric': 0.18297474275023387, 'fraction_numerical': 0.0011225444340505146, 'mean_word_length': 3.043872919818457, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2285988', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1881, 'n_words': 384}