1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
xhr: function(data) {
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', function(ev) {
console.log(ev);
var targetPercent = mediaType+'-ProgressBarPercent-'+incInputs;
console.log(targetPercent);
var targetCount = mediaType+'-ProgressBarCount-'+incInputs;
console.log(targetCount);
var targetWrap = mediaType+'-ProgressBarWrap-'+incInputs;
console.log(targetWrap);
var targetMsg = mediaType+'-MsgDisplay-'+incInputs;
console.log(targetMsg);
var targetCancel = mediaType+'-ProgressBarCancel-'+incInputs;
console.log(targetCancel);
if(mediaType == 'img'){
allowedExt = allowedImgExt;
allowedSize = allowedImgSize;
} else {
allowedExt = allowedVidExt;
allowedSize = allowedVidSize;
}
var uploadFile = checkFiles(fileID, mediaTypeID, allowedExt, suspExt, allowedSize);
var extractFileInfo = uploadFile[2];
// get file information
//var fileName = extractFileInfo[0];
var fileSize = extractFileInfo[1];
// get timestamp
var getStamp = ev.timeStamp;
console.log(getStamp);
var lComput = ev.lengthComputable;
//console.log('comput '+lComput);
var total = ev.total;
//console.log(total);
var loaded = ev.loaded;
var ratio = Math.floor(ev.loaded/(ev.total/100));
var percentage = ratio+'%';
console.log(percentage);
var classToAdd = '';
var classToRemove = '';
var msgDisplay = '';
var showSize = '';
switch(true){
case (ratio < 40):
classToRemove = 'progress-bar-custom';
classToAdd = 'progress-bar-danger';
msgDisplay = 'Uploading...';
showSize = 'Yes';
break;
case (ratio >= 40 && ratio < 60):
classToRemove = 'progress-bar-danger';
classToAdd = 'progress-bar-warning';
msgDisplay = 'Uploading...';
showSize = 'Yes';
break;
case (ratio >= 60 && ratio < 80):
classToRemove = 'progress-bar-warning';
classToAdd = 'progress-bar-info';
msgDisplay = 'Uploading...';
showSize = 'Yes';
break;
case (ratio >= 80 && ratio < 99):
classToRemove = 'progress-bar-info';
classToAdd = 'progress-bar-primary';
msgDisplay = 'Uploading...';
showSize = 'Yes';
break;
case (ratio >= 99 && ratio < 100):
classToRemove = 'progress-bar-primary';
classToAdd = 'progress-bar-success';
msgDisplay = 'Scanning in Process...';
showSize = 'No';
break;
case (ratio == 100):
classToRemove = 'progress-bar-primary';
classToAdd = 'progress-bar-success';
msgDisplay = 'Scanning in Process...';
showSize = 'No';
break;
} // end switch
var sizeUploaded = formatBytes(loaded)+' of '+formatBytes(fileSize)+' ';
if(showSize == 'Yes'){
msgDisplay = msgDisplay+' <br> '+sizeUploaded;
} else {
msgDisplay = msgDisplay;
}
console.log(targetPercent +' : add '+classToAdd);
console.log(targetPercent +' : del '+classToRemove);
$('#'+targetPercent).html(percentage).show();
//$('.progressBar').html(formatBytes(loaded)+' of '+formatBytes(fileSize)+' '+percentage).show();
//$('#'+targetCount).html(loaded+' KB of '+fileSize+' KB ').show();
//$('.alert').css('display', 'block')
$('#'+targetPercent).removeClass(classToRemove).addClass(classToAdd);
$('#'+targetPercent).css({
'width': percentage,
'color': '#ffffff',
'font-weight': 'bold'
});
$('#'+targetMsg).html(msgDisplay);
var getClasses = $('.progress-bar').attr('class');
console.log('classes '+getClasses);
/*
$('#'+targetWrap).css({
"background-color": background,
"width": percentage
});
*/
//$('#progressBar').css('width', (ev.loaded/(ev.total/100))+'%');
//console.log((ev.loaded/(ev.total/100)));
}, false);
//console.log(xhr);
return xhr;
}, |
Partager