var fileUploadErrors = {
maxFileSize: "File is too big",
minFileSize: "File is too small",
acceptFileTypes: "This file type is not supported",
maxNumberOfFiles: "Exceeded maximum number of files",
uploadedBytes: "File upload limit exceeded",
emptyResult: "Empty file upload result"
};
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
_initTemplates: function () {
this.options.uploadTemplate = function (o) {
var rows = $();
$.each(o.files, function (index, file) {
console.log('-->', file, file.name.split('.').pop(), o.options.acceptFileTypes);
if(o.options.acceptFileTypes !== undefined && !o.options.acceptFileTypes.test(file.type)){
file.error = fileUploadErrors.acceptFileTypes;
} else if(o.options.maxFileSize !== undefined && file.size > o.options.maxFileSize){
file.error = fileUploadErrors.maxFileSize;
}
file.isImage = /^image/.test(file.type);
console.log('--2->', file);
var hideFileTitle = o.options.hideFileTitle !== undefined
var row = $('
' +
(file.isImage ? '
'
: '
') +
'
' +
'
'+
(file.error ? '' : '
') +
'
' +
'
' +
'
' +
' ' +
'
' +
'
');
row.find('.file-name').text(file.name);
row.find('.file-size').text(o.formatFileSize(file.size));
if (file.error) {
row.addClass('error')
row.find('.error-message').text(file.error);
}
rows = rows.add(row);
});
return rows;
}
this.options.downloadTemplate = function (o) {
var rows = $();
$.each(o.files, function (index, file) {
var hideFileTitle = o.options.hideFileTitle !== undefined;
var hideFileSize = o.options.hideFileSize !== undefined;
var hideFileSize = o.options.hideFileSize !== undefined;
var row = $(
'' +
(file.isImage ? '
'
: '
') +
'
' +
(hideFileTitle || file.error ? '': '
') +
'
' +
'
' +
'
' +
''+
'' +
'
'+
'
' );
if (file.error) {
//
row.find('.preview').append('')
row.addClass('error')
row.find('.error-message').text(file.error);
} else {
console.log('>>', file);
if(file.isImage){
row.find('.preview').append('')
.find('img').prop('src', file.previewUrl).end()
.find('a').attr({
target:'_blank'
}).prop('rel', 'gallery').prop('href', file.url);
}
}
rows = rows.add(row);
});
return rows;
}
}
});