Skip to content

Commit

Permalink
使用最新版本的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
tison committed Mar 11, 2016
1 parent 22234af commit 7b8010b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions HHuploadify.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
}
.uploadify-button:hover {
background-color: #0086E3;
text-decoration: none;
}
/*
.uploadify-button span {
Expand Down
3 changes: 2 additions & 1 deletion HHuploadify.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@

uploadManager._getFiles(e);
// 如果是单个文件上传,那么要隐藏上传按钮
if(option.isSingle) {
var fileCount = _this.find('.uploadify-queue .uploadify-queue-item').length; // 注意这个一行,如果选择的文件有问题,弹出提示信息,如果没有这一行的话,上传按钮就会消失
if(option.isSingle && fileCount > 0) {
_this.find('.uploadify-button').hide();
}
});
Expand Down
41 changes: 21 additions & 20 deletions HHuploadifyReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,42 @@
if(typeof module !== 'undefined' && typeof exports === 'object') {
module.exports = ex;
}
// Javascript: exports as window functions
else {
for(var i in ex) {
window[i] = ex[i];
}
}
}
}(['jquery'],function(){
function initHHuploadify(selector,uploader,field,isSingle,title) {
}(['jquery','dragsort'],function(){
function initHHuploadify(selector,uploader,field,title,isSingle) {
isSingle = typeof isSingle == 'boolean' ? isSingle : false;
$(selector).HHuploadify({
auto: true,
fileTypeExts: '*.jpg;*.png;*.jpeg;*.gif',
multi: true,
buttonText: title == undefined ? 'choose' : 'choose ' + title,
itemTitle: title == undefined || title == '' ? false : title,
buttonText: title ? '选择' + title : '选择图片',
itemTitle: title || false,
fileSizeLimit: 99999999,
uploader: uploader,
isSingle: isSingle,
showPreview: 2,
onSelect : function() {
var instanceNumber = $(selector).find('.uploadify').index('.uploadify') + 1;
var $instance = $('#file_upload_' + instanceNumber + '-queue');
$instance.dragsort("destroy");
},
onUploadSuccess:function(file,result){
var instanceNumber = $(selector).find('.uploadify').index('.uploadify') + 1;
result = JSON.parse(result);
if(result.status == 0) {
alert(file.name + 'upload failed.' + result.info);
if(result != '') {
result = JSON.parse(result);
if(result.status == 0) {
alert(file.name + '上传失败。' + result.info);
}
else {
var file_index = file.index,
image_id = result.id;
var $fileInstance = $('#fileupload_' + instanceNumber + '_' + file_index);
$fileInstance.append('<input type="hidden" name="' + field + (!isSingle ? '[]' : '') + '" value="' + image_id + '">');
}
}
else {
var file_index = file.index,
image_id = result.id;
var $fileInstance = $('#fileupload_' + instanceNumber + '_' + file_index);
$fileInstance.append('<input type="hidden" name="' + field + (!isSingle ? '[]' : '') + '" value="' + image_id + '">');
$('#fileupload_'+instanceNumber+'_'+file.index).css('background','#0099FF');
alert(file.name + '上传失败。网络错误。');
}
},
onQueueComplete:function(){
Expand All @@ -72,7 +73,7 @@
}

function initHHuploadifyOne(selector,uploader,field,title) {
initHHuploadify(selector,uploader,field,true,title);
initHHuploadify(selector,uploader,field,title,true);
}

function initHHuploadifyCount(selector,uploader,fields,titles) {
Expand All @@ -99,7 +100,7 @@
for(i = 0;i < images.length;i ++) {
var image = images[i];
html += '<span class="uploadify-queue-item uploaded" style="background-image: url(' + image.url + ')">';
if(title != undefined)
if(title)
html += '<span class="itemtitle">' + title + '</span>';
html += '<input type="hidden" name="' + field + '[]" value="' + image.id + '">';
html += '<a href="javascript:void(0);" class="delfilebtn">&times;</a>';
Expand Down Expand Up @@ -129,7 +130,7 @@
var html = '';

html += '<span class="uploadify-queue-item uploaded" style="background-image: url(' + image.url + ')">';
if(title != undefined)
if(title)
html += '<span class="itemtitle">' + title + '</span>';
html += '<input type="hidden" name="' + field + '" value="' + image.id + '">';
html += '<a href="javascript:void(0);" class="delfilebtn">&times;</a>';
Expand Down

0 comments on commit 7b8010b

Please sign in to comment.