start breaking out a ui feature to set an input step (#253)

* start

* refactoring

* working

* version bump
This commit is contained in:
Jeffrey Warren
2018-05-09 13:49:11 -04:00
committed by GitHub
parent 6ce78f87f4
commit 630eb773de
8 changed files with 122 additions and 57 deletions

49
src/ui/SetInputStep.js Normal file
View File

@@ -0,0 +1,49 @@
function setInputStepInit(_sequencer) {
return function setInputStep(options) {
var dropzone = $(options.dropZoneSelector);
var fileInput = $(options.fileInputSelector);
onLoad = options.onLoad;
var reader = new FileReader();
function handleFile(e) {
e.preventDefault();
e.stopPropagation(); // stops the browser from redirecting.
if (e.target && e.target.files) var file = e.target.files[0];
else var file = e.dataTransfer.files[0];
if(!file) return;
var reader = new FileReader();
reader.onload = onLoad;
reader.readAsDataURL(file);
}
fileInput.on('change', handleFile);
dropzone[0].addEventListener('drop', handleFile, false);
dropzone.on('dragover', function onDragover(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}, false);
dropzone.on('dragenter', function onDragEnter(e) {
dropzone.addClass('hover');
});
dropzone.on('dragleave', function onDragLeave(e) {
dropzone.removeClass('hover');
});
}
}
module.exports = setInputStepInit;