$(document).on("change", ".uploadProfileInput", function () {
var triggerInput = this;
var currentImg = $(this).closest(".pic-holder").find(".pic").attr("src");
var holder = $(this).closest(".pic-holder");
var wrapper = $(this).closest(".profile-pic-wrapper");
$(wrapper).find('[role="alert"]').remove();
var files = !!this.files ? this.files : [];
if (!files.length || !window.FileReader) {
return;
}
if (/^image/.test(files[0].type)) {
// only image file
var reader = new FileReader(); // instance of the FileReader
reader.readAsDataURL(files[0]); // read the local file
reader.onloadend = function () {
$(holder).addClass("uploadInProgress");
$(holder).find(".pic").attr("src", this.result);
$(holder).append(
'
Loading...
'
);
// Dummy timeout; call API or AJAX below
setTimeout(() => {
$(holder).removeClass("uploadInProgress");
$(holder).find(".upload-loader").remove();
// If upload successful
if (Math.random() < 0.9) {
$(wrapper).append(
'