59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
window.onload = function() {
|
|
$(document).ready(function(){
|
|
$('#file-selectbutton').click(function(e) {
|
|
$('#file').trigger('click');
|
|
});
|
|
|
|
$('#file-name').click(function(e) {
|
|
$('#file').trigger('click');
|
|
});
|
|
|
|
$('#file-name').on('dragenter', function(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
});
|
|
|
|
$('#file-name').on('dragover', function(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
});
|
|
|
|
$('#file-name').on('drop', function(e) {
|
|
e.preventDefault();
|
|
var files = e.originalEvent.dataTransfer.files;
|
|
$('#file')[0].files = files;
|
|
$(this).val(files[0].name);
|
|
});
|
|
|
|
$('#file').change(function(e) {
|
|
if ($(this)[0].files !== undefined)
|
|
{
|
|
var files = $(this)[0].files;
|
|
var name = '';
|
|
|
|
$.each(files, function(index, value) {
|
|
name += value.name+', ';
|
|
});
|
|
|
|
$('#file-name').val(name.slice(0, -2));
|
|
}
|
|
else // Internet Explorer 9 Compatibility
|
|
{
|
|
var name = $(this).val().split(/[\\/]/);
|
|
$('#file-name').val(name[name.length-1]);
|
|
}
|
|
});
|
|
|
|
if (typeof file_max_files !== 'undefined')
|
|
{
|
|
$('#file').closest('form').on('submit', function(e) {
|
|
if ($('#file')[0].files.length > file_max_files) {
|
|
e.preventDefault();
|
|
alert('You can upload a maximum of files');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|