diff --git a/examples/demo.js b/examples/demo.js index e329094f7f..3199fe0656 100644 --- a/examples/demo.js +++ b/examples/demo.js @@ -24,5 +24,9 @@ window.onload = function() { $('body').on('click', 'button.remove', ui.removeStepUi); // image selection and drag/drop handling from examples/lib/imageSelection.js - setupFileHandling(sequencer); + sequencer.setInputStep({ + dropZoneSelector: "#dropzone", + fileInputSelector: "#fileInput", + step: sequencer.images.image1.steps[0] + }); }; diff --git a/examples/lib/imageSelection.js b/examples/lib/imageSelection.js deleted file mode 100644 index b4cb149c26..0000000000 --- a/examples/lib/imageSelection.js +++ /dev/null @@ -1,50 +0,0 @@ -function setupFileHandling(_sequencer, dropzoneId, fileInputId) { - - dropzoneId = dropzoneId || "dropzone"; - var dropzone = $('#' + dropzoneId); - - fileInputId = fileInputId || "fileInput"; - var fileInput = $('#' + fileInputId); - - 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 = function onFileReaderLoad() { - var loadStep = _sequencer.images.image1.steps[0]; - loadStep.output.src = reader.result; - _sequencer.run(0); - loadStep.options.step.imgElement.src = reader.result; - } - - 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'); - }); - -} diff --git a/src/ImageSequencer.js b/src/ImageSequencer.js index 25dc99d928..f377d0db47 100644 --- a/src/ImageSequencer.js +++ b/src/ImageSequencer.js @@ -220,7 +220,9 @@ ImageSequencer = function ImageSequencer(options) { //other functions log: log, objTypeOf: objTypeOf, - copy: copy + copy: copy, + + setInputStep: require('./ui/SetInputStep')(sequencer) } } diff --git a/src/ui/setInputStep.js b/src/ui/setInputStep.js new file mode 100644 index 0000000000..501fe54c23 --- /dev/null +++ b/src/ui/setInputStep.js @@ -0,0 +1,55 @@ +function setInputStepInit(_sequencer) { + + return function setInputStep(options) { + + var dropzone = $(options.dropZoneSelector); + var fileInput = $(fileInputId); + step = options.step; + + onLoad = options.onLoad || function onFileReaderLoad() { + var loadStep = ; + step.output.src = reader.result; + _sequencer.run(0); + step.options.step.imgElement.src = reader.result; + } + + 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;