/**
 * Alpha Color Picker JS
 * Thanks to Braad Martin (You rock!): https://github.com/BraadMartin/components/tree/master/alpha-color-picker
 * License: GPL
 */
!function(i){function a(i){var a;return i=i.replace(/ /g,""),i.match(/rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/)?(a=100*parseFloat(i.match(/rgba\(\d+\,\d+\,\d+\,([^\)]+)\)/)[1]).toFixed(2),a=parseInt(a)):a=100,a}function r(i,a,r,n){var o,e,c;o=a.data("a8cIris"),e=a.data("wpWpColorPicker"),o._color._alpha=i,c=o._color.toString(),a.val(c),e.toggler.css({"background-color":c}),n&&t(i,r),a.wpColorPicker("color",c)}function t(i,a){a.slider("value",i),a.find(".ui-slider-handle").text(i.toString())}Color.prototype.toString=function(i){if("no-alpha"==i)return this.toCSS("rgba","1").replace(/\s+/g,"");if(1>this._alpha)return this.toCSS("rgba",this._alpha).replace(/\s+/g,"");var a=parseInt(this._color,10).toString(16);if(this.error)return"";if(a.length<6)for(var r=6-a.length-1;r>=0;r--)a="0"+a;return"#"+a},i.fn.alphaColorPicker=function(){return this.each(function(){var n,o,e,c,l,s,d,p,u,f,h;n=i(this),n.wrap('<div class="alpha-color-picker-wrap"></div>'),e=n.attr("data-palette")||"true",c=n.attr("data-show-opacity")||"true",l=n.attr("data-default-color")||"",s=-1!==e.indexOf("|")?e.split("|"):"false"!=e,o=n.val().replace(/\s+/g,""),""==o&&(o=l),d={change:function(i,r){var t,o,e,c;t=n.attr("data-customize-setting-link"),o=n.wpColorPicker("color"),l==o&&(e=a(o),u.find(".ui-slider-handle").text(e)),void 0!==wp.customize&&wp.customize(t,function(i){i.set(o)}),c=p.find(".transparency"),c.css("background-color",r.color.toString("no-alpha"))},palettes:s},n.wpColorPicker(d),p=n.parents(".wp-picker-container:first"),i('<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(p.find(".wp-picker-holder")),u=p.find(".alpha-slider"),f=a(o),h={create:function(a,r){var t=i(this).slider("value");i(this).find(".ui-slider-handle").text(t),i(this).siblings(".transparency ").css("background-color",o)},value:f,range:"max",step:1,min:0,max:100,animate:300},u.slider(h),"true"==c&&u.find(".ui-slider-handle").addClass("show-opacity"),p.find(".min-click-zone").on("click",function(){r(0,n,u,!0)}),p.find(".max-click-zone").on("click",function(){r(100,n,u,!0)}),p.find(".iris-palette").on("click",function(){var r,o;r=i(this).css("background-color"),o=a(r),t(o,u),100!=o&&(r=r.replace(/[^,]+(?=\))/,(o/100).toFixed(2))),n.wpColorPicker("color",r)}),p.find(".button.wp-picker-default").on("click",function(){t(a(l),u)}),n.on("input",function(){t(a(i(this).val()),u)}),u.slider().on("slide",function(a,t){r(parseFloat(t.value)/100,n,u,!1),i(this).find(".ui-slider-handle").text(t.value)})})}}(jQuery);