function getCropServerURL(){if(typeof window.CropServerURL!="undefined"&&window.CropServerURL){return window.CropServerURL}if(typeof window.IS_BACKEND!="undefined"&&window.IS_BACKEND){return BACKEND_URL+"/manager/crop"}return FRONTEND_URL+"/user/file/crop"}function cropImage(e,i,a,r,p,o){var f={uploadURL:e,croperURL:getCropServerURL(),fileElem:null,thumbsnailInput:i,originalInput:a,previewElem:null,subdir:r,width:p,height:o,prefix:""};if(typeof e=="object"){f=$.extend(f,e)}if(!f.fileElem){if(f.prefix){f.fileElem="#"+f.prefix+"-fileupload"}else{f.fileElem="#fileupload"}}if(!f.prefix){f.prefix="noprefix"}if(!f.thumbsnailInput){f.thumbsnailInput=$(f.fileElem).data("thumbsnail-input")||"#"+f.prefix+"-image"}if(!f.originalInput){f.originalInput=$(f.fileElem).data("original-input")||"#"+f.prefix+"-image-original"}if(!f.previewElem){f.previewElem=$(f.fileElem).data("preview")||"";if(!f.previewElem)f.previewElem=$(f.fileElem).siblings("img")[0]}if(!f.subdir){f.subdir=$(f.fileElem).data("subdir")||"";if(!f.subdir){var t=f.uploadURL.match(/subdir=([^&]+)/);if(t&&t.length>0)f.subdir=decodeURIComponent(t[1])}}if(f.width==null){f.width=$(f.fileElem).data("width")||200}if(f.height==null){f.height=$(f.fileElem).data("height")||f.width}var d=$("#"+f.prefix+"-crop-image"),l=$("#"+f.prefix+"-progress"),n=$("#"+f.prefix+"-save-image"),p=f.width,o=f.height;var u=null;var s=function(t){App.getImgNaturalDimensions(t[0],function(e){var i=1;if(e.w>0){i=t.width()/e.w}var a=p*i,r=o*i;t.Jcrop({aspectRatio:p/o,setSelect:[0,0,a,r]},function(){u=this})})};var m=function(e,i){var a=function(){if(u)u.destroy();d.find(".crop-image").empty();u=null};if(u)a();$.each(e,function(e,i){$(f.originalInput).val(i);d.find(".crop-image").html('<img src="'+i+"?_="+Math.random()+'" />');l.fadeOut();n.data("image-file",i);var a=d.find(".crop-image img");a.off().on("load",function(){s(a)})});if(typeof $.fn.niftyModal!="undefined"){d.niftyModal("show",{afterClose:a})}else{d.modal("show");d.off("hide.bs.modal").on("hide.bs.modal",function(){a()})}};$(f.fileElem).fileupload({url:f.uploadURL,dataType:"json",done:function(e,i){var a=i.result;if(a.Code!=1){return App.message({title:App.i18n.SYS_INFO,text:a.Info,time:5e3,sticky:false,class_name:a.Code==1?"success":"error"})}m(a.Data.files)},progressall:function(e,i){var a=parseInt(i.loaded/i.total*100,10);l.fadeIn();l.css("width",a+"%")}}).prop("disabled",!$.support.fileInput).parent().addClass($.support.fileInput?undefined:"disabled");var v=$(f.fileElem).siblings(".avatar-actions");if(v.length<1){v=$('<div class="avatar-actions"></div');$(f.fileElem).parent("div").prepend(v)}var c=new RegExp("\\.svg$","i");n.on("click",function(){var n=$(this),s=d.find(".crop-image img");App.getImgNaturalDimensions(s[0],function(e){var i=u.tellSelect();if(i.w!=0){var a=e.w/s.width();var r=n.data("image-file");var t=v.children(".avatar-resize").data("token");var l={src:r,x:i.x*a,y:i.y*a,w:i.w*a,h:i.h*a,size:p+"x"+o,subdir:f.subdir};if(t!==undefined&&t)l.token=t;$.get(f.croperURL,l,function(e){if(e.Code!=1){return App.message({title:App.i18n.SYS_INFO,text:e.Info,time:5e3,sticky:false,class_name:e.Code==1?"success":"error"})}if(c.test(e.Data)){if(!$(f.previewElem).hasClass("img-svg"))$(f.previewElem).addClass("img-svg")}else{$(f.previewElem).removeClass("img-svg")}$(f.previewElem).attr("src",e.Data+"?_="+Math.random());$(f.thumbsnailInput).val(e.Data);if(typeof $.fn.niftyModal!="undefined"){d.niftyModal("hide")}else{d.modal("hide")}if(u)u.destroy();d.find(".crop-image").empty();u=null},"json")}else{alert("Please select a crop region then press save.")}})});var g=v.children(".avatar-remove");if(g.length<1){g=$('<a class="label label-danger avatar-remove" href="javascript:;" title="'+App.t("删除图片")+'"><i class="fa fa-times"></i></a>');v.append(g)}g.on("click",function(){$(f.previewElem).removeClass("img-svg");$(f.previewElem).attr("src",ASSETS_URL+"/images/user_128.png");$(f.originalInput).val("");$(f.thumbsnailInput).val("");v.children(".avatar-resize").hide()});if(typeof App.editor=="undefined"){return}var h=$('<a class="label label-primary avatar-browsing" href="javascript:;" title="'+App.t("从服务器选择")+'"><i class="fa fa-folder-open-o"></i></a>');v.append(h);var w=v.children(".avatar-resize");if(w.length<1){w=$('<a class="label label-warning avatar-resize" href="javascript:;" title="'+App.t("裁剪图片")+'" style="display:none"><i class="fa fa-crop"></i></a>');v.append(w)}h.on("click",function(){App.editor.finderDialog(App.editor.browsingFileURL+"?from=parent&size=12&filetype=image&subdir="+f.subdir+"&multiple=0",function(a,e){if(a.length<=0){return App.message({type:"error",text:App.t("没有选择任何选项！")})}$.post(f.uploadURL,{pipe:"_queryThumb",file:a[0],size:p+"x"+o,subdir:f.subdir},function(e){if(e.Code!=1)return App.message({type:"error",text:e.Info});if("thumb"in e.Data){var i=e.Data.thumb;if(c.test(i)){if(!$(f.previewElem).hasClass("img-svg"))$(f.previewElem).addClass("img-svg")}else{$(f.previewElem).removeClass("img-svg")}$(f.previewElem).attr("src",i+"?_="+Math.random());$(f.thumbsnailInput).val(i);$(f.originalInput).val(a[0]);v.children(".avatar-resize").data("token",e.Data.token).show();return}m([a[0]])},"json")},1e5)});w.on("click",function(){var e=$(f.originalInput).val();if(!e)return App.message({type:"error",text:App.t("请先选择图片！")});m([e])})}