/*
 =======================================================================*\
|| ###################################################################### ||
|| # vBulletin 6.2.3
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2026 MH Sub I, LLC dba vBulletin. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
vBulletin.precache("add_caption attach_files click_to_add_caption drop_files_here_to_upload enter_url_file error_uploading_image invalid_image_allowed_filetypes_are remove_all_photos_confirmation_message remove_all_photos_q upload upload_more uploading you_are_already_editing_continue".split(" "),[]);
vBulletin.upload=((a,p,r,v,K,F,C)=>{function w(b,e){a(".b-button--upload .js-upload-label",b).each((f,m)=>{f=a(m);m=f.data("default-text");m||(m=f.text(),f.data("default-text",m));f.text(void 0===e?m:r.get(e))})}async function L(b){b=await (await fetch(b)).blob();let e="dataurl"+String(Date.now()).slice(-6)+"."+b.type.split("/")[1];return new File([b],e)}async function M(b,e){return new Promise((f,m)=>{var c=new FormData,d=()=>m(Error("Upload Failed"));c.append("uploadFrom","newContent");c.append("files",
b);v.ajax({call:"/uploader/upload",data:c,success:function(k){for(var h of k)if(k=h.error){if(Array.isArray(k)||(k=[k]),k=[h.name,...k.map(g=>r.get(g))],0<k.length){C.openAlertDialog({title:r.get("upload"),message:k.join("<br />\n"),iconType:"warning"});d();return}}else{k=D(a(".b-content-entry-panel__content--attachment",e),h);f({upload:h,panelitem:k});return}d()},error_phrase:"error_uploading_image",after_error:d})})}function D(b,e){b=b.find(".js-attach-list");var f=a(".js-uploadFrom").val();e.name||
p.error("upload","unknown_error");var m=!1;if(e.name.match(/\.(gif|jpg|jpeg|jpe|png|bmp|webp)$/i)){var c=a("<img />").attr("src",pageData.baseurl+"/filedata/fetch?type=thumb&filedataid="+e.filedataid).addClass("b-attach-item__image");m=!0}else c=a("<span />").addClass("b-icon-fa b-icon-fa--16 fa-solid fa-file-lines");var d=b.find(".js-attach-item-sample").first().clone(!0);d.removeClass("js-attach-item-sample");d.find(".js-attach-item-image").append(c);d.find(".js-attach-item-filename").text(e.name);
d.append(a("<input />").attr({type:"hidden",name:"filedataids[]"}).val(e.filedataid)).append(a("<input />").attr({type:"hidden",name:"filenames[]"}).val(e.name));d.data({fileext:e.extension,filebasetype:e.basetype,filename:e.name,filedataid:e.filedataid,attachnodeid:0});e=(k,h)=>k.find(".js-attach-ctrl").filter((g,l)=>h.includes(a(l).data("action")));"signature"==f?(b.find(".js-attach-item").not(".js-attach-item-sample").remove(),e(d,["insert_image","insert_label"]).addClass("h-hide"),e(d,["insert"]).html(r.get("insert")).data("action",
"insert_sigpic").attr("data-action","insert_sigpic")):m||(e(d,["insert_image","insert_label"]).addClass("h-hide"),e(d,["insert"]).html(r.get("insert")));p.ckeditor.checkEnvironment()||e(d,["insert","insert_image","insert_label"]).addClass("h-hide");d.appendTo(b).removeClass("h-hide");b.removeClass("h-hide");return d}function E(b){function e(c){z(c,0<a(".photo-display .photo-item-wrapper:not(.h-hide)",c).length)}function f(c){c.length||(c=a("<form>"));let d=c.find('input[name="securitytoken"]');d.length||
(d=a('<input type="hidden" name="securitytoken" />'),c.append(d));d.val(pageData.securitytoken);return c.find(":input").filter((k,h)=>!a(h).parent().hasClass("js-photo-postdata")).serializeArray()}function m(c){var d=[["error_uploading_image"]];c&&0<c.files.length&&"acceptFileTypes"==c.files[0].error&&(d=[["invalid_image_allowed_filetypes_are"]]);v.showApiError(d,{},{title:"upload"})}console.log("Fileupload: vBulletin.upload.initializePhotoUpload");if(!b||0==b.length)if(b=a("body"),1<a(".js-photo-display",
b).length)return console.log("Fileupload: multiple upload forms, abort"),!1;a(".js-continue-button",b).offon("click",function(c){console.log("Fileupload: continue");var d=a(document).data("gallery-container"),k=d.find(".js-photo-postdata");c=k.closest(".js-contententry-form").find('input[name="nodeid"]');c=c.length&&c[0].value||0;var h={},g=a(this).closest(".js-photo-display"),l=[],n=0;k.empty();0<c&&p.gallery.clearCacheForNodeid(c);g.find(".photo-item-wrapper:not(.h-hide)").each(function(){var t=
a(this).find(".filedataid"),q=t.val();t=t.data("nodeid");var G=a.trim(a(this).find(".caption-box").val()),H=a.trim(a(this).find(".js-photo-title").val());a(this).removeClass("tmp-photo");"undefined"!==typeof t&&(a(this).removeClass("tmp-photo"),-1==a.inArray(t,A)&&A.push(t));n++;k.append(a("<input />").attr({type:"hidden",name:"filedataid[]"}).val(q)).append(a("<input />").attr({type:"hidden",name:"title_"+q}).val(H)).append(a("<input />").attr({type:"hidden",name:"caption_"+q}).val(G)).append(a("<input />").attr({type:"hidden",
name:"displayorder_"+q}).val(n));l.push({filedataid:q,caption:G,title:H,displayorder:n})});h.photocount=l.length;h.photos=l;h.isAjaxTemplateRenderWithData=!0;g.find(".photo-item-wrapper:hidden").remove();g.dialog("close");0<h.photos.length?(v.ajax({call:"/ajax/render/editor_gallery_photoblock",data:h,type:"POST",dataType:"json",success:function(t){var q=a(t.template);q.find(".b-gallery-thumbnail-list__aside").addClass("h-invisible");d.find(".js-gallery-content").removeClass("h-hide").find(".js-panel-content").empty().append(q);
setTimeout(function(){q.find(".b-gallery-thumbnail-list__aside").removeClass("h-invisible")},500);E(d);a(document).data("gallery-container",null)},silent:!0}),a(".js-edit-photos",d).removeClass("h-hide"),w(d,"upload_more")):(a(".js-panel-content",d).empty(),a(".js-edit-photos",d).addClass("h-hide"),w(d))});a(".js-edit-photos",b).offon("click",function(c){console.log("Fileupload: edit photos");a(document).data("gallery-container",a(this).closest(".b-content-entry-panel__content--gallery"));c=x(!1);
y(c.find(".photo-item-wrapper"));e(c);c.dialog("open");u(c);a(".b-button--upload",c).trigger("focus")});a(".js-cancel-button",b).offon("click",function(c){console.log("Fileupload: cancel");c=a(this).closest(".js-photo-display");var d=a(document).data("gallery-container");a(".photo-item-wrapper.tmp-photo",c).remove();a(".photo-item-wrapper",c).removeClass("h-hide");w(d,0<a(".js-slideshow--item",d).length?"upload_more":void 0);c.dialog("close")});a(".b-content-entry-panel__content--attachment",b).offon("click",
".js-upload-from-url",function(c){let d=a(this);C.openPromptDialogSimple({title:"enter_url_file",message:"",onClickOk:k=>{let h=d.parent().find(".js-upload-progress");h.removeClass("h-hide");v.ajax({call:"/uploader/url",data:{urlupload:k,attachment:1,uploadFrom:a(".js-uploadFrom",b).val()},skipdefaultsuccess:!0,complete:()=>{h.addClass("h-hide")},success:g=>{g.imageUrl&&($panel=a(".b-content-entry-panel__content--attachment"),g.name=g.filename,D($panel,g))},title_phrase:"error_uploading_image"})}});
return!1});a(".b-content-entry-panel__content--gallery, .js-profile-media-photoupload-dialog",b).fileupload({dropZone:"vb-self",dataType:"json",url:p.getAjaxBaseurl()+"/uploader/upload-photo",type:"POST",formData:c=>f(c.find(".b-content-entry-panel__content--gallery")),add:function(c,d){console.log("Fileupload: gallery add");c=a(this);a(document).data("gallery-container",c);c=x(!0);a(".js-upload-progress",c).removeClass("h-hide");w(c,"uploading");d.submit();a(".b-button--upload",c).trigger("focus")},
done:function(c,d){c=a(this);var k=d&&d.result&&d.result.errors&&0<d.result.errors.length;a(document).data("gallery-container",c);var h=x(!1);if(d&&d.result&&!k&&d.result.edit){d=a(d.result.edit);var g=a(".photo-display",h),l=h.parent();c=a(".photo-item-wrapper:not(.h-hide)",g).length;d.addClass("tmp-photo");0==(c+1)%3&&d.addClass("last-in-row");c+1>F.ATTACHLIMIT&&a(".js-attach-limit-warning",h).show();u(h);g.append(d);d.fadeIn("fast",function(){h.dialog("option","position",{of:window});l.hasClass("has-scrollbar")&&
g.animate({scrollTop:g[0].scrollHeight-g.height()},"fast")})}else d=k?d.result.errors[0]:"unknown_error",p.warning("upload",d)},fail:(c,d)=>{m(d)},always:function(c,d){c=x(!1);c.find(".js-upload-progress").addClass("h-hide");e(c)}});a(".b-content-entry-panel__content--attachment",b).fileupload({dropZone:"vb-self",dataType:"json",url:p.getAjaxBaseurl()+"/uploader/upload",type:"POST",previewAsCanvas:!1,autoUpload:!0,formData:c=>f(c.find(".b-content-entry-panel__content--attachment")),add:function(c,
d){console.log("Fileupload: attachments add");b.find(".js-upload-progress").removeClass("h-hide");d.submit()},done:function(c,d){c=[];var k=[],h={};if(d&&d.result)if(h=d.result,h.error)c=[h.error];else if(h.errors)c=h.errors;else for(var g of d.result)(d=g.error)?(Array.isArray(d)||(d=[d]),k.push(g.name,...d.map(l=>r.get(l)))):D(a(this),g);else c=[["invalid_server_response_please_try_again"]];0<c.length?v.showApiError(c,h,{title:"upload"}):0<k.length&&C.openAlertDialog({title:r.get("upload"),message:k.join("<br />\n"),
iconType:"warning"})},fail:(c,d)=>{m(d)},always:function(c,d){b.find(".js-upload-progress").addClass("h-hide")}});a(document).offon("click.photoadd",".js-photo-selector-continue",function(){console.log("Fileupload: continue 2");let c=a(this).closest(".js-photo-selector-container"),d={},k=c.data("selected-nodes")||{},h=c.data("selected-nodes-meta")||{};k.length?k.forEach(g=>{var l=h[g];if(l){const n=l.filedataid;l=l.title;d[g]={imgUrl:p.getAjaxBaseurl()+"/filedata/fetch?filedataid="+n+"&thumb=1",filedataid:n,
title:l}}}):c.find(".photo-item-wrapper").each(function(){var g=a(this).find(".filedataid"),l=g.data("nodeid");if(g.is(":checked")){g=g.val();var n=a.trim(a(this).find(".photo-title").text());d[l]={imgUrl:p.getAjaxBaseurl()+"/filedata/fetch?filedataid="+g+"&thumb=1",filedataid:g,title:n}}});a.isEmptyObject(d)||v.ajax({call:"/ajax/render/photo_item",data:{items:d,wrapperClass:"tmp-photo",isAjaxTemplateRenderWithData:!0},success:function(g){var l=x(!1),n=a(".photo-display",l);n.append(g.template);g=
a(".photo-item-wrapper:not(.h-hide)",n);y(g);z(l,0<g.length);u(l);l.dialog("option","position",{of:window});l.dialog("open")}});a(".photo-selector-galleries",c).tabs("destroy");c.dialog("close")});a(".js-photo-selector-cancel",b).offon("click",function(){console.log("Fileupload: cancel 2");a(document).data("gallery-container",null);var c=a(this).closest(".js-photo-selector-container");a(".photo-selector-galleries",c).tabs("destroy");c.dialog("close")})}function x(b,e){if(e&&0!=e.length)a(document).data("gallery-container",
e);else if(e=a(document).data("gallery-container"),!e)return a();if(e.hasClass("profile-media-photoupload-dialog")){var f=e;b&&(f.dialog("open"),u(f));return f}f=e.find(".js-photo-display");0==f.length?a(".js-photo-display").each(function(){if(a(this).data("associated-editor")==e.get(0))return f=a(this),!1}):(f.dialog({modal:!0,width:606,autoOpen:!1,showCloseButton:!1,closeOnEscape:!1,resizable:!1,showTitleBar:!1,dialogClass:"dialog-container upload-photo-dialog-container dialog-box"}),f.data("orig-width",
f.dialog("option","width")),f.data("associated-editor",e.get(0)),f.find(".b-form-input__file--hidden").prop("disabled",!1));b&&(f.dialog("open"),u(f));N(f);return f}function N(b){var e=b.find(".js-sortable-on-edit"),f=b.css("overflow")||"auto";e.length&&!e.data("sortable")&&e.sortable({forcePlaceholderSize:!1,placeholder:"photo-item-wrapper h-left sortable-placeholder",containment:"parent",tolerance:"pointer",start:function(m,c){a(".photo-item-wrapper:not(.h-hide)",e).removeClass("last-in-row");b.css("overflow",
"hidden")},update:function(m,c){m=a(".photo-item-wrapper:not(.h-hide)",e);y(m);z(b,0<m.length);u(b);b.css("overflow",f)}})}function u(b){var e=a(".photo-display",b),f=b.parent();e=a(".photo-item-wrapper:not(.h-hide)",e).length;!f.hasClass("has-scrollbar")&&6<=e&&(e=p.getScrollbarWidth(),f.addClass("has-scrollbar"),b.dialog("option","width",b.dialog("option","width")+e+11))}function y(b){b.removeClass("last-in-row").filter(":not(.h-hide)").filter(e=>2==e%3).addClass("last-in-row")}function z(b,e){a(".js-continue-button, .btnPhotoUploadSave",
b).toggle(e);w(b,e?"upload_more":void 0)}function O(){a(document).offon("click.removephoto",".photo-display .photo-item .js-remove-icon",function(){var b=a(this).closest(".photo-item-wrapper"),e=a(".filedataid",b).data("nodeid"),f=b.parents(".js-photo-display").last();"undefined"!==typeof e&&(e=a.inArray(e,A),-1!=e&&A.splice(e,1));b.addClass("h-hide");b=f.find(".photo-item-wrapper:not(.h-hide)");b.length<=F.ATTACHLIMIT&&a(".js-attach-limit-warning",f).hide();y(b);6>=b.length&&(f.parent().removeClass("has-scrollbar"),
f.dialog("option","width",f.data("orig-width")));z(f,0<b.length)});a(document).offon("blur.photocaption",".photo-display .photo-caption .caption-box",function(){a(this).scrollTop(0)});K.bindEditFormEventHandlers("gallery")}function P(){var b=jQuery.fn.fileupload;jQuery.fn.fileupload=function(){arguments&&arguments[0]&&arguments[0].dropZone&&"vb-self"==arguments[0].dropZone&&(arguments[0].dropZone=a(this));arguments&&arguments[0]&&arguments[0].dropZone&&arguments[0].dropZone.addClass("js-fileupload-dropzone");
return b.apply(this,arguments)}}function I(b){b&&b.each((e,f)=>{e=a(f);e.data("vb-dropzone-overlay-initialized")||(a("<div />").html(r.get("drop_files_here_to_upload")).addClass("h-hide-imp js-fileupload-dropzone-overlay fileupload-dropzone-overlay").appendTo(e),e.css("position","relative").data("vb-dropzone-overlay-initialized","1"))});a(".js-fileupload-dropzone-overlay").toggleClass("h-hide-imp",!b)}function Q(b){var e=a(".js-fileupload-dropzone"),f=e.filter(":visible"),m=e.filter(".b-content-entry-panel__content--attachment");
b.preventDefault();if(!(1>e.length)&&(0==f.length&&1==m.length&&(a(".js-content-entry").find(".js-toolbar-secondary .b-toolbar__item").filter(function(){return"b-content-entry-panel__content--attachment"==a(this).data("panel")}).trigger("click"),f=e.filter(":visible")),0<f.length)){I(f);a(".js-fileupload-dropzone-overlay").removeClass("fileupload-dropzone-overlay--active");let c=b.originalEvent.dataTransfer;c.dropEffect="none";c.effectAllowed="none";a(b.target).parents().each(function(){var d=a(this);
if(d.is(".js-fileupload-dropzone"))return d.find(".js-fileupload-dropzone-overlay").addClass("fileupload-dropzone-overlay--active"),c.dropEffect="copy",c.effectAllowed="copy",!1})}}function J(b){b.preventDefault();I(!1)}function R(){B&&(clearTimeout(B),B=0)}function S(b){var e=this;B=setTimeout(()=>{J.call(e,b)},200)}let A=[],B=0;a(()=>{P();a:{if("FormData"in window&&"FileReader"in window){var b=document.createElement("div");if("draggable"in b||"ondragstart"in b&&"ondrop"in b){b=!0;break a}}b=!1}b&&
(b=a(document),b.on("dragover.contentdragstart",Q),b.on("drop{0} dragend{0}".format(".contentdragstart"),J),b.on("dragenter{0} dragover{0}".format(".contentdragenter"),R),b.on("dragleave.contentdragenter",S));E();O()});return{uploadFile:async function(b,e){"string"==typeof b&&(b=await L(b));return M(b,e)},setUploadButtonText:w,initializePhotoUpload:E,getUploadedPhotosDlg:x,adjustPhotoDialogForScrollbar:u,relocateLastInRowClass:y}})(jQuery,vBulletin,vBulletin.phrase,vBulletin.ajaxtools,vBulletin.conversation,
vBulletin.contentEntryBox,vBulletin.dialogtools);
