Filter files to only plain-text

This commit is contained in:
riking 2015-05-16 21:18:07 -07:00
parent 30abc91a5c
commit d0b61ed23e

View File

@ -22,18 +22,15 @@ export default Em.Component.extend({
$this.on('dragover', function(e) { $this.on('dragover', function(e) {
if (e.preventDefault) e.preventDefault(); if (e.preventDefault) e.preventDefault();
//self.set('hover', true);
return false; return false;
}); });
$this.on('dragenter', function(e) { $this.on('dragenter', function(e) {
if (e.preventDefault) e.preventDefault(); if (e.preventDefault) e.preventDefault();
console.log('dragenter');
self.set('hover', self.get('hover') + 1); self.set('hover', self.get('hover') + 1);
return false; return false;
}); });
$this.on('dragleave', function(e) { $this.on('dragleave', function(e) {
if (e.preventDefault) e.preventDefault(); if (e.preventDefault) e.preventDefault();
console.log('dragleave');
self.set('hover', self.get('hover') - 1); self.set('hover', self.get('hover') - 1);
return false; return false;
}); });
@ -78,7 +75,20 @@ export default Em.Component.extend({
fileSelected(fileList) { fileSelected(fileList) {
const self = this; const self = this;
const numFiles = fileList.length; let files = [];
for (let i = 0; i < fileList.length; i++) {
files[i] = fileList[i];
}
const fileNameRegex = /\.(json|txt)$/;
files = files.filter(function(file) {
if (fileNameRegex.test(file.name)) {
return true;
}
if (file.type === "text/plain") {
return true;
}
return false;
});
const firstFile = fileList[0]; const firstFile = fileList[0];
this.set('loading', true); this.set('loading', true);