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