/*=======================================================================*\
|| ###################################################################### ||
|| # vBulletin 5.5.2
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2019 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   # ||
|| ###################################################################### ||
\*========================================================================*/
window.vBulletin=window.vBulletin||{};window.vBulletin.phrase=window.vBulletin.phrase||{};window.vBulletin.phrase.precache=window.vBulletin.phrase.precache||[];window.vBulletin.phrase.precache=$.merge(window.vBulletin.phrase.precache,["cancel","changed_extra_css_warning","error_loading_css","error_setting_theme","loading_themes","no_preview_available","revert","revert_extra_css_warning","save_and_continue","success","there_are_no_themes_installed","confirm_action"]);window.vBulletin.options=window.vBulletin.options||{};window.vBulletin.options.precache=window.vBulletin.options.precache||[];window.vBulletin.options.precache=$.merge(window.vBulletin.options.precache,["styleid"]);(function(U){var G=false,k,T="",Y=0,i="",H=0,N=false,D=function(m){var l=this;vBulletin.assertUserHasAdminPermission("canusesitebuilder",l,function(){B.call(l)});return false},B=function(l,q){var p=U(this),o=U(document.body),n=!p.hasClass("selected"),m=true;if(typeof l!="undefined"){n=!!l}if(typeof q!="undefined"){m=!!q}if(n){U(document.body).addClass("js-edit-mode-style");P();f();U(".js-style-panel").css("display","none").removeClass("h-hide").slideDown("400",W)}else{e(!n,p);U(".js-style-panel").slideUp("fast",function(){U(document.body).removeClass("js-edit-mode-style");if(!m){return }var r=window.location.href;if(r.indexOf("adminAction=stylePanel&")!=-1){r=r.replace("adminAction=stylePanel&","")}else{r=r.replace("?adminAction=stylePanel","")}if(r!=window.location.href){window.location.href=r}else{window.location.reload(true)}})}},c=function(l){B(false,l)},e=function(l,m){U(document).trigger("vb-toggle-sitebuilder-menu",{enableButtons:l,currentButton:m})},f=function(){},I=function(m,n){var l=U(".js-theme-selector__list:visible .js-theme-selector__theme-radio:checked").val();vBulletin.AJAX({call:"/ajax/api/style/setDefaultStyle",data:{styleid:l},error_phrase:"error_setting_theme",success:function(){var o=new Date();o.setDate(o.getDate()+365);U.cookie(pageData.cookie_prefix+"userstyleid",l,{path:pageData.cookie_path,domain:pageData.cookie_domain,expires:o});if(typeof n=="undefined"||n){c(true)}}});return false},O=function(l){c(false);return false},b=function(l){h(k.getValue(),null,Y,i)},K=function(l){openConfirmDialog({title:vBulletin.phrase.get("revert"),message:vBulletin.phrase.get("revert_extra_css_warning"),iconType:"warning",onClickYes:function(m){T="";k.setValue("");h("",X,Y,i)}});return false},V=function(l){c(true);return false},A=function(l){k.setValue(T)},g=function(p,l,q){if(!l&&p&&p.target){var l=U(p.target).closest(".js-theme-selector__theme").data("preview-url")}if(!q){var q=U(p.target).closest(".js-theme-selector__list")}var o=q.closest(".js-panel").find(".js-theme-selector__theme-preview"),n,m=o.find("> img, > p");if(o.length!=1){return }if(l){n=U("<img />").prop("src",l)}else{n=U("<p />").addClass("b-theme-selector__theme-preview-message").text(vBulletin.phrase.get("no_preview_available"))}if(m.is("p")&&n.is("p")){m.fadeTo(200,"0.5",function(){U(this).fadeTo(400,1)})}else{m.css("zIndex","2");n.css("zIndex","1").hide();o.append(n);m.fadeOut({duration:300,queue:false,complete:function(){U(this).remove()}});n.fadeIn({duration:600,queue:false})}},R=function(){var l=U(this);l.closest(".js-theme-selector__list").find(".js-theme-selector__theme").removeClass("b-theme-selector__theme--selected js-theme-selector__theme--selected js-vbscroller-selected-item");l.closest(".js-theme-selector__theme").addClass("b-theme-selector__theme--selected js-theme-selector__theme--selected js-vbscroller-selected-item")},C=function(v,q,m){var p=this,o="js-theme-selector__theme b-theme-selector__theme h-margin-right-xl",r=U('<input type="radio" name="styleid" value="'+p.styleid+'" />').addClass("js-theme-selector__theme-radio b-theme-selector__theme-radio h-margin-none h-margin-right-s"),t=U("<label />").prop("title",p.title),s=U("<div />").addClass("h-margin-s h-margin-bottom-none b-theme-selector__theme-title").text(p.title.length>30?p.title.substr(0,20)+" ...":p.title),l=U("<img />").addClass("h-margin-s h-margin-bottom-m").prop("src",p.iconurl),n=U("<div />").addClass("b-theme-selector__theme-thumbnail");var u=function(w){var x=new Image();x.src=w};u(p.iconurl);u(p.previewurl);if(q==p.styleid){r.prop("checked","checked");r.attr("checked","checked");g({},p.previewurl,v);o+=" js-theme-selector__theme--selected b-theme-selector__theme--selected js-vbscroller-selected-item"}n.append(l);s.prepend(r);t.append(n).append(s);U("<div />").addClass(o).data("preview-url",(p.previewurl||"")).append(t).appendTo(v);Z.call(l.get(0),2)},Z=function(v){var p=U(this);p.css({maxWidth:"none",maxHeight:"none"});var o=p.outerWidth()||0,w=p.outerHeight()||0,l=o>w?"height":"width",x,r,m,s=false;if(o>0&&w>0){var u=false;if(l=="width"&&o>100){x=100/o;r=o*x;m=w*x;u=true}else{if(l=="height"&&w>100){x=100/w;r=o*x;m=w*x;u=true}else{}}if(u){p.removeClass("h-margin-s h-margin-bottom-m").css({maxWidth:r,maxHeight:m});var q=p.parent();var t=U("<div />").addClass("b-theme-selector__image-resize-wrapper h-margin-s h-margin-bottom-m").css({width:100,height:100,overflow:"hidden"});t.append(p);q.append(t);s=true}}else{}if(!s){p.css({maxWidth:"100px",maxHeight:"100px"});if(v>0){var n=this;window.setTimeout(function(){Z.call(n,--v)},100)}else{var n=this;p.off("load").on("load",function(){Z.call(n,--v)})}}},j=function(m,p){var n,o=0,l=vBulletin.options.get("styleid");p.html("");if(m&&m.themes){U.each(m.themes,function(){C.apply(this,[p,l,o]);++o})}if(!o){U("<div />").addClass("b-theme-selector__message").text(vBulletin.phrase.get("there_are_no_themes_installed")).appendTo(p)}else{d(p)}},d=function(l){if(vBulletin.vBScroller&&vBulletin.vBScroller.initializeScroller){var m=l.closest(".js-vbscroller-wrapper");vBulletin.vBScroller.initializeScroller(m)}},E=function(o,p,m){var n=U(this).closest(".js-theme-selector__theme"),l=n.find(".js-theme-selector__theme-radio");if(n.is(".js-theme-selector__theme--selected")){return }l.attr("checked","checked");R.call(this);g.call(this,o);if(m.liveUpdate){I.call(this,o,false)}},J=function(m){var l={liveUpdate:false,container:document};m=U.extend({},l,m);var o=U(".js-theme-selector__list",m.containerSelector);function n(p){E.call(this,p,o,m)}o.off("change",".js-theme-selector__theme-radio").on("change",".js-theme-selector__theme-radio",n);o.off("click",".js-theme-selector__theme label img").on("click",".js-theme-selector__theme label img",n);vBulletin.AJAX({call:"/ajax/api/style/getThemeInfo",error:function(){var p=U("<div />").addClass("b-theme-selector__message").text(vBulletin.phrase.get("error_fetching_themes"));o.html(p)},success:function(p){j.apply(this,[p,o])}})},F=function(m){var l=U(m.target);if(l.is(".js_stylepanel_selectStyle")&&isNaN(parseFloat(l.val()))){return false}if(l.is(".js_stylepanel_selectTemplate")&&l.val()==""){return false}currentText=k.getValue();if(T!=k.getValue()){L()}else{X()}},S=function(l){if(typeof l=="string"){l=parseInt(l,10)}H=!!l;U(".js-textonly").prop("checked",H)},M=function(){var o=new Date(),l=U(".js_stylepanel_selectStyle").val(),m=U(".js-sb-sprite-icon-preview-img"),n=m.attr("src");n=n.replace(/styleid=\d+/,"styleid="+l);n=n.replace(/ts=\d+/,"ts="+o.getTime());m.attr("src",n)},a=function(m){var l=U(".js-sb-sprite-icon-preview");if(!l.data("preview-initialized")){U(".js-sb-sprite-icon-preview-bg-btn").css("background-color",function(){return U(this).data("bgcolor")}).on("click",function(){var n=U(this);U(".js-sb-sprite-icon-preview-img-wrapper").css("background-color",n.data("bgcolor"));U(".js-sb-sprite-icon-preview-bg-btn").removeClass("sb-sprite-icon-preview-bg-btn--selected");n.addClass("sb-sprite-icon-preview-bg-btn--selected");return false}).eq(1).click();l.data("preview-initialized","1")}if(m&&m=="css_sprite_icons_general.css"){l.removeClass("h-hide");M()}else{l.addClass("h-hide")}},X=function(){var n=U(".js_stylepanel_selectStyle"),m=U(".js_stylepanel_selectTemplate");if(!N){var l=U.cookie(pageData.cookie_prefix+"userstyleid");if(l){n.val(l)}n.selectBox();m.selectBox();N=true}vBulletin.AJAX({call:"/ajax/api/template/getCssTemplateSbEditor",data:{styleid:n.val(),templateName:m.val()},success:function(o){if(typeof (o.template)=="undefined"||typeof (o.template["template_un"])=="undefined"){T="";S(0)}else{T=o.template["template_un"];S(o.template["textonly"])}k.setValue(T);T=k.getValue();Y=n.val();i=m.val();a(i)},api_error:function(){T="";k.setValue("");Y=n.val();i=m.val();S(0);a("")},error_phrase:"error_loading_css",})},L=function(){openConfirmDialog({title:vBulletin.phrase.get("confirm_action"),message:vBulletin.phrase.get("changed_extra_css_warning"),iconType:"warning",buttonLabel:{yesLabel:vBulletin.phrase.get("save_and_continue"),noLabel:vBulletin.phrase.get("cancel")},onClickYes:function(l){h(k.getValue(),X,Y,i)},onClickNo:function(l){U(".js_stylepanel_selectStyle").selectBox("value",Y);U(".js_stylepanel_selectTemplate").selectBox("value",i);S(H)}})},h=function(p,n,l,m){var o=U(".js-textonly").prop("checked")?1:0;vBulletin.AJAX({call:"/ajax/api/template/saveCssTemplateSbEditor",data:{text:p,styleid:l,templateName:m,textonly:o},success:function(){T=p;M();vBulletin.alert("success","css_saved","",n)},error_phrase:"error_saving_css",})},W=function(){function l(){if(typeof (k)=="undefined"){var m=U(".sb-style-panel_cssextraedit").get(0);k=CodeMirror.fromTextArea(m,{mode:"css",lineNumbers:true});var n=U(m).attr("dir");if(n){U(k.display.wrapper).attr("dir",n)}T="";U(".js-style-panel #admin-stylepanel-csseditor .js_stylepanel_selectStyle").change();U(".js-tooltip[title]").qtip({style:{classes:"ui-tooltip-shadow"}});U(".sb-style-panel .tab-item a").off("click",l)}}U(".sb-style-panel .tab-item a").off("click",l).on("click",l);if(U(".js-style-panel .js-admin-stylepanel-csseditor").is(":visible")){l()}},P=function(){if(G){return }U(".js-style-panel .tabs").tabs();var l;l=".js-style-panel #admin-stylepanel-themes .js-button--save";U(document).off("click",l).on("click",l,I);l=".js-style-panel #admin-stylepanel-themes .js-button--cancel";U(document).off("click",l).on("click",l,O);l=".js-style-panel #admin-stylepanel-csseditor .js-button--revert";U(document).off("click",l).on("click",l,K);l=".js-style-panel #admin-stylepanel-csseditor .js-button--cancel";U(document).off("click",l).on("click",l,A);l=".js-style-panel #admin-stylepanel-csseditor .js-button--close";U(document).off("click",l).on("click",l,V);l=".js-style-panel #admin-stylepanel-csseditor .js-button--save";U(document).off("click",l).on("click",l,b);var m=".js-style-panel #admin-stylepanel-csseditor ";l=m+".js_stylepanel_selectStyle, "+m+".js_stylepanel_selectTemplate";U(document).off("change",l).on("change",l,F);if(U(".js-style-panel .js-theme-selector__container").length==1){J({liveUpdate:false,containerSelector:".js-style-panel"})}if(U(".js-style-panel .js-admin-stylepanel-csseditor").length==1){W()}G=true},Q=function(){U(function(){U(document).on("vb-sitebuilder-panel--style",D);if(typeof (pageData.adminAction)!="undefined"&&pageData.adminAction=="stylePanel"){U(".js-top-menu-tab--style").click()}})};window.vBulletin=window.vBulletin||{};window.vBulletin.sitebuilder=window.vBulletin.sitebuilder||{};window.vBulletin.sitebuilder.initThemesInQuickConfig=function(){J({liveUpdate:true,containerSelector:".js-config-site-panel"})};Q()})(jQuery);