/**! * wp-color-picker-alpha * * Overwrite Automattic Iris for enabled Alpha Channel in wpColorPicker * Only run in input and is defined data alpha in true * * Version: 2.0 * https://github.com/kallookoo/wp-color-picker-alpha * Licensed under the GPLv2 license. */ (function($) { if (!$.wp.wpColorPicker.prototype._hasAlpha) { // Variable for some backgrounds ( grid ) var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHJJREFUeNpi+P///4EDBxiAGMgCCCAGFB5AADGCRBgYDh48CCRZIJS9vT2QBAggFBkmBiSAogxFBiCAoHogAKIKAlBUYTELAiAmEtABEECk20G6BOmuIl0CIMBQ/IEMkO0myiSSraaaBhZcbkUOs0HuBwDplz5uFJ3Z4gAAAABJRU5ErkJggg==', // html stuff for wpColorPicker copy of the original color-picker.js _before = '', _after = '
', _wrap = '
', _button = '', _wrappingLabel = '', _wrappingLabelText = ''; /** * Overwrite Color * for enable support rbga */ Color.fn.toString = function() { 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) { hex = ('00000' + hex).substr(-6); } return '#' + hex; }; /** * Overwrite wpColorPicker */ $.widget('wp.wpColorPicker', $.wp.wpColorPicker, { _hasAlpha: true, /** * @summary Creates the color picker. * * Creates the color picker, sets default values, css classes and wraps it all in HTML. * * @since 3.5.0 * * @access private * * @returns {void} */ _create: function() { // Return early if Iris support is missing. if (!$.support.iris) { return; } var self = this, el = self.element; // Override default options with options bound to the element. $.extend(self.options, el.data()); // Create a color picker which only allows adjustments to the hue. if (self.options.type === 'hue') { return self._createHueOnly(); } // Bind the close event. self.close = $.proxy(self.close, self); self.initialValue = el.val(); // Add a CSS class to the input field. el.addClass('wp-color-picker'); /* * Check if there's already a wrapping label, e.g. in the Customizer. * If there's no label, add a default one to match the Customizer template. */ if (!el.parent('label').length) { // Wrap the input field in the default label. el.wrap(_wrappingLabel); // Insert the default label text. self.wrappingLabelText = $(_wrappingLabelText) .insertBefore(el) .text(wpColorPickerL10n.defaultLabel); } /* * At this point, either it's the standalone version or the Customizer * one, we have a wrapping label to use as hook in the DOM, let's store it. */ self.wrappingLabel = el.parent(); // Wrap the label in the main wrapper. self.wrappingLabel.wrap(_wrap); // Store a reference to the main wrapper. self.wrap = self.wrappingLabel.parent(); // Set up the toggle button and insert it before the wrapping label. self.toggler = $(_before) .insertBefore(self.wrappingLabel) .css({backgroundColor: self.initialValue}); // Set the toggle button span element text. self.toggler.find('.wp-color-result-text').text(wpColorPickerL10n.pick); // Set up the Iris container and insert it after the wrapping label. self.pickerContainer = $(_after).insertAfter(self.wrappingLabel); // Store a reference to the Clear/Default button. self.button = $(_button); // Set up the Clear/Default button. if (self.options.defaultColor) { self.button .addClass('wp-picker-default') .val(wpColorPickerL10n.defaultString) .attr('aria-label', wpColorPickerL10n.defaultAriaLabel); } else { self.button .addClass('wp-picker-clear') .val(wpColorPickerL10n.clear) .attr('aria-label', wpColorPickerL10n.clearAriaLabel); } // Wrap the wrapping label in its wrapper and append the Clear/Default button. self.wrappingLabel .wrap('