ACMS.Dispatch._imgresize=function(elm){var obj=new ACMS.Dispatch.Imgresize(elm);obj.resize()};ACMS.Dispatch.Imgresize=function(elm){this.elm=elm;this.dropAreaMark=".js-drop_area";this.inputMark=ACMS.Config.resizeImageInputMark;this.previewMark=ACMS.Config.resizeImagePreviewMark;this.targetMark=ACMS.Config.resizeImageTargetMark;this.targetMarkCF=ACMS.Config.resizeImageTargetMarkCF;this.dropSelect=false;this.dragging=0};
ACMS.Dispatch.Imgresize.prototype.resize=function(){var self=this;if($(self.targetMark,self.elm).length>0)_.each($(self.targetMark,self.elm),function(v){self.exec(v)});else if(1&&$(self.elm).hasClass(self.targetMarkCF.substr(1))&&!$(self.elm).hasClass("resizeImage")){$(self.elm).addClass("resizeImage");self.exec(self.elm)}};
ACMS.Dispatch.Imgresize.prototype.exec=function(target){var self=this;self.previewBox=$(self.previewMark,target).clone();$(self.previewMark,target).after($.parseHTML('<div class="js-img_resize_preview_location" />'));self.listener(target)};
ACMS.Dispatch.Imgresize.prototype.listener=function(target){var self=this,objDropArea=$(this.dropAreaMark,target).get(0);self.dragging=0;if(objDropArea&&window.File&&window.FileReader){objDropArea.addEventListener("drop",function(event){self.dropSelect=true;self.readFiles(event.dataTransfer.files,target);$(this).removeClass("drag-n-drop-hover");self.dragging=0;event.stopPropagation();event.preventDefault();return false},false);objDropArea.addEventListener("dragover",function(event){$(this).addClass("drag-n-drop-hover");
event.stopPropagation();event.preventDefault();return false},false);objDropArea.addEventListener("dragenter",function(){self.dragging++;$(this).addClass("drag-n-drop-hover");event.stopPropagation();event.preventDefault();return false},false);objDropArea.addEventListener("dragleave",function(){self.dragging--;if(self.dragging===0)$(this).removeClass("drag-n-drop-hover");event.stopPropagation();event.preventDefault();return false},false)}else;$(self.inputMark,target).on("change",function(event){self.readFiles(event.target.files,
target)})};
ACMS.Dispatch.Imgresize.prototype.readFiles=function(files,target){var self=this,multiple=files.length>1,createObjectURL=window.URL&&window.URL.createObjectURL,$sizeSelect=$("[name^=image_size_]",target),rawSize=$sizeSelect.length>0&&$sizeSelect.val().length<2;if($sizeSelect.length>1)return false;$(self.previewMark,target).remove();$(".js-img_resize_data",target).remove();for(var i=0;i<files.length;i++){var file=files[i],image=new Image;if(!file)continue;image.force=multiple;image.target=target;image.mime=
file.type;image.onload=ACMS.Dispatch.Utility.imgToDataURL;image.src=createObjectURL(file);image.callback=function(elm,dataUrl,resize){var image=elm,target=image.target;if(rawSize)resize=false;self.set(target,dataUrl,resize||self.dropSelect)}}};
ACMS.Dispatch.Imgresize.prototype.set=function(target,dataUrl,resize){var self=this;if(!self.previewBox){self.previewBox=$(self.previewMark,target).clone();$(self.previewMark,target).remove();$(".js-img_resize_data",target).remove()}$(".js-img_resize_preview_location",target).before(self.previewBox.clone().show().prop("src",dataUrl));$(".js-img_data_url",target).attr("data-src",dataUrl);if(resize){dataUrl=dataUrl.replace(/^data:image\/.*;base64,/,"");$(self.inputMark,target).replaceWith($(self.inputMark,
target).clone(true))}else dataUrl="";var $dataForm=$('<input class="js-img_resize_data" accept="image/*">').prop({type:"hidden",name:$(self.inputMark,target).prop("name"),value:dataUrl});$(self.inputMark,target).after($dataForm)};
