jQuery(function(){var h=jQuery,o=h("#uploader"),j=h('
').appendTo(o.find(".queueList")),t=o.find(".statusBar"),c=t.find(".info"),b=o.find(".uploadBtn"),g=o.find(".placeholder"),n=t.find(".progress").hide(),v=0,m=0,k=window.devicePixelRatio||1,l=110*k,a=110*k,i="pedding",w={},s=(function(){var x=document.createElement("p").style,y="transition" in x||"WebkitTransition" in x||"MozTransition" in x||"msTransition" in x||"OTransition" in x;x=null;return y})(),q;var f=base_path+"com/webuploader/rdrphoto.do";if(!WebUploader.Uploader.support()){alert("Web Uploader 不支持您的浏览器!如果你使用的是IE浏览器,请尝试升级 flash 播放器");throw new Error("WebUploader does not support the browser you are using.")}q=WebUploader.create({pick:{id:"#filePicker",label:"点击选择图片"},dnd:"#uploader .queueList",paste:document.body,accept:{title:"Images",extensions:"jpg,jpeg,png",mimeTypes:"image/jpg,image/jpeg,image/png"},thumb:{type:"image/jpg,jpeg,png"},swf:BASE_URL+"/js/Uploader.swf",disableGlobalDnd:true,chunked:true,server:f,fileNumLimit:300,fileSizeLimit:5*1024*1024,fileSingleSizeLimit:1*1024*1024});q.addButton();function r(C){var D=h(''+C.name+'
'),A=h('删除向右旋转向左旋转
').appendTo(D),z=D.find("p.progress span"),y=D.find("p.imgWrap"),B=h(''),x=function(E){switch(E){case"exceed_size":text="文件大小超出";break;case"interrupt":text="上传暂停";break;default:text="上传失败,请重试";break}B.text(text).appendTo(D)};if(C.getStatus()==="invalid"){x(C.statusText)}else{y.text("预览中");q.makeThumb(C,function(F,G){if(F){y.text("不能预览");return}var E=h('');y.empty().append(E)},l,a);w[C.id]=[C.size,0];C.rotation=0}C.on("statuschange",function(F,E){if(E==="progress"){z.hide().width(0)}else{if(E==="queued"){D.off("mouseenter mouseleave");A.remove()}}if(F==="error"||F==="invalid"){console.log(C.statusText);x(C.statusText);w[C.id][1]=1}else{if(F==="interrupt"){x("interrupt")}else{if(F==="queued"){w[C.id][1]=0}else{if(F==="progress"){B.remove();z.css("display","block")}else{if(F==="complete"){D.append('')}}}}}D.removeClass("state-"+E).addClass("state-"+F)});D.on("mouseenter",function(){A.stop().animate({height:30})});D.on("mouseleave",function(){A.stop().animate({height:0})});A.on("click","span",function(){var E=h(this).index(),F;switch(E){case 0:q.removeFile(C);return;case 1:C.rotation+=90;break;case 2:C.rotation-=90;break}if(s){F="rotate("+C.rotation+"deg)";y.css({"-webkit-transform":F,"-mos-transform":F,"-o-transform":F,transform:F})}else{y.css("filter","progid:DXImageTransform.Microsoft.BasicImage(rotation="+(~~((C.rotation/90)%4+4)%4)+")")}});D.appendTo(j)}function u(x){var y=h("#"+x.id);delete w[x.id];d();y.off().find(".file-panel").off().end().remove()}function d(){var x=0,A=0,y=n.children(),z;h.each(w,function(C,B){A+=B[0];x+=B[0]*B[1]});z=A?x/A:0;y.eq(0).text(Math.round(z*100)+"%");y.eq(1).css("width",Math.round(z*100)+"%");e()}function e(){var y="",x;if(i==="ready"){y="选中"+v+"张图片,共"+WebUploader.formatSize(m)+"。"}else{if(i==="confirm"){x=q.getStats();if(x.uploadFailNum){y="已成功上传"+x.successNum+"张照片至XX相册,"+x.uploadFailNum+'张照片上传失败,重新上传失败图片或忽略'}}else{x=q.getStats();y="共"+v+"张("+WebUploader.formatSize(m)+"),已上传"+x.successNum+"张";if(x.uploadFailNum){y+=",失败"+x.uploadFailNum+"张"}}}c.html(y)}function p(z){var y,x;if(z===i){return}b.removeClass("state-"+i);b.addClass("state-"+z);i=z;switch(i){case"pedding":g.removeClass("element-invisible");j.parent().removeClass("filled");j.hide();t.addClass("element-invisible");q.refresh();break;case"ready":g.addClass("element-invisible");h("#filePicker2").removeClass("element-invisible");j.parent().addClass("filled");j.show();t.removeClass("element-invisible");q.refresh();break;case"uploading":h("#filePicker2").addClass("element-invisible");n.show();b.text("暂停上传");break;case"paused":n.show();b.text("继续上传");break;case"confirm":n.hide();b.text("开始上传").addClass("disabled");x=q.getStats();if(x.successNum&&!x.uploadFailNum){p("finish");return}break;case"finish":x=q.getStats();if(x.successNum){alert("上传成功")}else{i="done";location.reload()}break}e()}q.onUploadProgress=function(z,x){var A=h("#"+z.id),y=A.find(".progress span");y.css("width",x*100+"%");w[z.id][1]=x;d()};q.onFileQueued=function(x){v++;m+=x.size;if(v===1){g.addClass("element-invisible");t.show()}r(x);p("ready");d()};q.onFileDequeued=function(x){v--;m-=x.size;if(!v){p("pedding")}u(x);d()};q.on("all",function(y){var x;switch(y){case"uploadFinished":p("confirm");break;case"startUpload":p("uploading");break;case"stopUpload":p("paused");break}});q.onError=function(x){alert("Eroor: "+x)};b.on("click",function(){if(h(this).hasClass("disabled")){return false}if(i==="ready"){q.upload()}else{if(i==="paused"){q.upload()}else{if(i==="uploading"){q.stop()}}}});c.on("click",".retry",function(){q.retry()});c.on("click",".ignore",function(){alert("todo")});b.addClass("state-"+i);d()});