artabro/wire/modules/Inputfield/InputfieldImage/InputfieldImage.min.js
2024-08-27 11:35:37 +02:00

1 line
No EOL
43 KiB
JavaScript

function InputfieldImage($){var $uploadBeforeItem=null;var uploadReplace={file:"",item:null,edit:null};var magnificOptions={type:"image",closeOnContentClick:true,closeBtnInside:true};var cookieData=null;var retryGridItems=[];var gridSliding=false;function useAjaxUpload(){var isFileReaderSupport=window.File&&window.FileList&&window.FileReader;var isAjaxUpload=$(".InputfieldAllowAjaxUpload").length>0;var isPageIDIndicator=$("#PageIDIndicator").length>0;return isFileReaderSupport&&(isPageIDIndicator||isAjaxUpload)}function throttle(fn,threshhold,scope){threshhold||(threshhold=250);var last,deferTimer;return function(){var context=scope||this;var now=+new Date,args=arguments;if(last&&now<last+threshhold){clearTimeout(deferTimer);deferTimer=setTimeout(function(){last=now;fn.apply(context,args)},threshhold)}else{last=now;fn.apply(context,args)}}}function inverseState(index,old){return!old}function setupSortable($el){if($el.hasClass("ui-sortable")){$el.sortable("destroy");$el.children("li").each(function(n){var $sort=$(this).find("input.InputfieldFileSort");$sort.val(n)})}var timer;var sortableOptions={items:"> .gridImage",start:function(e,ui){var size=getCookieData($el.closest(".Inputfield"),"size");ui.placeholder.append($("<div/>").css({display:"block",height:size+"px",width:size+"px"}));timer=window.setTimeout(function(){closeEdit($el,null)},100);$el.addClass("InputfieldImageSorting")},stop:function(e,ui){var $this=$(this);if(timer!==null){ui.item.find(".InputfieldImageEdit__edit").trigger("click");clearTimeout(timer)}$this.children("li").each(function(n){var $sort=$(this).find(".InputfieldFileSort");if($sort.val()!=n)$sort.val(n).trigger("change")});$el.removeClass("InputfieldImageSorting");ui.item.find(".Inputfield").trigger("sort-stop")},update:function(e,ui){$el.trigger("sorted",[ui.item])},cancel:".InputfieldImageEdit,.focusArea,input,textarea,button,select,option"};$el.sortable(sortableOptions)}function setupMagnificForRenderValue($el){var options=$.extend(true,{},magnificOptions);options.callbacks={elementParse:function(item){var src=$(item.el).attr("data-original");if(typeof src=="undefined"||!src)src=$(item.el).attr("src");item.src=src}};options.gallery={enabled:true};$el.find("img").magnificPopup(options)}function setupMagnificForSingle($el){var options=$.extend(true,{},magnificOptions);options.callbacks={elementParse:function(item){item.src=$(item.el).attr("src")}};options.gallery={enabled:false};$el.find("img").magnificPopup(options)}function findEditedElement($parent){return $parent.find(".InputfieldImageEdit--active")}function findEditMarkup($edit){return $("#"+$edit.find(".InputfieldImageEdit__edit").attr("data-current"))}function setDeleteStateOnAllItems($input){var checked=$input.is(":checked");var $items=$input.parents(".gridImages").find(".gridImage__deletebox");if(checked){$items.prop("checked","checked").trigger("change")}else{$items.prop("checked",false).trigger("change")}}function updateGrid($inputfield){var $gridImages;if(typeof $inputfield=="undefined"){$gridImages=$(".gridImages")}else{$gridImages=$inputfield.find(".gridImages")}$gridImages.each(function(){var $grid=$(this),$edit=findEditedElement($grid);if($edit.length){moveEdit(findEditMarkup($edit),$edit)}})}function checkInputfieldWidth($inputfield){var narrowItems=[];var mediumItems=[];var wideItems=[];var n=0,ni=0,mi=0,wi=0;var $inputfields;var $item;if(typeof $inputfield=="undefined"){$inputfields=$(".InputfieldImage.Inputfield")}else{$inputfields=$inputfield}$inputfields.removeClass("InputfieldImageNarrow InputfieldImageMedium InputfieldImageWide");$inputfields.each(function(){$item=$(this);var width=$item.width();if(width<1)return;if(width<=500){narrowItems[ni]=$item;ni++}else if(width<=900){mediumItems[mi]=$item;mi++}else{wideItems[wi]=$item;wi++}});for(n=0;n<ni;n++){$item=narrowItems[n];$item.addClass("InputfieldImageNarrow")}for(n=0;n<mi;n++){$item=mediumItems[n];$item.addClass("InputfieldImageMedium")}for(n=0;n<wi;n++){$item=wideItems[n];$item.addClass("InputfieldImageWide")}}function windowResize(){$(".focusArea.focusActive").each(function(){var $edit=$(this).closest(".InputfieldImageEdit, .gridImage");if($edit.length)stopFocus($edit)});updateGrid();checkInputfieldWidth()}function updateDeleteClass($checkbox){if($checkbox.is(":checked")){$checkbox.parents(".ImageOuter").addClass("gridImage--delete")}else{$checkbox.parents(".ImageOuter").removeClass("gridImage--delete")}}function setupEdit($el,$edit){if($el.closest(".InputfieldImageEditAll").length)return;var $img=$edit.find(".InputfieldImageEdit__image");var $thumb=$el.find("img");$img.attr({src:$thumb.attr("data-original"),"data-original":$thumb.attr("data-original"),alt:$thumb.attr("alt")});var options=$.extend(true,{},magnificOptions);options.callbacks={elementParse:function(item){item.src=$(item.el).attr("data-original")}};options.gallery={enabled:true};$edit.attr("id","edit-"+$el.attr("id"));var $items=$edit.parents(".gridImages").find(".gridImage").not($el).find("img").add($img).magnificPopup(options);var $editEdit=$edit.find(".InputfieldImageEdit__edit");$editEdit.attr("data-current",$el.attr("id")).append($el.find(".ImageData").children().not(".InputfieldFileSort"));$editEdit.find(".Inputfield").trigger("image-edit")}function startFocus($edit){var $img,$el,$thumb,$input,$focusArea,$focusCircle,$inputfield,focusData=null,gridSize,mode,$zoomSlider,$zoomBox,lastZoomPercent=0,useZoomFocus=false;$inputfield=$edit.closest(".Inputfield");gridSize=getCookieData($inputfield,"size");mode=getCookieData($inputfield,"mode");if($inputfield.hasClass("InputfieldImageFocusZoom"))useZoomFocus=true;if($edit.hasClass("gridImage")){$el=$edit;$img=$edit.find(".gridImage__overflow").find("img");$thumb=$img}else{$el=$("#"+$edit.attr("data-for"));$img=$edit.find(".InputfieldImageEdit__image");$thumb=$el.find(".gridImage__overflow").find("img")}function getFocus(focusStr){if(typeof focusStr=="undefined"){if(focusData!==null)return focusData;var $input=$edit.find(".InputfieldImageFocus");focusStr=$input.val()}var a=focusStr.split(" ");var top=typeof a[0]=="undefined"?50:parseFloat(a[0]);var left=typeof a[1]=="undefined"?50:parseFloat(a[1]);var zoom=typeof a[2]=="undefined"?0:parseInt(a[2]);focusData={top:top>100?100:top,left:left>100?100:left,zoom:zoom>100?0:zoom};return focusData}function getFocusStr(focusObj){if(typeof focusObj=="undefined")focusObj=getFocus();return focusObj.top+" "+focusObj.left+" "+focusObj.zoom}function getFocusProperty(property){var focus=getFocus();return focus[property]}function setFocus(focusObj){focusData=focusObj;var focusStr=focusObj.top+" "+focusObj.left+" "+focusObj.zoom;$thumb.attr("data-focus",focusStr);$input=$edit.find(".InputfieldImageFocus");if(focusStr!=$input.val()){$input.val(focusStr).trigger("change")}}function setFocusProperty(property,value){var focus=getFocus();focus[property]=value;setFocus(focus)}function setFocusDragPosition(){var focus=getFocus();var $overlay=$focusCircle.parent();var w=$overlay.width();var h=$overlay.height();var x=Math.round(focus.left/100*w);var y=Math.round(focus.top/100*h);if(x<0)x=0;if(y<0)y=0;if(x>w)x=w;if(y>h)y=h;$focusCircle.css({top:y+"px",left:x+"px"})}$focusArea=$img.siblings(".focusArea");if(!$focusArea.length){$focusArea=$("<div />").addClass("focusArea");$img.after($focusArea)}$focusArea.css({height:$img.height()+"px",width:$img.width()+"px","background-color":"rgba(0,0,0,0.7)"}).addClass("focusActive");$focusCircle=$focusArea.find(".focusCircle");if(!$focusCircle.length){$focusCircle=$("<div />").addClass("focusCircle");$focusArea.append($focusCircle)}$img.parent().addClass("focusWrap");setFocusDragPosition();var zoomSlide=function(zoomPercent){var zoomBoxSize,focus,faWidth,faHeight;if(typeof zoomPercent=="undefined")zoomPercent=lastZoomPercent;lastZoomPercent=zoomPercent;faWidth=$focusArea.width();faHeight=$focusArea.height();if(faWidth>faHeight){$zoomBox.height(100-zoomPercent+"%");zoomBoxSize=$zoomBox.height();$zoomBox.width(zoomBoxSize)}else{$zoomBox.width(100-zoomPercent+"%");zoomBoxSize=$zoomBox.width();$zoomBox.height(zoomBoxSize)}focus=getFocus();var crop=getFocusZoomCropDimensions(focus.left,focus.top,zoomPercent,faWidth,faHeight,zoomBoxSize);$zoomBox.css({top:crop.top+"px",left:crop.left+"px","background-position":"-"+crop.left+"px -"+crop.top+"px","background-size":faWidth+"px "+faHeight+"px"});focus.zoom=zoomPercent;setFocusProperty("zoom",focus.zoom);if(mode=="grid")setGridSizeItem($thumb.parent(),gridSize,false,focus)};var dragEvent=function(event,ui){var $this=$(this);var circleSize=$this.outerHeight();var w=$this.parent().width();var h=$this.parent().height();var top=ui.position.top>0?ui.position.top:0;var left=ui.position.left>0?ui.position.left:0;top=top>0?top/h*100:0;left=left>0?left/w*100:0;var newFocus={top:top,left:left,zoom:getFocusProperty("zoom")};setFocus(newFocus);if(useZoomFocus){zoomSlide(newFocus.zoom)}else if(mode=="grid"){setGridSizeItem($thumb.parent(),gridSize,false,newFocus)}};$focusCircle.draggable({containment:"parent",drag:dragEvent,stop:dragEvent});if(useZoomFocus){var zoom=getFocusProperty("zoom");$zoomSlider=$("<div />").addClass("focusZoomSlider").css({"margin-top":"5px"});$zoomBox=$("<div />").addClass("focusZoomBox").css({position:"absolute",background:"transparent","background-image":"url("+$img.attr("src")+")"});$focusArea.prepend($zoomBox);$img.after($zoomSlider);$thumb.attr("src",$img.attr("src"));$zoomSlider.slider({min:0,max:50,value:zoom,range:"max",slide:function(event,ui){zoomSlide(ui.value)}});zoomSlide(zoom)}else{$focusArea.css("background-color","rgba(0,0,0,0.5)")}}function stopFocus($edit){$focusCircle=$edit.find(".focusCircle");if($focusCircle.length){var $focusWrap=$focusCircle.closest(".focusWrap");$focusWrap.find(".focusZoomSlider").slider("destroy").remove();$focusWrap.find(".focusZoomBox").remove();$focusWrap.removeClass("focusWrap");$focusCircle.draggable("destroy");$focusCircle.parent().removeClass("focusActive");$focusCircle.remove();var $button=$edit.find(".InputfieldImageButtonFocus");if($button.length){$icon=$button.find("i");$icon.removeClass("focusIconActive").toggleClass($icon.attr("data-toggle"))}}}function getFocusZoomPosition(focusPercent,sourceDimension,cropDimension){var focusPX=parseInt(sourceDimension*focusPercent/100);var position=parseInt(focusPX-cropDimension/2);var maxPosition=parseInt(sourceDimension-cropDimension);if(0>position)position=0;if(maxPosition<position)position=maxPosition;return position}function getFocusZoomCropDimensions(focusLeft,focusTop,zoomPercent,faWidth,faHeight,zoomBoxSize){var percentW=zoomBoxSize/faWidth*100;var percentH=zoomBoxSize/faHeight*100;var maxDimension=percentW>=percentH?faWidth:faHeight;var cropDimension=maxDimension-maxDimension*zoomPercent/100;var posLeft=getFocusZoomPosition(focusLeft,faWidth,cropDimension);var posTop=getFocusZoomPosition(focusTop,faHeight,cropDimension);return{left:posLeft,top:posTop,width:cropDimension,height:cropDimension}}function getFocusZoomPosition4GridviewSquare(focusPercent,sourceDimPX,gridViewPX,zoomPercent,scale,smallestSidePX){sourceDimPX=sourceDimPX*scale;var gridViewPercent=gridViewPX/sourceDimPX*100;var adjustPercent=gridViewPercent/2;var posPercent=focusPercent-adjustPercent;var posMinVal=0;var posMaxVal=100-gridViewPercent;if(posPercent<=posMinVal)posPercent=0;if(posPercent>=posMaxVal)posPercent=posMaxVal;var posPX=sourceDimPX/100*posPercent/scale;posPX=-1*parseInt(posPX);return posPX}function getFocusZoomCropDimensions4GridviewSquare(focusLeft,focusTop,zoomPercent,w,h,gridViewSize,scale){var smallestSidePX=w>=h?h:w;var posLeft=getFocusZoomPosition4GridviewSquare(focusLeft,w,gridViewSize,zoomPercent,scale,smallestSidePX);var posTop=getFocusZoomPosition4GridviewSquare(focusTop,h,gridViewSize,zoomPercent,scale,smallestSidePX);var transformLeft=parseInt(posLeft);var transformTop=parseInt(posTop);return{transformLeft:transformLeft,transformTop:transformTop,scale:scale}}function tearDownEdit($edit){stopFocus($edit);$edit.off("click",".InputfieldImageButtonFocus");$inputArea=$edit.find(".InputfieldImageEdit__edit");if($inputArea.children().not(".InputfieldFileSort").length){var $items=$inputArea.children();$("#"+$inputArea.attr("data-current")).find(".ImageData").append($items)}}function closeEdit($parent,$not){var $edit;if($parent){$edit=$parent.find(".InputfieldImageEdit--active")}else if($not){$edit=$(".InputfieldImageEdit--active").not($not.find(".InputfieldImageEdit--active"))}else{$edit=$(".InputfieldImageEdit--active")}if($edit.length){tearDownEdit($edit);$edit.removeClass("InputfieldImageEdit--active").removeAttr("id");$("#"+$edit.attr("data-for")).removeClass("gridImageEditing")}$(".InputfieldImageEdit__replace").removeClass("InputfieldImageEdit__replace")}function moveEdit($el,$edit){if(!$el||!$el.length)return;var $children=$el.parent().children().not(".InputfieldImageEdit");var lastTop=0;var found=false;var $insertBeforeItem=null;$children.each(function(){if($insertBeforeItem)return;var $item=$(this);var top=$item.offset().top;if(found&&top!=lastTop){$insertBeforeItem=$item}else if($item.attr("id")==$el.attr("id")){found=true}lastTop=top});if($insertBeforeItem){$edit.insertBefore($insertBeforeItem)}else{$edit.insertAfter($children.eq($children.length-1))}var $arrow=$edit.find(".InputfieldImageEdit__arrow");if($arrow.length)$arrow.css("left",$el.position().left+$el.outerWidth()/2+"px")}function initGridEvents(){$(window).on("resize",throttle(windowResize,200));$(document).on("click dblclick",".gridImage__trash",function(e){var $input=$(this).find("input");$input.prop("checked",inverseState).trigger("change");if(e.type=="dblclick"){setDeleteStateOnAllItems($input);e.preventDefault();e.stopPropagation()}});$(document).on("change",".gridImage__deletebox",function(){updateDeleteClass($(this))});$(document).on("click",".gridImage__edit",function(e){var $el=$(this).closest(".gridImage");if(!$el.length)return;if($el.closest(".InputfieldImageEditAll").length)return false;var $all=$el.closest(".gridImages");var $edit=$all.find(".InputfieldImageEdit");if($el.hasClass("gridImageEditing")){$edit.find(".InputfieldImageEdit__close").trigger("click")}else{moveEdit($el,$edit);tearDownEdit($edit);setupEdit($el,$edit);$edit.addClass("InputfieldImageEdit--active").attr("data-for",$el.attr("id"));$all.find(".gridImageEditing").removeClass("gridImageEditing");$el.addClass("gridImageEditing")}}).on("click",".InputfieldImageEditAll img",function(e){e.stopPropagation();e.preventDefault();$.magnificPopup.close();var options=$.extend(true,{},magnificOptions);var $img=$(this);options["items"]={src:$img.attr("data-original"),title:$img.attr("alt")};$.magnificPopup.open(options);return true}).on("click",".InputfieldImageButtonFocus",function(){var $button=$(this);var $icon=$button.find("i");var $edit=$button.closest(".InputfieldImageEdit, .gridImage");var $focusCircle=$edit.find(".focusCircle");if($focusCircle.length){stopFocus($edit)}else{startFocus($edit);$icon.addClass("focusIconActive");$icon.toggleClass($icon.attr("data-toggle"))}});$(document).on("click",function(e){var $el=$(e.target);if(typeof clickLanguageTabActive!="undefined"&&clickLanguageTabActive){return}if($el.closest(".InputfieldImageEdit").length){closeEdit(null,$el.parents(".gridImages"))}else if($el.is("input, textarea")&&$el.closest(".InputfieldImageEditAll").length){$el.trigger("focus").one("blur",function(){$el.closest(".gridImages").sortable("enable")});$el.closest(".gridImages").sortable("disable")}else if($el.closest(".gridImage__inner").length){closeEdit(null,$el.parents(".gridImages"))}else if($el.closest(".mfp-container").length){return}else if($el.closest(".ui-dialog").length){return}else if($el.is(".mfp-close")){return}else if($el.is("a.remove")){return}else{closeEdit(null,null)}});$(document).on("click",".InputfieldImageEdit__close",function(e){closeEdit($(this).parents(".gridImages"),null)});$(document).on("change",".InputfieldImage",function(){$(this).find(".InputfieldImageButtonCrop:not(.pw-modal-dblclick)").addClass("pw-modal-dblclick ui-state-disabled")}).on("click",".InputfieldImageButtonCrop.ui-state-disabled",function(e){var $button=$(this);var $list=$button.closest(".gridImages");if(!$list.hasClass("gridImagesAlerted")){ProcessWire.alert(ProcessWire.config.InputfieldImage.labels.changes);$list.addClass("gridImagesAlerted")}setTimeout(function(){$button.removeClass("ui-state-active")},500);return false});$(".ImagesGrid").on("click","button.pw-modal",function(e){e.preventDefault()});setupEditableFilename();checkInputfieldWidth()}function setupEditableFilename(){$(document).on("click",".InputfieldImageEdit__name",function(e){var $span=$(this).children("span");var $input=$span.closest(".gridImage, .InputfieldImageEdit").find(".InputfieldFileRename");var $list=$span.closest(".gridImages");var sortable=$list.hasClass("ui-sortable");if(sortable)$list.sortable("disable");$input.val($span.text());$span.on("keypress",function(e){if(e.which==13){$span.trigger("blur");return false}return true});$span.attr("autocomplete","off").attr("autocorrect","off").attr("autocapitalize","off").attr("spellcheck","false");$span.trigger("focus").on("blur",function(){var val=$(this).text();if(val.trim().length<1){$span.text($input.val())}else if(val!=$input.val()){$input.val(val).trigger("change");$list.closest(".Inputfield").trigger("change")}$span.off("keypress");if(sortable)$list.sortable("enable")})})}function setListSize($inputfield,pct){pct=Math.floor(pct);$inputfield.find(".gridImage__overflow").each(function(){var dataPct=100-pct;var $this=$(this);$this.css("width",pct+"%");$this.siblings(".ImageData").css("width",dataPct+"%");$this.find("img").css({top:0,left:0,transform:"none"})});setCookieData($inputfield,"listSize",pct)}function setGridSize($inputfield,gridSize,ragged){if(!gridSize)return;var size=gridSize+"px";var $gridImages=$inputfield.find(".gridImages");if(typeof ragged=="undefined"||ragged==null)ragged=$gridImages.attr("data-ragged")?true:false;if(ragged){$gridImages.attr("data-ragged",1)}else{$gridImages.removeAttr("data-ragged")}$gridImages.find(".gridImage__overflow").each(function(){setGridSizeItem($(this),gridSize,ragged)});$gridImages.find(".gridImage__edit, .gridImage__resize").css("line-height",size);$gridImages.attr("data-size",gridSize);setCookieData($inputfield,"size",gridSize);if(retryGridItems.length)setTimeout(function(){while(retryGridItems.length){var item=retryGridItems.pop();setGridSizeItem(item.item,item.gridSize,ragged)}},150)}function setGridSizeItem($item,gridSize,ragged,focus){var $img;if($item.hasClass("gridImage__overflow")){$img=$item.children("img")}else if($item.is("img")){$img=$item;$item=$img.closest(".gridImage__overflow")}else{return}if(!gridSize){$img.removeAttr("width").removeAttr("height");$item.width("auto").height("auto");return}var zoom=0;var w=$img.width();var h=$img.height();var dataW=parseInt($img.attr("data-w"));var dataH=parseInt($img.attr("data-h"));if(!w)w=dataW;if(!h)h=dataH;if(!ragged&&typeof focus=="undefined"){var focusStr=$img.attr("data-focus");if(typeof focusStr=="undefined")focusStr="50.0 50.0 0";var focusArray=focusStr.split(" ");focus={top:parseFloat(focusArray[0]),left:parseFloat(focusArray[1]),zoom:parseInt(focusArray[2])}}if(!ragged)zoom=focus.zoom;if(ragged){$img.attr("height",gridSize).removeAttr("width");$img.css({"max-height":"100%","max-width":"none",top:"50%",left:"50%",transform:"translate3d(-50%, -50%, 0)"})}else if(zoom>0&&$item.closest(".InputfieldImageFocusZoom").length&&!gridSliding){var maxHeight,maxWidth;if(w>=h){maxHeight="100%";maxWidth="none";if(w==dataW){h=gridSize;w=h/dataH*dataW}}else{maxHeight="none";maxWidth="100%";if(h==dataH){w=gridSize;h=w/dataW*dataH}}var scale=1+zoom/100*2;var crop=getFocusZoomCropDimensions4GridviewSquare(focus.left,focus.top,zoom,w,h,gridSize,scale);$img.css({left:"0px",top:"0px","transform-origin":"0px 0px",transform:"scale("+crop.scale+") translate3d("+crop.transformLeft+"px, "+crop.transformTop+"px, 0)","max-width":maxWidth,"max-height":maxHeight})}else if(w>=h){$img.attr("height",gridSize).removeAttr("width");if(focus.left<1)focus.left=.001;$img.css({"max-height":"100%","max-width":"none",top:"50%",left:focus.left+"%",transform:"translate3d(-"+focus.left+"%, -50%, 0)"})}else if(h>w){$img.attr("width",gridSize).removeAttr("height");if(focus.top<1)focus.top=.001;$img.css({"max-height":"none","max-width":"100%",top:focus.top+"%",left:"50%",transform:"translate3d(-50%, -"+focus.top+"%, 0)"})}else{$img.css({"max-height":"100%","max-width":"none",top:"50%",left:"50%",transform:"translate3d(-50%, -50%, 0)"});$img.removeAttr("width").attr("height",gridSize)}w=$img.width();if(w){$item.css({width:ragged?w+"px":gridSize+"px",height:gridSize+"px"})}else{var tries=$item.attr("data-tries");if(!tries)tries=0;if(typeof tries=="undefined")tries=0;tries=parseInt(tries);if(tries>3){$item.css({width:gridSize+"px",height:gridSize+"px"})}else{retryGridItems.push({item:$item,gridSize:gridSize});$item.attr("data-tries",tries+1)}}}function setupImageListToggle($target){if($target.find(".InputfieldImageListToggle").length)return;var $list=$("<a class='InputfieldImageListToggle' href='list'></a>").append("<i class='fa fa-th-list'></i>");var $left=$("<a class='InputfieldImageListToggle' href='left'></a>").append("<i class='fa fa-tasks'></i>");var $grid=$("<a class='InputfieldImageListToggle' href='grid'></a>").append("<i class='fa fa-th'></i>");var activeClass="InputfieldImageListToggle--active";var defaultMode="";var toggleClick=function(e){var $a=$(this);var $inputfield=$a.closest(".Inputfield");var href=$a.attr("href");var size;var $aPrev=$a.parent().children("."+activeClass);var hrefPrev=$aPrev.attr("href");$aPrev.removeClass(activeClass);$a.addClass(activeClass);stopFocus($inputfield);if(href=="list"){if(!$inputfield.hasClass("InputfieldImageEditAll")){$inputfield.find(".InputfieldImageEdit--active .InputfieldImageEdit__close").trigger("click");$inputfield.addClass("InputfieldImageEditAll")}size=getCookieData($inputfield,"listSize");setListSize($inputfield,size);setCookieData($inputfield,"mode","list")}else if(href=="left"){$inputfield.removeClass("InputfieldImageEditAll");size=getCookieData($inputfield,"size");setGridSize($inputfield,size,true);setCookieData($inputfield,"mode","left");updateGrid()}else if(href=="grid"){$inputfield.removeClass("InputfieldImageEditAll");size=getCookieData($inputfield,"size");setGridSize($inputfield,size,false);setCookieData($inputfield,"mode","grid");if(hrefPrev=="left")setTimeout(function(){setGridSize($inputfield,size,false)},100)}setupSortable($inputfield.find(".gridImages"));$a.trigger("blur");return false};$list.on("click",toggleClick);$left.on("click",toggleClick);$grid.on("click",toggleClick);if($target.hasClass("InputfieldImage")){$target.children(".InputfieldHeader").append($list).append($left).append($grid);defaultMode=getCookieData($target,"mode")}else{$(".InputfieldImage > .InputfieldHeader",$target).append($list).append($left).append($grid)}if(defaultMode=="list"){$list.trigger("click")}else if(defaultMode=="left"){$left.trigger("click")}else{}}function setupSizeSlider($inputfield){var $header=$inputfield.children(".InputfieldHeader");if($header.children(".InputfieldImageSizeSlider").length)return;var $gridImages=$inputfield.find(".gridImages");var gridSize=$gridImages.attr("data-gridsize");var min=gridSize/2;var max=gridSize*2;var $slider=$('<span class="InputfieldImageSizeSlider"></span>');$header.append($slider);var sizeSlide=function(event,ui){var value=ui.value;var minPct=15;var divisor=Math.floor(gridSize/minPct);var v=value-min;var listSize=Math.floor(minPct+v/divisor);if($inputfield.hasClass("InputfieldImageEditAll")){setCookieData($inputfield,"size",value);setListSize($inputfield,listSize)}else{setCookieData($inputfield,"listSize",listSize);setGridSize($inputfield,value)}};$slider.slider({min:min,max:max,value:getCookieData($inputfield,"size"),range:"min",slide:sizeSlide,start:function(event,ui){gridSliding=true;if($inputfield.find(".InputfieldImageEdit:visible").length){$inputfield.find(".InputfieldImageEdit__close").trigger("click")}},stop:function(event,ui){gridSliding=false;sizeSlide(event,ui);updateGrid($inputfield)}})}function setCookieData($inputfield,property,value){var data=getCookieData($inputfield);var id=$inputfield.attr("id");var name=id?id.replace("wrap_Inputfield_",""):"";if(!name.length||typeof value=="undefined")return;if(data[name][property]==value)return;data[name][property]=value;$.cookie("InputfieldImage",data,{secure:window.location.protocol.indexOf("https:")===0});cookieData=data}function getCookieData($inputfield,property){if(cookieData&&typeof property=="undefined")return cookieData;var id=$inputfield.attr("id");var name=id?id.replace("wrap_Inputfield_",""):"na";var data=cookieData?cookieData:$.cookie("InputfieldImage");var value=null;if(!data)data={};if(typeof data[name]=="undefined")data[name]={};if(typeof data[name].size=="undefined"||!data[name].size){data[name].size=parseInt($inputfield.find(".gridImages").attr("data-size"));if(!data[name].size)data[name].size=130}if(typeof data[name].listSize=="undefined"||!data[name].listSize){data[name].listSize=23}if(typeof data[name].mode=="undefined"||!data[name].mode){data[name].mode=$inputfield.find(".gridImages").attr("data-gridMode");if(!data[name].mode)data[name].mode="list"}if(cookieData==null)cookieData=data;if(typeof property=="undefined"){value=data}else if(property===true){value=data[name]}else if(typeof data[name][property]!="undefined"){value=data[name][property]}return value}function initInputfield($inputfield){if($inputfield.hasClass("InputfieldStateCollapsed"))return;var maxFiles=parseInt($inputfield.find(".InputfieldImageMaxFiles").val());var $gridImages=$inputfield.find(".gridImages");var size=getCookieData($inputfield,"size");var mode=getCookieData($inputfield,"mode");var ragged=mode=="left"?true:false;var renderValueMode=$inputfield.hasClass("InputfieldRenderValueMode");if(!size)size=$gridImages.attr("data-gridsize");size=parseInt(size);if(!renderValueMode&&($inputfield.hasClass("InputfieldImageEditAll")||mode=="list")){var listSize=getCookieData($inputfield,"listSize");setListSize($inputfield,listSize)}else{setGridSize($inputfield,size,ragged)}if(!$inputfield.hasClass("InputfieldImageInit")){$inputfield.addClass("InputfieldImageInit");if(renderValueMode){return setupMagnificForRenderValue($inputfield)}else if(maxFiles==1){$inputfield.addClass("InputfieldImageMax1");setupMagnificForSingle($inputfield)}else{setupSortable($gridImages)}setupImageListToggle($inputfield);setupSizeSlider($inputfield)}checkInputfieldWidth($inputfield);$inputfield.on("change",".InputfieldFileActionSelect",function(){var $note=$(this).next(".InputfieldFileActionNote");if($(this).val().length){$note.fadeIn()}else{$note.hide()}})}function initUploadOldSchool(){$("body").addClass("ie-no-drop");$(".InputfieldImage.InputfieldFileMultiple").each(function(){var $field=$(this),maxFiles=parseInt($field.find(".InputfieldFileMaxFiles").val()),$list=$field.find(".gridImages"),$uploadArea=$field.find(".InputfieldImageUpload");$uploadArea.on("change","input[type=file]",function(){var $t=$(this),$mask=$t.parent(".InputMask");if($t.val().length>1)$mask.addClass("ui-state-disabled");else $mask.removeClass("ui-state-disabled");if($t.next("input.InputfieldFile").length>0)return;var numFiles=$list.children("li").length+$uploadArea.find("input[type=file]").length+1;if(maxFiles>0&&numFiles>=maxFiles)return;$uploadArea.find(".InputMask").not(":last").each(function(){var $m=$(this);if($m.find("input[type=file]").val()<1)$m.remove()});var $i=$mask.clone().removeClass("ui-state-disabled");$i.children("input[type=file]").val("");$i.insertAfter($mask)})})}function initUploadHTML5($inputfield){var $target;if($inputfield.length>0){$target=$inputfield.find(".InputfieldImageUpload")}else{$target=$(".InputfieldImageUpload")}$target.each(function(i){var $this=$(this);var $content=$this.closest(".InputfieldContent");if($this.hasClass("InputfieldImageInitUpload"))return;initHTML5Item($content,i);$this.addClass("InputfieldImageInitUpload")});function initHTML5Item($this,i){var $form=$this.parents("form");var $repeaterItem=$this.closest(".InputfieldRepeaterItem");var postUrl=$repeaterItem.length?$repeaterItem.attr("data-editUrl"):$form.attr("action");postUrl+=(postUrl.indexOf("?")>-1?"&":"?")+"InputfieldFileAjax=1";var $postToken=$form.find("input._post_token");var postTokenName=$postToken.attr("name");var postTokenValue=$postToken.val();var $errorParent=$this.find(".InputfieldImageErrors").first();var fieldName=$this.find(".InputfieldImageUpload").data("fieldname");fieldName=fieldName.slice(0,-2);var $inputfield=$this.closest(".Inputfield.InputfieldImage");var extensions=$this.find(".InputfieldImageUpload").data("extensions").toLowerCase();var maxFilesize=$this.find(".InputfieldImageUpload").data("maxfilesize");var filesUpload=$this.find("input[type=file]").get(0);var $fileList=$this.find(".gridImages");var fileList=$fileList.get(0);var gridSize=$fileList.data("gridsize");var doneTimer=null;var maxFiles=parseInt($this.find(".InputfieldImageMaxFiles").val());var resizeSettings=getClientResizeSettings($inputfield);var useClientResize=resizeSettings.maxWidth>0||resizeSettings.maxHeight>0||resizeSettings.maxSize>0;setupDropzone($this);if(maxFiles!=1)setupDropInPlace($fileList);$fileList.children().addClass("InputfieldFileItemExisting");$inputfield.on("pwimageupload",function(event,data){traverseFiles([data.file],data.xhr)});function errorItem(message,filename){if(typeof filename!=="undefined")message="<b>"+filename+":</b> "+message;var icon="<i class='fa fa-fw fa-warning'></i> ";return"<li>"+icon+message+"</li>"}function basename(str){var base=new String(str).substring(str.lastIndexOf("/")+1);if(base.lastIndexOf(".")!=-1)base=base.substring(0,base.lastIndexOf("."));return base}function setupDropzone($el){if($el.hasClass("InputfieldImageDropzoneInit"))return;var el=$el.get(0);var $inputfield=$el.closest(".Inputfield");function dragStart(){if($inputfield.hasClass("pw-drag-in-file"))return;$el.addClass("ui-state-hover");$inputfield.addClass("pw-drag-in-file")}function dragStop(){if(!$inputfield.hasClass("pw-drag-in-file"))return;$el.removeClass("ui-state-hover");$inputfield.removeClass("pw-drag-in-file")}el.addEventListener("dragleave",function(){dragStop()},false);el.addEventListener("dragenter",function(evt){evt.preventDefault();dragStart()},false);el.addEventListener("dragover",function(evt){if(!$el.is("ui-state-hover"))dragStart();evt.preventDefault();evt.stopPropagation();return false},false);el.addEventListener("drop",function(evt){traverseFiles(evt.dataTransfer.files);dragStop();evt.preventDefault();evt.stopPropagation();return false},false);$el.addClass("InputfieldImageDropzoneInit")}function setupDropInPlace($gridImages){var $i=null;var haltDrag=false;var timer=null;var $inputfield=$gridImages.closest(".Inputfield");function addInputfieldClass(){$inputfield.addClass("pw-drag-in-file")}function removeInputfieldClass(){$inputfield.removeClass("pw-drag-in-file")}function getCenterCoordinates($el){var offset=$el.offset();var width=$el.width();var height=$el.height();var centerX=offset.left+width/2;var centerY=offset.top+height/2;return{clientX:centerX,clientY:centerY}}function noDropInPlace(){return $gridImages.find(".InputfieldImageEdit--active").length>0}function dragEnter(evt){if(noDropInPlace())return;evt.preventDefault();evt.stopPropagation();addInputfieldClass();haltDrag=false;if($i==null){var gridSize=$gridImages.attr("data-size")+"px";var $o=$("<div/>").addClass("gridImage__overflow");if($gridImages.closest(".InputfieldImageEditAll").length){$o.css({width:"100%",height:gridSize})}else{$o.css({width:gridSize,height:gridSize})}$i=$("<li/>").addClass("ImageOuter gridImage gridImagePlaceholder").append($o);$gridImages.append($i)}var coords=getCenterCoordinates($i);$i.simulate("mousedown",coords)}function dragOver(evt){if(noDropInPlace())return;evt.preventDefault();evt.stopPropagation();addInputfieldClass();haltDrag=false;if($i==null)return;var coords={clientX:evt.originalEvent.clientX,clientY:evt.originalEvent.clientY};$i.simulate("mousemove",coords)}function dragEnd(evt){if(noDropInPlace())return;evt.preventDefault();evt.stopPropagation();if($i==null)return false;haltDrag=true;if(timer)clearTimeout(timer);timer=setTimeout(function(){if(!haltDrag||$i==null)return;$i.remove();$i=null;removeInputfieldClass()},1e3)}function drop(evt){if(noDropInPlace())return;removeInputfieldClass();haltDrag=false;var coords={clientX:evt.clientX,clientY:evt.clientY};$i.simulate("mouseup",coords);$uploadBeforeItem=$i.next(".gridImage");$i.remove();$i=null}if($gridImages.length&&!$gridImages.hasClass("gridImagesInitDropInPlace")){$gridImages.on("dragenter",dragEnter);$gridImages.on("dragover",dragOver);$gridImages.on("dragleave",dragEnd);$gridImages.on("drop",drop);$gridImages.addClass("gridImagesInitDropInPlace")}}function uploadFile(file,extension,xhrsub){var labels=ProcessWire.config.InputfieldImage.labels;var filesizeStr=parseInt(file.size/1024,10)+"&nbsp;kB";var tooltipMarkup=""+'<div class="gridImage__tooltip">'+"<table><tbody><tr>"+"<th>"+labels.dimensions+"</th>"+'<td class="dimensions">'+labels.na+"</td>"+"</tr><tr>"+"<th>"+labels.filesize+"</th>"+"<td>"+filesizeStr+"</td>"+"</tr><tr>"+"<th>"+labels.variations+"</th>"+"<td>0</td>"+"</tr></tbody></table>"+"</div>";var $progressItem=$('<li class="gridImage gridImageUploading"></li>'),$tooltip=$(tooltipMarkup),$imgWrapper=$('<div class="gridImage__overflow"></div>'),$imageData=$('<div class="ImageData"></div>'),$hover=$("<div class='gridImage__hover'><div class='gridImage__inner'></div></div>"),$progressBar=$("<progress class='gridImage__progress' min='-1' max='100' value='0'></progress>"),$edit=$('<a class="gridImage__edit" title="'+file.name+'"><span>&nbsp;</span></a>'),$spinner=$('<div class="gridImage__resize"><i class="fa fa-spinner fa-spin fa-2x fa-fw"></i></div>'),reader,xhr,fileData,fileUrl=URL.createObjectURL(file),$fileList=$inputfield.find(".gridImages"),singleMode=maxFiles==1,size=getCookieData($inputfield,"size"),listSize=getCookieData($inputfield,"listSize"),listMode=$inputfield.hasClass("InputfieldImageEditAll"),$img=$('<img height="'+size+'" alt="">');$imgWrapper.append($img);$hover.find(".gridImage__inner").append($edit);$hover.find(".gridImage__inner").append($spinner.css("display","none"));$hover.find(".gridImage__inner").append($progressBar);$imageData.append($(""+'<h2 class="InputfieldImageEdit__name">'+file.name+"</h2>"+'<span class="InputfieldImageEdit__info">'+filesizeStr+"</span>"));if(listMode){$imgWrapper.css("width",listSize+"%");$imageData.css("width",100-listSize+"%")}else{$imgWrapper.css({width:size+"px",height:size+"px"})}$progressItem.append($tooltip).append($imgWrapper).append($hover).append($imageData);$img.attr({src:fileUrl,"data-original":fileUrl});img=new Image;img.addEventListener("load",function(){$tooltip.find(".dimensions").html(this.width+"&nbsp;&times;&nbsp;"+this.height);var factor=Math.min(this.width,this.height)/size;$img.attr({width:this.width/factor,height:this.height/factor})},false);img.src=fileUrl;if(typeof xhrsub!="undefined"){xhr=xhrsub}else{xhr=new XMLHttpRequest}function updateProgress(evt){if(typeof evt!="undefined"){if(!evt.lengthComputable)return;$progressBar.val(parseInt(evt.loaded/evt.total*100))}$("body").addClass("pw-uploading");$spinner.css("display","block")}xhr.upload.addEventListener("progress",updateProgress,false);xhr.addEventListener("load",function(){xhr.getAllResponseHeaders();var response=JSON.parse(xhr.responseText);if(typeof response.ajaxResponse!="undefined")response=response.ajaxResponse;var wasZipFile=response.length>1;if(response.error!==undefined)response=[response];for(var n=0;n<response.length;n++){var r=response[n];if(r.error){$errorParent.append(errorItem(r.message));if(n==response.length-1)$progressItem.hide();continue}var $item=null;var $markup=$(r.markup).hide();var $input=$this.find("input[type=file]");if($input.val())$input.replaceWith($input.clone(true));if(r.overwrite)$item=$fileList.children("#"+$markup.attr("id"));if(maxFiles==1||r.replace){$item=$fileList.children(".gridImage").first()}else if(uploadReplace.item&&response.length==1){$item=uploadReplace.item}if($item&&$item.length){$item.replaceWith($markup)}else if($uploadBeforeItem&&$uploadBeforeItem.length){$uploadBeforeItem.before($markup);$uploadBeforeItem=$markup}else if(n===0){$progressItem.replaceWith($markup)}else{$fileList.append($markup)}if(listMode){$markup.find(".gridImage__overflow").css("width",listSize+"%")}else{$markup.find(".gridImage__overflow").css({height:size+"px",width:size+"px"});$markup.find("img").hide()}$markup.fadeIn(150,function(){$markup.find("img").fadeIn();if(listMode){setListSize($inputfield,listSize)}else{setGridSize($inputfield,size)}setTimeout(function(){var $inputfields=$markup.find(".Inputfield");if($inputfields.length){InputfieldsInit($markup.find(".Inputfields"));$inputfields.trigger("reloaded",["InputfieldImageUpload"])}},250)}).css("display","");$markup.addClass("InputfieldFileItemExisting");if($item&&$item.length)$markup.effect("highlight",500);if($progressItem.length)$progressItem.remove();if(uploadReplace.item&&maxFiles!=1){$markup.find(".InputfieldFileReplace").val(uploadReplace.file);var $imageEditName=$markup.find(".InputfieldImageEdit__name");var uploadNewName=$imageEditName.text();var uploadNewExt=uploadNewName.substring(uploadNewName.lastIndexOf(".")+1).toLowerCase();uploadNewName=uploadNewName.substring(0,uploadNewName.lastIndexOf("."));var uploadReplaceName=uploadReplace.file;if(uploadReplaceName.indexOf("?")>-1){uploadReplaceName=uploadReplaceName.substring(0,uploadReplaceName.indexOf("?"))}var uploadReplaceExt=uploadReplaceName.substring(uploadReplaceName.lastIndexOf(".")+1).toLowerCase();uploadReplaceName=uploadReplaceName.substring(0,uploadReplaceName.lastIndexOf("."));if(uploadReplaceExt==uploadNewExt){$imageEditName.children("span").text(uploadReplaceName).removeAttr("contenteditable")}$markup.find(".gridImage__edit").trigger("click")}uploadReplace.file="";uploadReplace.item=null;uploadReplace.edit=null}if(doneTimer)clearTimeout(doneTimer);$uploadBeforeItem=null;doneTimer=setTimeout(function(){if(maxFiles!=1){setupSortable($fileList)}else{setupMagnificForSingle($inputfield)}$("body").removeClass("pw-uploading");$fileList.trigger("AjaxUploadDone")},500);$inputfield.trigger("change").removeClass("InputfieldFileEmpty")},false);if(uploadReplace.edit){uploadReplace.edit.find(".InputfieldImageEdit__close").trigger("click")}else if($inputfield.find(".InputfieldImageEdit:visible").length){$inputfield.find(".InputfieldImageEdit__close").trigger("click")}if(uploadReplace.item){uploadReplace.item.replaceWith($progressItem);uploadReplace.item=$progressItem}else if($uploadBeforeItem&&$uploadBeforeItem.length){$uploadBeforeItem.before($progressItem)}else{$fileList.append($progressItem)}function sendUpload(file,imageData){if(typeof xhrsub=="undefined"){xhr.open("POST",postUrl,true)}xhr.setRequestHeader("X-FILENAME",encodeURIComponent(file.name));xhr.setRequestHeader("X-FIELDNAME",fieldName);if(uploadReplace.item)xhr.setRequestHeader("X-REPLACENAME",uploadReplace.file);xhr.setRequestHeader("Content-Type","application/octet-stream");xhr.setRequestHeader("X-"+postTokenName,postTokenValue);xhr.setRequestHeader("X-REQUESTED-WITH","XMLHttpRequest");if(typeof imageData!="undefined"&&imageData!=false){xhr.send(imageData)}else{xhr.send(file)}updateGrid();$inputfield.trigger("change");var numFiles=$inputfield.find(".InputfieldFileItem").length;if(numFiles==1){$inputfield.removeClass("InputfieldFileEmpty").removeClass("InputfieldFileMultiple").addClass("InputfieldFileSingle")}else if(numFiles>1){$inputfield.removeClass("InputfieldFileEmpty").removeClass("InputfieldFileSingle").addClass("InputfieldFileMultiple")}}updateProgress();if(typeof file.name==="undefined")file.name=getUploadFilename(file);var ext=file.name.substring(file.name.lastIndexOf(".")+1).toLowerCase();if(useClientResize&&(ext=="jpg"||ext=="jpeg"||ext=="png"||ext=="gif")){var resizer=new PWImageResizer(resizeSettings);$spinner.addClass("pw-resizing");resizer.resize(file,function(imageData){$spinner.removeClass("pw-resizing");sendUpload(file,imageData)})}else{sendUpload(file)}}function traverseFiles(files,xhr){var toKilobyte=function(i){return parseInt(i/1024,10)};if(typeof files==="undefined"){fileList.innerHTML="No support for the File API in this web browser";return}for(var i=0,l=files.length;i<l;i++){if(typeof files[i].name==="undefined")files[i].name=getUploadFilename(files[i]);var extension=files[i].name.split(".").pop().toLowerCase();var message;if(extensions.indexOf(extension)==-1){if(typeof ProcessWire.config.InputfieldFile.labels["bad-ext"]!="undefined"){message=ProcessWire.config.InputfieldFile.labels["bad-ext"];message=message.replace("EXTENSIONS",extensions)}else{message=extension+" is a invalid file extension, please use one of: "+extensions}$errorParent.append(errorItem(message,files[i].name))}else if(!useClientResize&&files[i].size>maxFilesize&&maxFilesize>2e6){var filesizeKB=toKilobyte(files[i].size),maxFilesizeKB=toKilobyte(maxFilesize);if(typeof ProcessWire.config.InputfieldFile.labels["too-big"]!="undefined"){message=ProcessWire.config.InputfieldFile.labels["too-big"];message=message.replace("MAX_KB",maxFilesizeKB)}else{message="Filesize "+filesizeKB+" kb is too big. Maximum allowed is "+maxFilesizeKB+" kb"}$errorParent.append(errorItem(message,files[i].name))}else if(typeof xhr!="undefined"){uploadFile(files[i],extension,xhr)}else{uploadFile(files[i],extension)}if(maxFiles==1)break}}function getUploadFilename(file){if(typeof file.name!=="undefined")return file.name;var ext="";switch(file.type){case"image/jpeg":ext=".jpg";break;case"image/png":ext=".png";break;case"image/gif":ext=".gif";break;case"image/svg+xml":ext=".svg";break;case"image/webp":ext=".webp"}return $inputfield.attr("id").replace("wrap_Inputfield_","")+ext}filesUpload.addEventListener("change",function(evt){traverseFiles(this.files);evt.preventDefault();evt.stopPropagation();this.value=""},false)}function setupEnlargementDropzones(){var sel=".InputfieldImageEdit__imagewrapper img";$(document).on("dragenter",sel,function(){var $this=$(this);if($this.closest(".InputfieldImageMax1").length)return;var src=$this.attr("src");var $edit=$this.closest(".InputfieldImageEdit");var $parent=$this.closest(".InputfieldImageEdit__imagewrapper");$parent.addClass("InputfieldImageEdit__replace");uploadReplace.file=new String(src).substring(src.lastIndexOf("/")+1);uploadReplace.item=$("#"+$edit.attr("data-for"));uploadReplace.edit=$edit}).on("dragleave",sel,function(){var $this=$(this);if($this.closest(".InputfieldImageMax1").length)return;var $parent=$this.closest(".InputfieldImageEdit__imagewrapper");$parent.removeClass("InputfieldImageEdit__replace");uploadReplace.file="";uploadReplace.item=null;uploadReplace.edit=null})}setupEnlargementDropzones()}function getClientResizeSettings($inputfield){var settings={maxWidth:0,maxHeight:0,maxSize:0,quality:1,autoRotate:true,debug:ProcessWire.config.debug};var data=$inputfield.attr("data-resize");if(typeof data!="undefined"&&data.length){data=data.split(";");settings.maxWidth=data[0].length?parseInt(data[0]):0;settings.maxHeight=data[1].length?parseInt(data[1]):0;settings.maxSize=data[2].length?parseFloat(data[2]):0;settings.quality=parseFloat(data[3])}return settings}function init(){$(".InputfieldImage.Inputfield").each(function(){initInputfield($(this))});initGridEvents();if(useAjaxUpload()){initUploadHTML5("")}else{initUploadOldSchool()}$(document).on("reloaded",".InputfieldImage",function(){var $inputfield=$(this);$inputfield.removeClass("InputfieldImageInit");initInputfield($inputfield);initUploadHTML5($inputfield);Inputfields.init($inputfield);$(".InputfieldImageListToggle--active",$inputfield).trigger("click")}).on("wiretabclick",function(e,$newTab,$oldTab){$newTab.find(".InputfieldImage").each(function(){initInputfield($(this))})}).on("opened",function(){var $t=$(this);if($t.hasClass("InputfieldImage")){initInputfield($t)}else{$t.find(".InputfieldImage").each(function(){initInputfield($(this))})}})}init()}jQuery(document).ready(function($){InputfieldImage($)});