mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
Rearrange handleDrop() to flow more naturally
This commit is contained in:
parent
fe24a5e15a
commit
916ec7aace
@ -59,23 +59,21 @@ let FileDragAndDrop = React.createClass({
|
|||||||
handleDrop(event) {
|
handleDrop(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
let files;
|
|
||||||
|
|
||||||
if(this.props.dropzoneInactive) {
|
if (!this.props.dropzoneInactive) {
|
||||||
return;
|
let files;
|
||||||
|
|
||||||
|
// handle Drag and Drop
|
||||||
|
if(event.dataTransfer && event.dataTransfer.files.length > 0) {
|
||||||
|
files = event.dataTransfer.files;
|
||||||
|
} else if(event.target.files) { // handle input type file
|
||||||
|
files = event.target.files;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof this.props.onDrop === 'function' && files) {
|
||||||
|
this.props.onDrop(files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle Drag and Drop
|
|
||||||
if(event.dataTransfer && event.dataTransfer.files.length > 0) {
|
|
||||||
files = event.dataTransfer.files;
|
|
||||||
} else if(event.target.files) { // handle input type file
|
|
||||||
files = event.target.files;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof this.props.onDrop === 'function' && files) {
|
|
||||||
this.props.onDrop(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDeleteFile(fileId) {
|
handleDeleteFile(fileId) {
|
||||||
@ -107,28 +105,25 @@ let FileDragAndDrop = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleOnClick() {
|
handleOnClick() {
|
||||||
let evt;
|
// do not propagate event if the drop zone's inactive,
|
||||||
// when multiple is set to false and the user already uploaded a piece,
|
// for example when multiple is set to false and the user already uploaded a piece
|
||||||
// do not propagate event
|
if (!this.props.dropzoneInactive) {
|
||||||
if(this.props.dropzoneInactive) {
|
let evt;
|
||||||
// if there is a handle function for doing stuff
|
|
||||||
// when the dropzone is inactive, then call it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
evt = new MouseEvent('click', {
|
evt = new MouseEvent('click', {
|
||||||
view: window,
|
view: window,
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: true
|
cancelable: true
|
||||||
});
|
});
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// For browsers that do not support the new MouseEvent syntax
|
// For browsers that do not support the new MouseEvent syntax
|
||||||
evt = document.createEvent('MouseEvents');
|
evt = document.createEvent('MouseEvents');
|
||||||
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
|
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refs.fileSelector.getDOMNode().dispatchEvent(evt);
|
this.refs.fileSelector.getDOMNode().dispatchEvent(evt);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user