mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Refactored file dropper
This commit is contained in:
@ -3,9 +3,14 @@ App.Controls = App.Controls || {};
|
||||
|
||||
App.Controls.FileDropper = function(
|
||||
$fileInput,
|
||||
onChange,
|
||||
_,
|
||||
jQuery) {
|
||||
|
||||
var options = {
|
||||
onChange: null,
|
||||
setNames: false,
|
||||
};
|
||||
|
||||
var $dropDiv = jQuery('<div class="file-handler"></div>');
|
||||
var allowMultiple = $fileInput.attr('multiple');
|
||||
$dropDiv.html((allowMultiple ? 'Drop files here!' : 'Drop file here!') + '<br/>Or just click on this box.');
|
||||
@ -37,9 +42,28 @@ App.Controls.FileDropper = function(
|
||||
window.alert('Cannot select multiple files.');
|
||||
return;
|
||||
}
|
||||
onChange(files);
|
||||
if (typeof(options.onChange) !== 'undefined') {
|
||||
options.onChange(files);
|
||||
}
|
||||
if (options.setNames && !allowMultiple) {
|
||||
$dropDiv.text(files[0].name);
|
||||
}
|
||||
}
|
||||
|
||||
function readAsDataURL(file, callback) {
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = function() {
|
||||
callback(reader.result);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
_.extend(options, {
|
||||
readAsDataURL: readAsDataURL,
|
||||
});
|
||||
|
||||
return options;
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('fileDropper', App.Controls.FileDropper);
|
||||
|
Reference in New Issue
Block a user