var Uploader={
seconds:0,
minutes:0,
hours:0,
start_time:0,
upload_id:null,
total_upload_size:0,
total_kbytes:0,
toggle_upload_stats:0,
file_label_highlight_on:'#FFFFE0',
file_label_highlight_off:'#F9F9F9',
CPB_loop:false,
CPB_width:0,
CPB_bytes:0,
CPB_time_width:1000,
CPB_time_bytes:15,
CPB_hold:true,
CPB_byte_timer:null,
CPB_status_timer:null,
BPB_width_inc:0,
BPB_width_new:0,
BPB_width_old:0,
BPB_timer:null,
UP_timer:null,
progress_data:null,
check_allow_extensions_on_client:null,
check_disallow_extensions_on_client:null,
allow_extensions:null,
disallow_extensions:null,
check_file_name_format:null,
check_file_name_regex:null,
check_file_name_error_message:null,
max_file_name_chars:null,
min_file_name_chars:null,
check_null_file_count:1,
check_duplicate_file_count:1,
max_upload_slots:null,
cedric_progress_bar:0,
cedric_hold_to_sync:0,
bucket_progress_bar:1,
progress_bar_width:400,
block_ui_enabled:1,
show_percent_complete:1,
show_files_uploaded:null,
show_current_position:null,
show_current_file:null,
show_elapsed_time:null,
show_est_time_left:1,
show_est_speed:null,
IsStop:0,
getFileName:function(slot_value){
var index_of_last_slash = slot_value.lastIndexOf("\\");
if(index_of_last_slash < 1){ index_of_last_slash = slot_value.lastIndexOf("/"); }
var file_name = slot_value.slice(index_of_last_slash + 1, slot_value.length);
return file_name;
},
getFileExtension:function(slot_value){
var file_extension = slot_value.substring(slot_value.lastIndexOf(".") + 1, slot_value.length).toLowerCase();
return file_extension;
},
highlightFileLabel:function(file_label, color){ JQ("#" + file_label).css({background:color}); },
clearFileLabels:function(){
JQ("#upload_form").find(":file").each(function(){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_off);
});
},
// Check the file format before uploading
checkFileNameFormat:function(){
if(!Uploader.check_file_name_format){ return false; }
var found_error = false;
JQ("#upload_form").find(":file").each(function(){
if(JQ(this).val() !== ""){
var file_name = Uploader.getFileName(JQ(this).val());
if(file_name.length > Uploader.max_file_name_chars){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_on);
Uploader.showAlert("Error, file name cannot be more than " + Uploader.max_file_name_chars + " characters.", 500, 85, Uploader.block_ui_enabled);
found_error = true;
}
if(file_name.length < Uploader.min_file_name_chars){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_on);
Uploader.showAlert("Error, file name cannot be less than " + Uploader.min_file_name_chars + " characters.", 500, 85, Uploader.block_ui_enabled);
found_error = true;
}
if(!Uploader.check_file_name_regex.test(file_name)){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_on);
Uploader.showAlert(Uploader.check_file_name_error_message, 500, 85, Uploader.block_ui_enabled);
found_error = true;
}
}
});
return found_error;
},
// Check for legal file extentions
checkAllowFileExtensions:function(){
if(!Uploader.check_allow_extensions_on_client){ return false; }
var found_error = false;
JQ("#upload_form").find(":file").each(function(){
if(JQ(this).val() !== ""){
var file_extension = Uploader.getFileExtension(Uploader.getFileName(JQ(this).val()));
if(!file_extension.match(Uploader.allow_extensions)){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_on);
Uploader.showAlert('Sorry, uploading a file with the extension "' + file_extension + '" is not allowed.', 500, 85, Uploader.block_ui_enabled);
found_error = true;
}
}
});
return found_error;
},
// Check for illegal file extentions
checkDisallowFileExtensions:function(){
if(!Uploader.check_disallow_extensions_on_client){ return false; }
var found_error = false;
JQ("#upload_form").find(":file").each(function(){
if(JQ(this).val() !== ""){
var file_extension = Uploader.getFileExtension(Uploader.getFileName(JQ(this).val()));
if(file_extension.match(Uploader.disallow_extensions)){
Uploader.highlightFileLabel(JQ(this).attr("id") + "_label", Uploader.file_label_highlight_on);
Uploader.showAlert('Sorry, uploading a file with the extension "' + file_extension + '" is not allowed.', 500, 85, Uploader.block_ui_enabled);
found_error = true;
}
}
});
return found_error;
},
// Make sure the user selected at least one file
checkNullFileCount:function(){
if(!Uploader.check_null_file_count){ return false; }
var found_file = false;
JQ("#upload_form").find(':file').each(function(){
if(JQ(this).val() !== ""){ found_file = true; }
});
if(!found_file){
Uploader.showAlert("Please Choose A File To Upload.", 400, 80, Uploader.block_ui_enabled);
return true;
}
else{ return false; }
},
// Make sure the user is not uploading duplicate files
checkDuplicateFileCount:function(){
if(!Uploader.check_duplicate_file_count){ return false; }
var found_duplicate = false;
var file_count = 0;
var file_name_array = [];
JQ("#upload_form").find(":file").each(function(){
if(JQ(this).val() !== ""){
var obj = {};
obj.file_name = Uploader.getFileName(JQ(this).val());
obj.label_name = JQ(this).attr("id") + "_label";
file_name_array[file_count] = obj;
file_count++;
}
});
for(var i = 0; i < file_name_array.length; i++){
var obj_1 = file_name_array[i];
for(var j = 0; j < file_name_array.length; j++){
var obj_2 = file_name_array[j];
if(obj_1.file_name === obj_2.file_name && obj_1.label_name !== obj_2.label_name){
found_duplicate = true;
Uploader.highlightFileLabel(obj_1.label_name, Uploader.file_label_highlight_on);
Uploader.highlightFileLabel(obj_2.label_name, Uploader.file_label_highlight_on);
}
}
}
if(found_duplicate){
Uploader.showAlert("Duplicate upload files detected.", 400, 80, Uploader.block_ui_enabled);
return true;
}
else{ return false; }
},
showAlert:function(alert_message, alert_width, alert_height, block_ui_enabled){
if(!block_ui_enabled){ alert(alert_message); }
else{
alert_message = "
" + alert_message + "
";
JQ.blockUI({
message:alert_message,
css:{
width:alert_width+'px',
height:alert_height+'px',
top:(JQ(window).height() / 3) - (alert_height / 2) + 'px',
left:(JQ(window).width() / 2) - (alert_width / 2) + 'px',
textAlign:'center',
cursor:'default',
backgroundColor:'#EDEDED',
borderColor:'#D9D9D9',
color:'black',
font:'14px Arial',
fontWeight:'bold',
padding:'2px',
opacity:'1',
'-webkit-border-radius':'2px',
'-moz-border-radius':'2px'
},
overlayCSS:{
cursor:'default',
applyPlatformOpacityRules:true
}
});
}
},
showCGIOutput:function(CGI_message, reset_page){
Uploader.showAlert(CGI_message, 400, 80, Uploader.block_ui_enabled);
if(reset_page){ Uploader.resetFileUploadPage(); }
},
showDebugMessage:function(message){ JQ("#uploader_debug").append(message + "
"); },
showAlertMessage:function(message){ JQ("#uploader_alert").html(message); },
redirectAfterUpload:function(redirect_url, embedded_upload_results){
redirect_url = decodeURIComponent(redirect_url);
if(embedded_upload_results){
JQ(document).ready(function(){ JQ('#upload_container').html('
