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