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;this.previewOnly=ACMS.Config.resizeImage!=="on";var inputs=$(this.inputMark,elm);if(inputs.length>1){_.each(inputs,function(input,i){input.name=input.name.replace(/\[\d*\]$/,"["+i+"]")})}};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;var $dropArea=$(this.dropAreaMark,target);var objDropArea=$dropArea.get(0);self.dragging=0;if(objDropArea&&window.File&&window.FileReader&&!this.previewOnly){self.banDrag(target);if(!$("img",target).attr("src")){$dropArea.addClass("drag-n-drop-hover");setTimeout(function(){$dropArea.find(".acms-admin-drop-area").fadeOut(200,function(){$dropArea.removeClass("drag-n-drop-hover");$dropArea.find(".acms-admin-drop-area").show()})},800)}objDropArea.addEventListener("drop",function(event){event.stopPropagation();event.preventDefault();self.dragging=0;self.dropSelect=true;$(this).removeClass("drag-n-drop-hover");var files=event.dataTransfer.files;var gif=false;for(var i=0;i<files.length;i++){var file=files[i];if(file.type==="image/gif"){gif=true;break}}if(gif){if(!window.confirm(ACMS.i18n("drop_select_gif_image.alert"))){return false}}self.readFiles(event.dataTransfer.files,target);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,$sizeSelect=$("[name^=image_size_]",target),$bannerSize=$(".js-banner_size_large"),$bannerSizeCriterion=$(".js-banner_size_large_criterion"),rawSize=$sizeSelect.length>0&&$sizeSelect.val().length<2;if($sizeSelect.length>1){return false}if($bannerSize.length>=1&&$bannerSize.val()){ACMS.Config.lgImg=$bannerSizeCriterion.val()+":"+$bannerSize.val()}$(self.previewMark,target).remove();$(".js-img_resize_data",target).remove();var lgImageSize=ACMS.Config.lgImg;var lgImgAry=lgImageSize.split(":");var lgImgSide=lgImgAry[0];var lgImgSize=lgImgAry[1];var multi=files.length>1;if(rawSize){lgImgSize=999999999}for(var i=0;i<files.length;i++){var file=files[i];if(!file)continue;ACMS.Library.resizeImage.getDataUrlFromFile(file,lgImgSide,lgImgSize,function(dataUrl,resize){if(rawSize){resize=false}if(multi){resize=true}if(!self.dropSelect&&file.type==="image/gif"){resize=false}if(self.previewOnly){resize=false}self.set(target,dataUrl,resize||self.dropSelect)})}};ACMS.Dispatch.Imgresize.prototype.banDrag=function(target){$("img",target).mousedown(function(e){e.preventDefault()});$("img",target).mouseup(function(e){e.preventDefault()})};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_resize_preview_old",target).remove();$(".js-img_data_url",target).attr("data-src",dataUrl);self.banDrag(target);if(resize){$(self.inputMark,target).replaceWith($(self.inputMark,target).clone(true));if($(self.inputMark,target).val()!==""){$(self.inputMark,target).val("")}}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)};