var espcms_botton_edit='\u4FEE\u6539';var espcms_botton_del='\u5220\u9664';var espcms_botton_del_ok='\u786E\u8BA4\u5220\u9664';var espcms_filenamage_upfile_loading='\u4E0A\u4F20\u4E2D';var espcms_filenamage_upfile_ok='\u4E0A\u4F20\u6210\u529F';var espcms_filenamage_upfile_err='\u4E0A\u4F20\u9519\u8BEF';var espcms_filenamage_upfile_no='\u4E0A\u4F20\u5931\u8D25';var espcms_botton_upfile_ok='\u786E\u8BA4\u4E0A\u4F20';var espcms_upfile_nofile_message_warning='\u63D0\u9192\uFF1A\u5F53\u524D\u672A\u6DFB\u52A0\u4E0A\u4F20\u6587\u4EF6\uFF0C\u8BF7\u5148\u589E\u52A0\u4E0A\u4F20\u6587\u4EF6\u540E\u518D\u8FDB\u884C\u4E0A\u4F20\u64CD\u4F5C\uFF01';var espcms_upfile_ok='\u606D\u559C\uFF0C\u5F53\u524D\u7528\u6237\u5934\u50CF\u4FEE\u6539\u6210\u529F';$(document).ready(function(){$(function(){var $wrap=$('#espcms_upload');var $queue=$('<ul class="espcms_uploadPicList"></ul>').appendTo($wrap);var percentages={};var $placeHolder=$wrap.find('#picker');var $upload=$('#file_upfile_botton');var state='pedding';var isSupportBase64=(function(){var data=new Image();var support=true;data.onload=data.onerror=function(){if(this.width!=1||this.height!=1){support=false;}}
data.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";return support;})();var ratio=window.devicePixelRatio||1;var thumbnailWidth=110*ratio;var thumbnailHeight=110*ratio;var fileCount=0,fileSize=0;var uploader=WebUploader.create({swf:uploadSWF,server:$('#editinfo').attr('action'),fileVal:'espcms_webupfilename',pick:'#picker',resize:false,duplicate:true,sendAsBinary:false,chunked:true,chunkSize:chunksize,compress:false,accept:{title:'Images',extensions:upfile_ext,mimeTypes:'*'},threads:1,fileNumLimit:1,fileSizeLimit:100*1024*1024,fileSingleSizeLimit:upload_max_filesize_byte});function espcms_upfile_add_file(file){var $li=$('<li id="'+file.id+'">'+'<p class="uploadtitle">'+file.name+'</p>'+'<p class="uploadimgWrap"></p>'+'<p class="uploadprogress"><span class="progressline"></span></p>'+'<p class="uploadloading"><span class="espcms_icon_fa espcms_icon_fa-spinner espcms_icon_fa-spin espcms_icon_fa-1x" aria-hidden="true"></span>'+espcms_filenamage_upfile_loading+'</p>'+'</li>'),$btns=$('<div class="upload_file_panel"><span class="cancel">'+espcms_botton_del+'</span></div>').appendTo($li),$prgress=$li.find('p.uploadprogress span'),$loading=$li.find('p.uploadloading'),$wrap=$li.find('p.uploadimgWrap'),$info=$('<p class="uploaderror"></p>').hide().appendTo($li),showError=function(code){switch(code){case'exceed_size':text='文件过大';break;case'interrupt':text='文件传输中断';break;case'http':text='http请求错误';break;case'not_allow_type':text='文件格式不允许';break;default:text='上传失败，请重试';break;}
$info.text(text).show();};$("#user_phto_div").hide();if(file.getStatus()==='invalid'){showError(file.statusText);}else{$wrap.text('预览中');if('|png|jpg|jpeg|bmp|gif|'.indexOf('|'+file.ext.toLowerCase()+'|')==-1){$wrap.empty().addClass('notimage').append('<i class="file-preview file-type-'+file.ext.toLowerCase()+'" title="'+file.name+'"></i>'+'<span class="file-title" title="'+file.name+'">'+file.name+'</span>');}else{uploader.makeThumb(file,function(error,src){var img;if(error){$wrap.text('不能预览');return;}
if(isSupportBase64){img=$('<img src="'+src+'" title="'+file.name+'">');$wrap.empty().append(img);}},thumbnailWidth,thumbnailHeight);}
percentages[file.id]=[file.size,0];file.rotation=0;if(!file.ext){showError('not_allow_type');uploader.removeFile(file);}}
file.on('statuschange',function(cur,prev){if(prev==='progress'){$loading.hide();$prgress.hide().width(0);}else if(prev==='queued'){$li.off('mouseenter mouseleave');$btns.remove();}
if(cur==='error'||cur==='invalid'){showError(file.statusText);percentages[file.id][1]=1;}else if(cur==='interrupt'){showError('interrupt');}else if(cur==='queued'){percentages[file.id][1]=0;}else if(cur==='progress'){$info.hide();$prgress.css('display','block');}
$li.removeClass('state-'+prev).addClass('state-'+cur);});$li.on('mouseenter',function(){$btns.stop().animate({height:30});});$li.on('mouseleave',function(){$btns.stop().animate({height:0});});$btns.on('click','span',function(){var index=$(this).index();switch(index){case 0:removeFile(file);return;case 1:file.rotation+=90;break;case 2:file.rotation-=90;break;}});$li.appendTo($queue);}
function removeFile(file){var $li=$('#'+file.id);delete percentages[file.id];$li.off().find('.upload_file_panel').off().end().remove();fileCount--;fileSize-=file.size;uploader.removeFile(file);if(!fileCount){$('#file_upfile_botton').hide();$placeHolder.show();}
$("#user_phto_div").show();}
uploader.on('uploadBeforeSend',function(obj,data,headers){var file=obj.file;data.upFileType=$("#upFileType").val();data.tokenname=$("#tokenname").val();data.tokenkey=$("#tokenkey").val();});uploader.on('fileQueued',function(file){fileCount++;fileSize+=file.size;$placeHolder.hide();espcms_upfile_add_file(file);$queue.show();$('#file_upfile_botton').show();});uploader.on('uploadProgress',function(file,percentage){$('#'+file.id).find('p.uploadloading').show();});uploader.on('startUpload',function(){if(!this.getStats().queueNum){alert(espcms_upfile_nofile_message_warning);return false;}else{if($upload.hasClass('disabled')){return false;}
$upload.addClass('disabled').text(espcms_filenamage_upfile_loading);$('.espcms_close_dialog').addClass('disabled');}});$upload.on('click',function(){uploader.upload();});uploader.on('fileDequeued',function(file){});uploader.on('uploadSuccess',function(file,response){$('#'+file.id).find('p.uploadloading').hide();if(response.returnVal=='1'){$('#'+file.id).find('p.uploadprogress').append('<span class="successinfo">'+espcms_filenamage_upfile_ok+'</span>').show();$('#picker').hide();alert(espcms_upfile_ok);}else{$('#'+file.id).find('p.uploaderror').text(espcms_filenamage_upfile_no).show();$upload.removeClass('disabled').text(espcms_botton_upfile_ok);$('.espcms_close_dialog').removeClass('disabled');$('#'+file.id).append('<div class="upload_file_panel"><span class="cancel">'+espcms_botton_del+'</span></div>');delFile(file);}
parent.closeifram();});function delFile(file){var id='#'+file.id;$(id).on('mouseenter',function(){$(id).children('.upload_file_panel').stop().animate({height:30});});$(id).on('mouseleave',function(){$(id).children('.upload_file_panel').stop().animate({height:0});});$(id).children('.upload_file_panel').on('click','span',function(){var index=$(this).index();switch(index){case 0:removeFile(file);return;}});}
uploader.on('uploadError',function(file){$('#'+file.id).find('p.uploadloading').hide();$('#'+file.id).find('p.uploaderror').text(espcms_filenamage_upfile_err).show();$upload.removeClass('disabled').text(espcms_botton_upfile_ok);$('.espcms_close_dialog').removeClass('disabled');});uploader.on('uploadFinished',function(){$('#file_upfile_botton').hide();$upload.removeClass('disabled').text(espcms_botton_upfile_ok);$('.espcms_close_dialog').removeClass('disabled');});});});