From 7b8010bb587b0098ff0fe0ecf5fd16cdcc1d9f57 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 11 Mar 2016 18:36:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=80=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HHuploadify.css | 1 + HHuploadify.js | 3 ++- HHuploadifyReady.js | 41 +++++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/HHuploadify.css b/HHuploadify.css index efc2dd1..21515c2 100755 --- a/HHuploadify.css +++ b/HHuploadify.css @@ -32,6 +32,7 @@ } .uploadify-button:hover { background-color: #0086E3; + text-decoration: none; } /* .uploadify-button span { diff --git a/HHuploadify.js b/HHuploadify.js index f8cc6c5..9b3a29a 100755 --- a/HHuploadify.js +++ b/HHuploadify.js @@ -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(); } }); diff --git a/HHuploadifyReady.js b/HHuploadifyReady.js index 52afde8..e6fc7e3 100755 --- a/HHuploadifyReady.js +++ b/HHuploadifyReady.js @@ -16,25 +16,20 @@ 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'); @@ -42,15 +37,21 @@ }, 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(''); + } } else { - var file_index = file.index, - image_id = result.id; - var $fileInstance = $('#fileupload_' + instanceNumber + '_' + file_index); - $fileInstance.append(''); + $('#fileupload_'+instanceNumber+'_'+file.index).css('background','#0099FF'); + alert(file.name + '上传失败。网络错误。'); } }, onQueueComplete:function(){ @@ -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) { @@ -99,7 +100,7 @@ for(i = 0;i < images.length;i ++) { var image = images[i]; html += ''; - if(title != undefined) + if(title) html += '' + title + ''; html += ''; html += '×'; @@ -129,7 +130,7 @@ var html = ''; html += ''; - if(title != undefined) + if(title) html += '' + title + ''; html += ''; html += '×';