$( document ).ready(function() {
//Custom file upload
$.fn.customFileInput = function(){
var fileInput = $(this);
fileInput.val('');
fileInput.each(function() {
var el = $(this);
var defText = 'Перетащите сюда ваш файл';
var upload = $('
', el);
var uploadFeedback = $('', el).appendTo(upload);
el.bind('change',function() {
var fileName = $(this).val().split(/\\/).pop();
var fileExt = 'custom_upload_ext-' + fileName.split('.').pop().toLowerCase();
uploadFeedback
.html('')
.removeClass(uploadFeedback.data('fileExt') || '')
.addClass('file_selected');
if( $(this).parent('.custom_upload').find('.input').val() == '' )
$('.custom_upload_button', this).removeClass('file_selected').html('');
if( $('.custom_upload_multiple .custom_upload_wrap input').val() !== '' ) {
$(this).after('');
$('.custom_upload_multiple').append('');
$('.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('');
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(''+defText+'
');
$(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();
});
});