Uploadify:html
BUG1:文件上传后,点击“取消”或“取消全部上传”,而后上传同一个文件,提示“文件已存在”this
修改方法:htm
找到源码中cancel取消方法:(添加代码)队列
cancel: function (fileID, supressEvent) {rem
var args = arguments;get
this.each(function () {源码
// Create a reference to the jQuery DOM object文件上传
var $this = $(this),it
swfuploadify = $this.data('uploadify'),io
settings = swfuploadify.settings,
delay = -1;
delete swfuploadify.queueData.files[fileID];
if (args[0]) {
// Clear the queue
if (args[0] == '*') {
var queueItemCount = swfuploadify.queueData.queueLength;
$('#' + settings.queueID).find('.uploadify-queue-item').each(function () {
delay++;
if (args[1] === true) {
swfuploadify.cancelUpload($(this).attr('id'), false);
} else {
swfuploadify.cancelUpload($(this).attr('id'));
}
/* 添加代码 */
delete swfuploadify.queueData.files[$(this).attr('id')];
swfuploadify.queueData.queueLength = swfuploadify.queueData.queueLength - 1;
/* 添加结束 */
$(this).find('.data').removeClass('data').html(' - Cancelled');
$(this).find('.uploadify-progress-bar').remove();
$(this).delay(1000 + 100 * delay).fadeOut(500, function () {
$(this).remove();
});
});
swfuploadify.queueData.queueSize = 0;
swfuploadify.queueData.queueLength = 0;
// Trigger the onClearQueue event
if (settings.onClearQueue) settings.onClearQueue.call($this, queueItemCount);
} else {
for (var n = 0; n < args.length; n++) {
swfuploadify.cancelUpload(args[n]);
/* 添加代码 */
delete swfuploadify.queueData.files[args[n]];
swfuploadify.queueData.queueLength = swfuploadify.queueData.queueLength - 1;
/* 添加结束 */
$('#' + args[n]).find('.data').removeClass('data').html(' - Cancelled');
$('#' + args[n]).find('.uploadify-progress-bar').remove();
$('#' + args[n]).delay(1000 + 100 * n).fadeOut(500, function () {
$(this).remove();
});
}
}
} else {
var item = $('#' + settings.queueID).find('.uploadify-queue-item').get(0);
$item = $(item);
swfuploadify.cancelUpload($item.attr('id'));
$item.find('.data').removeClass('data').html(' - Cancelled');
$item.find('.uploadify-progress-bar').remove();
$item.delay(1000).fadeOut(500, function () {
$(this).remove();
});
}
});
}
BUG2:上传个文件提示“文件已存在”,点击“肯定”,页面删除,可是再上传同一个文件是,会提示2次“文件已存在”(说明队列中文件根本没有删除只是页面显示删除了)
修改:找到对应的方法(根据提示信息搜索到对应的方法,添加代码)
onSelect: function (file) {
// Load the swfupload settings
var settings = this.settings;
// Check if a file with the same name exists in the queue
var queuedFile = {};
for (var n in this.queueData.files) {
queuedFile = this.queueData.files[n];
if (queuedFile.uploaded != true && queuedFile.name == file.name) {
var replaceQueueItem = confirm('文件名为 "' + file.name + '" 文件已存在.\n你是否想在队列中替换现有的文件?');
if (!replaceQueueItem) {
this.cancelUpload(file.id);
this.queueData.filesCancelled++;
return false;
} else {
/* 添加代码 */
$('#' + queuedFile.id).remove();
/* 添加结束 */
this.cancelUpload(queuedFile.id);
this.queueData.filesReplaced++;
}
}
}