/*
 =======================================================================*\
|| ###################################################################### ||
|| # 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(["saving"],["commentminchars"]);
vBulletin.media=function(d,k,r,E){function t(a){return a.is(".js-profile-media-container")?a:a.closest(".js-profile-media-container")}function w(a){return d(".js-profile-media-container",a)}function n(a=null){return z[t(a).data("key")]}function l(a){a=parseInt(a,10);Number.isNaN(a)&&(a=0);return a}function F(a){let b=a.data("photos-perpage")||50;if(A)return b;let c=a.is(":visible");c||a.removeClass("h-hide");let e=Math.floor(a.width()/128);c||a.addClass("h-hide");return 0==b%e||b<=e?b:b-b%e}function u(a,
b){let c=n(a);r.render({template:"profile_media_content",data:{userid:a.data("user-id"),pageno:b,perpage:a.data("perpage")},success:function(e){d(".js-mediacontent",a).html(e.template).removeClass("h-hide");d(".profileMediaDetailContainer",a).empty();x(a,!1);c.galleryData.currentMediaPage=b;v(a,"a");e=a.closest(".tabs").find(".widget-tabs-nav");e.length&&!k.isScrolledIntoView(e)&&d("html,body").animate({scrollTop:e.offset().top},"slow")},title_phrase:"profile_media"})}function y(a,b,c,e){d(a.currentTarget);
a=e.galleryData;var f=l(e.$mediaPageCount.html());let g=d(".profileMediaDetailContainer",c).is(":visible"),h=g?a.currentGalleryPage:a.currentMediaPage;b="current"==b?l(e.$mediaCurrentPage.val()):h+b;if(0<b&&b<=f)if(g){if(!a.currentNodeId&&!a.currentUserId)return!1;q(c,{pageno:b,perpage:"default"})}else u(c,b),c=c.closest(".tab"),e=e.filterHistory,a=k.makePaginatedUrl(location.href,b),c.length&&e.isEnabled()?(f=c.data("url-path"),b={from:"media_filter",page:b||1,tab:f?f:"#"+c.attr("id")},e.pushState(b,
document.title,a)):allowHistory&&(location.href=a);else B(e,h,f);return!1}function B(a,b,c){a.$mediaPrevPage.toggleClass("h-disabled",1>=b);a.$mediaNextPage.toggleClass("h-disabled",b>=c);a.$mediaCurrentPage.val(b);a.$mediaPageCount.text(c)}function v(a,b){if("a"==b){var c=".js-medialist";b="currentMediaPage"}else c="v"==b?".media-video-list":".js-album-detail",b="currentGalleryPage";c=d(c,a);a=n(a);b=a.galleryData[b];c=Number(c.data("totalpages"))||Math.max(b,1);B(a,b,c)}function G(a){let b=w(a),
c=n(b),e="1"==a.find(".conversation-toolbar-wrapper").data("allow-history"),f=new k.history.instance(e);c.allowHistory=e;c.filterHistory=f;f.isEnabled()&&f.setStateChange(function(g){g=f.getState();if("media_filter"==g.data.from){f.log(g.data,g.title,g.url);let h=a.closest(".ui-tabs"),m=h.find(".ui-tabs-nav > li").filter('li:has(a[href*="#{0}"])'.format(a.attr("id")));m.hasClass("ui-tabs-active")?u(b,g.data.page):k.selectTabByIndex.call(h,m.index())}},"media_filter")}function x(a,b){d(".profileMediaDetailContainer",
a).toggleClass("h-hide",!b);d(".profileMediaContainer",a).toggleClass("h-hide",b);d('.js-media-toggle[data-show-on="in-album"]',a).toggleClass("h-hide-imp",!b);d('.js-media-toggle[data-show-on="mediahome"]',a).toggleClass("h-hide-imp",b)}function q(a,b,c={}){let e=t(a),f=d(".profileMediaDetailContainer",e),g=n(e).galleryData;a={nodeid:g.currentNodeId,userid:g.currentUserId,channelid:g.currentChannelid,pageno:1,dateFilter:e.find(".media-filter-overlay input[name=filter_time]:checked").val(),albumid:0};
let h=d(".media-tab");b=d.extend({},a,b);isNaN(b.nodeid)||("default"==b.perpage&&(b.perpage=F(f)),0!=b.nodeid&&r.render({template:-1==b.nodeid?"profile_media_videolist":"profile_textphotodetail",data:b,success:function(m){let H=b.pageno;g.currentNodeId=b.nodeid;g.currentUserId=b.userid;g.currentGalleryPage=H;f.html(m.template);f.addClass("list-item").attr("data-nodeid",b.nodeid);d(".profile-media-uploadphotos",f).on("click",I);x(e,!0);b.perpage&&(h.data("perpage",b.perpage),h.data("callbacks",c));
k.initFlexGridFixLastRowAll();v(e,-1==b.nodeid?"v":"p");k.ensureFun(c.success)()},after_error:function(){k.ensureFun(c.error)()},complete:function(){k.ensureFun(c.complete)()},title_phrase:"profile_media"}))}function I(a){let b=d(a.currentTarget),c=p.getUploadedPhotosDlg(!1,b.closest(".js-album-detail"));(a=l(c.data("nodeid")))&&r.render({template:"media_addphotos",data:{nodeid:a},success:function(e){c.html(e.template);p.initializePhotoUpload(c.parent());e=c.find(".js-save-button");e.offon("click",
f=>J(f,c,t(b)));c.find(".js-cancel-button").offon("click",function(f){c.dialog("close")});p.relocateLastInRowClass(c.find(".photo-item-wrapper"));0<d(".photo-display .photo-item-wrapper:not(.h-hide)",c).length?(p.setUploadButtonText(c,"upload_more"),e.show()):e.hide();c.dialog("open");p.adjustPhotoDialogForScrollbar(c)},after_error:function(){c.dialog("close")},title_phrase:"profile_media"})}function J(a,b,c){let e=d(a.currentTarget),f=e.closest("form");b=d(a.target).closest(".profile-media-photoupload-dialog");
if(0<f.length){e.closest(".photo-display-container").find(".photo-item-wrapper:not(.h-hide)").each(function(h,m){h=parseInt(d(m).find(".filedataid").val(),10);isNaN(h)||(f.append('<input type="hidden" name="filedataid[]" value="'+h+'"/>'),d('<input type="hidden" name="title_'+h+'" />').val(d(m).find("textarea").val()).appendTo(f))});let g=d("button",f).prop("disabled",!0);r.ajax({url:f.attr("action"),data:f.serializeArray(),success:function(){b.dialog("close");q(c,n(c).galleryData.currentFilter)},
complete:function(){g.prop("disabled",!1)},title_phrase:"profile_media"})}else b.dialog("close")}function C(a){let b=t(a),c=d(".profileMediaContainer",b);c.is(":visible")||(c=d(".profileMediaDetailContainer",b));a={nodeid:l(a.data("nodeid"))||l(c.attr("data-nodeid")),userid:l(c.data("userid")),channelid:l(c.data("channelid")),albumid:l(a.data("albumid"))};0<a.nodeid&&(a.userid=0);return a}function D(a){let b=K(a);a.offon("click",".profile-media-backbtn",c=>{x(a,!1);a.find(".filtered-by").addClass("h-hide").find(".filter-text-wrapper").empty();
v(a,"a")});a.offon("change",".mediaCurrentPage",c=>y(c,"current",a,b));a.offon("click",".mediaPreviousPage",c=>y(c,-1,a,b));a.offon("click",".mediaNextPage",c=>y(c,1,a,b));a.offon("click",".albumLink",c=>{c=d(c.currentTarget);let e=C(c);e.pageno=1;e.perpage="default";b.galleryData.currentFilter=e;q(c,e)});L(a);M(a);d(".profileMediaContainer",a).length||N(a)}function K(a){let b=a.data("key");b||(b=O++,a.data("key",b));let c={};c.$mediaCurrentPage=d(".mediaCurrentPage",a);c.$mediaPageCount=d(".mediaPageCount",
a);c.$mediaPrevPage=d(".mediaPreviousPage",a);c.$mediaNextPage=d(".mediaNextPage",a);c.allowHistory=!1;c.filterHistory={};c.galleryData={mediaTypeFilter:!1,currentMediaPage:l(c.$mediaCurrentPage.val())||1,currentGalleryPage:1,currentNodeId:0,currentUserId:0,currentChannelid:0};return z[b]=c}function L(a){let b=a.closest(".tab");if(b.length){G(b);let c=a.closest(".canvas-widget").find(".js-module-top-anchor").attr("id");b.offon("click",".toolbar-filter",function(e){let f=d(".filter-wrapper",this);
f.toggleClass("selected");f.attr("aria-expanded",f.is(".selected"));d(".js-expanded-indicator",this).toggleClass("fa-caret-down fa-caret-up");d(e.target).closest(".conversation-toolbar-wrapper").find(".toolbar-filter-overlay").slideToggle("slow",function(){if(d(this).is(":visible")){d("body").off("click.media_filter").on("click.media_filter",function(h){0==d(h.target).closest(".toolbar-filter-overlay").length&&0==d(h.target).closest(".toolbar-filter").length&&(d("body").off("click.media_filter"),
d(".toolbar-filter",b).trigger("click"))});var g={};k.isScrolledIntoView(this,g)||d("html,body").animate({scrollTop:"+="+Math.abs(g.bottom)},"fast")}else d("body").off("click.media_filter")})});d("form.media-filter-overlay",b).trigger("reset");b.offon("change",".media-filter-overlay input[type=radio]",function(e,f){var g=n(w(b));let h=g.filterHistory;var m=h.isEnabled();if(!m&&g.allowHistory)return url=k.makePaginatedUrl(location.href,1),location.href=k.makeFilterUrl(url,this.name,this.value,b,c),
!0;e=C(d(e.target));b.data("perpage")&&(e.perpage=b.data("perpage"));q(a,e,b.data("callbacks"));d(this).data("bypass-filter-display")||k.conversation.displaySelectedFilterText(this,this.value);m&&!f&&(g=k.getSelectedFilters(d("form.toolbar-filter-overlay",b)),f=this.name,m=this.value,e=d(".conversation-toolbar-wrapper .filtered-by",b),g={from:"filter",page:1,tab:b.data("url-path")?b.data("url-path"):"#"+b.attr("id"),filters:g,filtervalue:m,filtername:f},e.data("reset")?url=location.pathname.replace(/\/page[0-9]+/,
""):(url=k.makePaginatedUrl(location.href,1),url=k.makeFilterUrl(url,f,m,b)),h.pushState(g,document.title,url),e.data("reset",null))});b.offon("click",".filtered-by .js-remove-filter",function(e){var f=n(w(b));e=d(this).closest(".filtered-by");let g=d(this).closest(".filter-text"),h=g.data("filter-name");if(!f.filterHistory.isEnabled()&&f.allowHistory)return location.href=k.makeFilterUrl(location.href,h,g.data("filter-value"),b,c),!1;$defaultSelectedFilter=d(".toolbar-filter-overlay .filter-options input[name={0}]".format(h),
b).prop("checked",!1).filter(".js-default-checked");g.remove();f=e.find(".filter-text").length;0==f?(e.addClass("h-hide"),e.data("reset",!0)):1==f&&e.find(".clear-all").addClass("h-hide");1==$defaultSelectedFilter.length&&($defaultSelectedFilter.data("bypass-filter-display",!0),$defaultSelectedFilter.trigger("click"),$defaultSelectedFilter.data("bypass-filter-display",null))})}}function M(a){let b=d(document),c=!1,e;a.offon("click",".profile-media-createvideo, .profile-media-upload",function(f){e=
d(f.currentTarget).is(".profile-media-upload")?"gallery":"video";c?c.dialog("open"):c=E.openModalDialog(d(".profileMediaEditContainer",a),{width:800,title:"profile_media",dialogClass:"js-profile-media",onOpen:function(g){k.ckeditor.initEditor(g.find(".js-ckeditor-init-on-focus"));p.initializePhotoUpload(g);let h="b-content-entry-panel__content--"+e;g.find('.b-toolbar__item[data-panel="'+h+'"]:not(.b-toolbar__item--active)').trigger("click");k.ckeditor.initEditorComponents(g);b.data("gallery-container",
d("."+h,g))},onClose:function(){b.data("gallery-container",null)}})});a.offon("afterSave",".js-album-detail",function(f,g){f=d(f.currentTarget);q(f,n(f).galleryData.currentFilter);return!1});a.offon("afterCancel",".js-album-detail",function(f){d(f.currentTarget).closest(".js-album-detail").find(".js-photo-preview").removeClass("h-hide-imp");return!0});b.offon("afterSave",".js-profile-media",function(f,g){if("b-content-entry-panel__content--gallery"==d(".b-toolbar__item--active",this).data("panel")){f=
l(d(".js-medialist",a).data("totalcount"));let h=l(d(".profileMediaContainer",a).data("albums-perpage"));f=Math.ceil((f+1)/h);g.alert&&k.alert("media",g.alert,"alert");u(a,f)}else u(a,1);return!1})}function N(a){var b=d(".profileMediaDetailContainer",a);let c=l(b.data("channelid")),e=l(b.data("nodeid"));if(c&&e){let f=n(a);b=l(b.find(".albumSlideShowPageNo").val())||1;f.galleryData.currentNodeId=e;f.galleryData.currentChannelid=c;f.galleryData.currentGalleryPage=b;v(a,"p");A=!0}}let p;if(!k.pageHasSelectors(["#media-tab",
"#video-tab",".album-widget"]))return!1;let O=1,z={};var A=!1;d(()=>{p=k.upload;let a=d(document);$mediacontainers=d(".js-profile-media-container");a.on("vb-instrument",b=>{b=d(b.target);b.is(".js-profile-media-container")&&D(b)});$mediacontainers.each((b,c)=>D(d(c)));k.initFlexGridFixLastRowAll()});return{loadGalleryById:q,getCurrentPage:function(a){return l(n(a).$mediaCurrentPage.val())}}}(jQuery,vBulletin,vBulletin.ajaxtools,vBulletin.dialogtools);
