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

1 line
14 KiB
JavaScript
Raw Permalink Normal View History

$(document).ready(function(){$(document).on("change",".InputfieldFileDelete input",function(){setInputfieldFileStatus($(this))}).on("dblclick",".InputfieldFileDelete",function(){var $input=$(this).find("input");var $items=$(this).parents(".InputfieldFileList").find(".InputfieldFileDelete input");if($input.is(":checked")){$items.prop("checked",false).trigger("change")}else{$items.prop("checked",true).trigger("change")}return false});function setInputfieldFileStatus($t){var $info=$t.parents(".InputfieldFileInfo");var collapsed=$t.closest(".InputfieldFile").hasClass("InputfieldItemListCollapse");if($t.is(":checked")){$info.addClass("ui-state-error");if(!collapsed)$info.siblings(".InputfieldFileData").slideUp("fast")}else{$info.removeClass("ui-state-error");if(!collapsed)$info.siblings(".InputfieldFileData").slideDown("fast")}}function initSortable($fileLists){$fileLists.each(function(){var $this=$(this);var qty=$this.children("li").length;if($this.closest(".InputfieldRenderValueMode").length)return;var $inputfield=$this.closest(".Inputfield");if(qty<2){if(qty==0)$inputfield.addClass("InputfieldFileEmpty").removeClass("InputfieldFileMultiple InputfieldFileSingle");else $inputfield.addClass("InputfieldFileSingle").removeClass("InputfieldFileEmpty InputfieldFileMultiple");return}else{$this.closest(".Inputfield").removeClass("InputfieldFileSingle InputfieldFileEmpty").addClass("InputfieldFileMultiple")}$this.sortable({start:function(e,ui){ui.item.children(".InputfieldFileInfo").addClass("ui-state-highlight")},stop:function(e,ui){$(this).children("li").each(function(n){$(this).find(".InputfieldFileSort").val(n)});ui.item.children(".InputfieldFileInfo").removeClass("ui-state-highlight");$inputfield.addClass("InputfieldFileJustSorted InputfieldStateChanged");setTimeout(function(){$inputfield.removeClass("InputfieldFileJustSorted")},500)},update:function(e,ui){$inputfield.trigger("sorted",[ui.item])}})}).find(".ui-widget-header, .ui-state-default").on("mouseenter",function(){$(this).addClass("ui-state-hover")}).on("mouseleave",function(){$(this).removeClass("ui-state-hover")})}function InitOldSchool(){$("body").addClass("ie-no-drop");$(document).on("change",".InputfieldFileUpload input[type=file]",function(){var $t=$(this);var $mask=$t.closest(".InputMask");if($t.val().length>1){$mask.addClass("ui-state-disabled")}else{$mask.removeClass("ui-state-disabled")}if($mask.next(".InputMask").length>0)return;var $inputfield=$t.closest(".InputfieldFile");var $upload=$t.closest(".InputfieldFileUpload");var $list=$inputfield.find(".InputfieldFileList");var maxFiles=parseInt($upload.find(".InputfieldFileMaxFiles").val());var numFiles=$list.children("li").length+$upload.find("input[type=file]").length+1;var maxFilesize=parseInt($upload.attr("data-maxfilesize"));var abort=false;$upload.find("input[type=file]").each(function(){if(typeof this.files[0]!=="undefined"){var size=this.files[0].size;if(size>maxFilesize){ProcessWire.alert("File "+this.files[0].name+" is "+size+" bytes which exceeds max allowed size of "+maxFilesize+" bytes");$(this).val("").closest(".InputMask").removeClass("ui-state-disabled ui-state-active");abort=true}}});if(abort)return false;if(maxFiles>0&&numFiles>=maxFiles){}else{$upload.find(".InputMask").not(":last").each(function(){var $m=$(this);if($m.find("input[type=file]").val()<1)$m.remove()});var $mask2=$mask.clone().removeClass("ui-state-disabled");var $input=$mask2.find("input[type=file]");$input.attr("id",$input.attr("id")+"-");$input.val("");$mask2.insertAfter($mask);$mask2.css("margin-left","0.5em").removeClass("ui-state-active")}var name=$t.val();var pos=name.lastIndexOf("/");if(pos===-1)pos=name.lastIndexOf("\\");name=name.substring(pos+1);$mask.find(".ui-button-text").text(name).prepend("<i class='fa fa-fw fa-file-o'></i>");$mask.removeClass("ui-state-active")})}function InitHTML5($inputfield){if($inputfield.length>0){var $target=$inputfield.find(".InputfieldFileUpload")}else{var $target=$(".InputfieldFileUpload")}$target.closest(".InputfieldContent").each(function(i){if($(this).hasClass("InputfieldFileInit"))ret