praiadeseselle/wire/modules/Inputfield/InputfieldImage/InputfieldImage.min.js

1 line
42 KiB
JavaScript
Raw Permalink Normal View History

2022-03-08 15:55:41 +01:00
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").click();clearTimeout(timer)}$this.children("li").each(function(n){var $sort=$(this).find(".InputfieldFileSort");if($sort.val()!=n)$sort.val(n).change()});$el.removeClass("InputfieldImageSorting")},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").change()}else{$items.prop("checked",false).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()