/*
 =======================================================================*\
|| ###################################################################### ||
|| # 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   # ||
|| ###################################################################### ||
\*========================================================================*/
let activeElementId=0,colorPickerType=0,pickerReady=!1,colors="00 33 66 99 CC FF".split(" "),specialColors="#000000 #333333 #666666 #999999 #CCCCCC #FFFFFF #FF0000 #00FF00 #0000FF #FFFF00 #00FFFF #FF00FF".split(" ");
function preview_color(a){var b=fetch_object("color_"+a);a=fetch_object("preview_"+a);if(is_transparent(b.value))a.style.background="none",a.style.borderStyle="dashed",a.title="";else{b=b.value;try{var c=get_color_value(b);a.style.background=c;a.style.borderStyle="inset";a.title=""}catch(d){c=vBAdmin.renderPhrase("css_value_invalid",b),a.style.background="url("+IMGDIR_MISC+"/cp_help.png) no-repeat center",a.style.borderStyle="dashed",a.title=c}}}
function set_swatch_color(a,b,c){$("#swatches tr").eq(b).find("td").eq(a).css("background-color",c)}
function init_color_picker(a){colorPickerType=a;fetch_object("colorPickerType").value=a;var b,c;if(2>a)for(b=0;12>b;b++)set_swatch_color(0,b,"#000000"),set_swatch_color(1,b,specialColors[b]),set_swatch_color(2,b,"#000000");switch(a){case 0:green=[5,4,3,2,1,0,0,1,2,3,4,5];blue=[0,0,0,5,4,3,2,1,0,0,1,2,3,4,5,5,4,3,2,1,0];for(b=0;12>b;b++)for(c=3;21>c;c++){var d=2*Math.floor((20-c)/6)+Math.floor(b/6);var f=green[b];var g=blue[c];set_swatch_color(c,b,"#"+colors[d]+colors[f]+colors[g])}break;case 1:green=
[0,0,0,0,1,2,3,4,5,0,1,2,3,4,5,0,1,2,3,4,5];blue=[0,1,2,3,4,5,0,1,2,3,4,5];for(b=0;12>b;b++)for(c=3;21>c;c++)d=Math.floor((c-3)/6)+3*Math.floor(b/6),f=green[c],g=blue[b],set_swatch_color(c,b,"#"+colors[d]+colors[f]+colors[g]);break;case 2:var e=255;for(b=0;12>b;b++)for(c=0;21>c;c++)set_swatch_color(c,b,"rgb("+e+","+e+","+e+")"),e--,4==e&&(e=0);break;case 3:case 4:case 5:case 6:case 7:case 8:var h=e=255;for(b=0;12>b;b++)for(c=0;21>c;c++){acolor=Math.round(h);bcolor=Math.round(e);0>acolor&&(acolor=
0);switch(a){case 3:d=acolor;g=f=bcolor;break;case 4:d=bcolor;f=acolor;g=bcolor;break;case 5:f=d=bcolor;g=acolor;break;case 6:f=d=acolor;g=bcolor;break;case 7:d=acolor;f=bcolor;g=acolor;break;case 8:d=bcolor,g=f=acolor}set_swatch_color(c,b,"rgb("+d+","+f+","+g+")");1<e?e-=2.03174:(e=0,1.03<h&&(h-=2.03174))}break;default:return!1}return pickerReady=!0}function switch_color_picker(a){init_color_picker(((colorPickerType+a)%9+9)%9)}
function open_color_picker(a,b){if(pickerReady)if(b=$("#colorPicker"),activeElementId==a&&b.is(":visible"))close_color_picker();else{activeElementId=a;var c=$("#color_"+a);a=$("#preview_"+a);var d=a.css("background-color");$("#oldColor").css("background",d);$("#newColor").css("background",d);$("#txtColor").val(c.val());d=a.offset();c=d.left+a.outerWidth();a=d.top+a.outerHeight();var f=b.outerWidth(),g=b.outerHeight();let e=$(window);d=e.scrollLeft()+5;f=e.scrollLeft()+e.width()-f-5;let h=e.scrollTop()+
5;g=e.scrollTop()+e.height()-g-5;c=Math.max(d,Math.min(c,f));a=Math.max(h,Math.min(a,g));b.css({left:c+"px",top:a+"px"}).show()}else alert(vBAdmin.renderPhrase("color_picker_not_ready"))}function close_color_picker(){activeElementId=0;$("#colorPicker").hide()}function col_over(a){color=fetch_hex_color(a.style.backgroundColor);fetch_object("newColor").style.background=color;fetch_object("txtColor").value=color}
function col_click(a){color="transparent"==a?a:get_color_value(a.style.backgroundColor);fetch_object("color_"+activeElementId).value=color;preview_color(activeElementId);close_color_picker()}function get_color_value(a){if(a.match(/rgb\(\s*(\d+),\s*(\d+)\s*,\s*(\d+)\s*\)/i))return fetch_hex_color(a);a.match(/^\s*#?(?:[a-fA-F0-9]{3}|[a-fA-F0-9]{6})\s*$/i)&&"#"!=a.substr(0,1)&&(a="#"+a);return a}
function fetch_hex_color(a){if("r"==a.substr(0,1)){let b=a.match(/rgb\(\s*(\d+),\s*(\d+)\s*,\s*(\d+)\s*\)/i);for(a=1;4>a;a++)b[a]=parseInt(b[a]).toString(16),2>b[a].length&&(b[a]="0"+b[a]);a="#"+(b[1]+b[2]+b[3]).toUpperCase()}return a.toUpperCase()}function get_rgb_value(a){return a.match(/rgb\(\s*(\d+),\s*(\d+)\s*,\s*(\d+)\s*\)/i)?match[0]:a.match(/^\s*#?(?:[a-fA-F0-9]{3}|[a-fA-F0-9]{6})\s*$/i)?fetch_rgb_color(a):a}
function fetch_rgb_color(a){let b,c;a=a.replace(/^#/,"");if(3==a.length)b=a[0]+a[0],c=a[1]+a[1],a=a[2]+a[2];else if(6==a.length)b=a.substr(0,2),c=a.substr(2,2),a=a.substr(4,2);else return"";return"rgb("+[b,c,a].map(d=>parseInt(d,16)).join(", ")+")"}function is_transparent(a){return""==a||"none"==a||"transparent"==a}
$(()=>{if(fetch_object("color_0")){for(var a=0;;){let b=$("#color_"+a);if(0==b.length)break;b.on("change",((c,d)=>preview_color(c)).bind(null,a));$("#preview_"+a).on("click",((c,d)=>open_color_picker(c,d)).bind(null,a));preview_color(a);a++}a=Number($("#colorPickerType").val());0!=a&&init_color_picker(a);a=$("#colorPicker");$("#swatches").on("click","td",b=>col_click(b.currentTarget));$("#swatches").on("mouseover","td",b=>col_over(b.currentTarget));$(".js-colorpicker-close").on("click",close_color_picker);
$(".js-colorpicker-switch").on("click",()=>switch_color_picker(1));$(".js-colorpicker-transparent").on("click",()=>col_click("transparent"));a.on("wheel",b=>{b.preventDefault();switch_color_picker(Math.sign(b.originalEvent.deltaY))});a.on("contextmenu",b=>{b.preventDefault();switch_color_picker(1)});pickerReady=!0}});
