Created
June 4, 2018 08:51
-
-
Save yasaryousuf/8c7ae1ad182586f0693a85624b0f658a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.doc input').fileupload( | |
{ | |
url: WP_Ajax.ajaxurl, | |
sequentialUploads: true, | |
formData: {action: 'upload_file'}, | |
add: function (e, data) { | |
var uploadErrors = []; | |
var acceptFileTypes = /\/(pdf|JPEG|JPG|TIFF|GIF|png|BMP|DOC|DOCX|XLS|XLSX|ODT|ODS)$/i; | |
if(data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) { | |
uploadErrors.push('File type not accepted'); | |
} | |
if (data.originalFiles[0]['size'] > 10000000) { | |
uploadErrors.push('Filesize too big. Maximum file size should be 10 MB'); | |
} | |
if(uploadErrors.length > 0) { | |
swal("", uploadErrors.join("\n"), "error"); | |
} else { | |
data.context = $('<p/>').text('Uploading...').appendTo(document.body); | |
data.submit(); | |
} | |
}, | |
done: function(e, data){ | |
var html = data.result + '<a class="remove-file"><i class="fa fa-minus-circle"></i></a>'; | |
$(e.target).closest('.doc').find('.file-name').html(html); | |
documentProgress(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment