Detect that dragged files are teams

Previously, due to the HTML5 drag-and-drop API's security model, we
couldn't tell if a dragged file was a team or not. This new code makes
the check slightly more reliable.
This commit is contained in:
Guangcong Luo
2016-01-18 16:47:42 -08:00
parent 8be8204c61
commit 5fcb16b163

View File

@@ -34,16 +34,20 @@
e.preventDefault();
if (!app.dragging && app.curRoom.id === 'teambuilder') {
if (e.originalEvent.dataTransfer.files && e.originalEvent.dataTransfer.files[0]) {
var file = e.originalEvent.dataTransfer.files[0];
var dataTransfer = e.originalEvent.dataTransfer;
if (dataTransfer.files && dataTransfer.files[0]) {
var file = dataTransfer.files[0];
if (file.name.slice(-4) === '.txt') {
// Someone dragged in a .txt file, hand it to the teambuilder
app.curRoom.defaultDragEnterTeam(e);
}
} else {
// security doesn't let us read the filename :(
// we'll just have to assume it's a team
app.curRoom.defaultDragEnterTeam(e);
} else if (dataTransfer.items && dataTransfer.items[0]) {
// no files or no permission to access files
var item = dataTransfer.items[0];
if (item.kind === 'file' && item.type === 'text/plain') {
// Someone dragged in a .txt file, hand it to the teambuilder
app.curRoom.defaultDragEnterTeam(e);
}
}
}