/* global Color */ /* global wp */ jQuery( document ).ready( function($) { 'use strict'; Color.prototype.toString = function(remove_alpha) { if (remove_alpha === 'no-alpha') { return this.toCSS( 'rgba', '1' ).replace( /\s+/g, '' ); } if (this._alpha < 1) { return this.toCSS( 'rgba', this._alpha ).replace( /\s+/g, '' ); } 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; }; $( '.azera-shop-color-control' ).each( function() { var $control = $( this ), value = $control.val().replace( /\s+/g, '' ), palette; // Manage Palettes var palette_input = Boolean( $control.attr( 'data-palette' ) ); if ( palette_input === false) { palette = false; } else if ( palette_input === true) { palette = true; } else { palette = $control.attr( 'data-palette' ).split( ',' ); } $control.wpColorPicker( { // change some things with the color picker clear: function() { }, change: function(event, ui) { // send ajax request to wp.customizer to enable Save & Publish button var _new_value = $control.val(); var key = $control.attr( 'data-customize-setting-link' ); wp.customize( key, function(obj) { obj.set( _new_value ); } ); // change the background color of our transparency container whenever a color is updated var $transparency = $control.parents( '.wp-picker-container:first' ).find( '.transparency' ); // we only want to show the color at 100% alpha $transparency.css( 'backgroundColor', ui.color.toString( 'no-alpha' ) ); }, palettes: palette // remove the color palettes } ); $( '