mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/region-edoc.git
synced 2026-01-24 06:05:39 +03:00
66 lines
3.0 KiB
JavaScript
66 lines
3.0 KiB
JavaScript
$( document ).ready(function() {
|
|
//Custom file upload
|
|
|
|
$.fn.customFileInput = function(){
|
|
var fileInput = $(this);
|
|
|
|
fileInput.val('');
|
|
fileInput.each(function() {
|
|
var el = $(this);
|
|
var defText = 'Перетащите сюда ваш файл';
|
|
var upload = $('<div class="custom_upload"></div>', el);
|
|
var uploadFeedback = $('<div class="custom_upload_button TABLE_type"><div><p><div class="i_upload-1"></div>'+defText+'</p></div></div>', el).appendTo(upload);
|
|
|
|
el.bind('change',function() {
|
|
var fileName = $(this).val().split(/\\/).pop();
|
|
var fileExt = 'custom_upload_ext-' + fileName.split('.').pop().toLowerCase();
|
|
|
|
uploadFeedback
|
|
.html('<div><p>'+fileName+'</p></div>')
|
|
.removeClass(uploadFeedback.data('fileExt') || '')
|
|
.addClass('file_selected');
|
|
|
|
if( $(this).parent('.custom_upload').find('.input').val() == '' )
|
|
$('.custom_upload_button', this).removeClass('file_selected').html('<div><p><div class="i_upload-1"></div>'+defText+'</p></div>');
|
|
|
|
if( $('.custom_upload_multiple .custom_upload_wrap input').val() !== '' ) {
|
|
$(this).after('<div class="custom_upload_disable"></div>');
|
|
$('.custom_upload_multiple').append('<div class="custom_upload_wrap"><input type="file" value="" name="upl[]"></div>');
|
|
$('.custom_upload_multiple').find('.custom_upload_wrap:last').hide(0);
|
|
$('.custom_upload_multiple').find('.custom_upload_wrap:last').fadeIn(400);
|
|
$('.custom_upload_multiple').find('.custom_upload_wrap:last').find('input').customFileInput();
|
|
}
|
|
|
|
if(uploadFeedback.hasClass('file_selected')) {
|
|
upload.find('.custom_upload_delete').fadeIn(400);
|
|
}
|
|
else upload.find('.custom_upload_delete').hide(0);
|
|
});
|
|
|
|
upload.mousemove(function(e) {
|
|
el.css({ 'left' : e.pageX - $(this).offset().left - el.outerWidth(true) + 30 });
|
|
}).insertAfter(el);
|
|
|
|
el.appendTo(upload);
|
|
|
|
upload.append('<div class="custom_upload_delete"></div>');
|
|
upload.find('.custom_upload_delete').hide(0);
|
|
|
|
$('.custom_upload_delete').click(function(){
|
|
$(this).parent('.custom_upload').find('.input').val('');
|
|
$(this).parent('.custom_upload').find('.custom_upload_button').removeClass('file_selected').html('<i class="i_upload-1"></i><p>'+defText+'</p>');
|
|
$(this).hide(0);
|
|
});
|
|
|
|
$('.custom_upload_multiple .custom_upload_delete').click(function(){
|
|
$(this).parents('.custom_upload_wrap').remove();
|
|
});
|
|
});
|
|
return $(this);
|
|
};
|
|
|
|
$('.custom_upload_wrap').each(function(index, element) {
|
|
$('input', this).customFileInput();
|
|
});
|
|
|
|
}); |