var _Root = {};

_Root.attrs = {};

_Root.allowFileDrop = function(cb){
  _Root.attrs.ondragover = function(e){
    e.preventDefault();
    };
  _Root.attrs.ondrop = function(e){
    e.preventDefault();  // don't open the file in the browser
    var files = [];
    
    // some browsers use `.items` and some use `.files`, so check for both:
    if (e.dataTransfer.items) {
      for (var i = 0; i < e.dataTransfer.items.length; i++) {
        if (e.dataTransfer.items[i].kind === 'file') {  // If dropped items aren't files, reject them
          files.push( e.dataTransfer.items[i].getAsFile() );
          }
        }
      }
    else {
      for (var i = 0; i < e.dataTransfer.files.length; i++) {
        files.push( e.dataTransfer.files[i] );
        }
      }
    for(var i=0, file=null; i<files.length; i++){
      file = files[i]
      cb(file)
      //console.log(file.name);
      }
    }
  };

_Root.unallowFileDrop = function(){
  _Root.attrs.ondragover = null;
  _Root.attrs.ondrop = null;
  };

export default _Root;