ACMS.Dispatch._imgresize=function(context){var targetMark=".js-img_resize",inputMark=".js-img_resize_input",previewMark=".js-img_resize_preview",createObjectURL=window.URL&&window.URL.createObjectURL?function(file){return window.URL.createObjectURL(file)}:window.webkitURL&&window.webkitURL.createObjectURL?function(file){return window.webkitURL.createObjectURL(file)}:undefined,lgImageSize=ACMS.Config.lgImg,lgImgAry=lgImageSize.split(":");lgImgSide=lgImgAry[0],lgImgSize=lgImgAry[1];function resize(target){var $previewBox=
$(previewMark,target).clone(),$previewPBox=$(previewMark,target).parent(),_toDataURL=function(){var canvas=document.createElement("canvas"),ctx=canvas.getContext("2d"),srcSize={width:this.width,height:this.height},destSize=null,dataUrl=null,ratio=1;noResize=false;if($("[name^=image_size_]",target).length>0&&$("[name^=image_size_]",target).val().length<2)noResize=true;if(!lgImgSide)if(srcSize.width>srcSize.height)lgImgSide="width";else lgImgSide="height";if(lgImgSide.substring(0,1)==="h")if(srcSize.height<
lgImgSize){destSize={width:srcSize.width,height:srcSize.height};noResize=true}else{ratio=lgImgSize/srcSize.height;destSize={width:srcSize.width*ratio,height:lgImgSize}}else if(srcSize.width<lgImgSize){destSize={width:srcSize.width,height:srcSize.height};noResize=true}else{ratio=lgImgSize/srcSize.width;destSize={width:lgImgSize,height:srcSize.height*ratio}}canvas.width=destSize.width;canvas.height=destSize.height;ctx.drawImage(this,0,0,srcSize.width,srcSize.height,0,0,destSize.width,destSize.height);
dataUrl=canvas.toDataURL(this.mime);$previewPBox.append($previewBox.clone().show().prop("src",dataUrl));if(!noResize||this.multiple){dataUrl=dataUrl.replace(/^data:image\/.*;base64,/,"");$(inputMark,target).replaceWith($(inputMark,target).clone(true))}else dataUrl="";var $dataForm=$('<input class="js-img_resize_data" accept="image/*">').prop({type:"hidden",name:$(inputMark,target).prop("name"),value:dataUrl});$(inputMark,target).after($dataForm)};$(inputMark,target).on("change",function(event){var i=
0,multiple=event.target.files.length>1;$(previewMark,target).remove();$(".js-img_resize_data",target).remove();for(i=0;i<event.target.files.length;i++){var file=event.target.files[i],image=new Image;if(!file)continue;image.multiple=multiple;image.mime=file.type;image.onload=_toDataURL;image.src=createObjectURL(file)}})}_.each($(targetMark,context),function(v){resize(v)})};
