Вход Регистрация
Файл: assets/plugins/jquery/jquery.minicolors.js
Строк: 1146
<?php
/*
 * jQuery MiniColors: A tiny color picker built on jQuery
 *
 * Copyright: Cory LaViska for A Beautiful Site, LLC: http://www.abeautifulsite.net/
 *
 * Contribute: https://github.com/claviska/jquery-minicolors
 *
 * @license: http://opensource.org/licenses/MIT
 *
 */
(function (factory) {
    
/* jshint ignore:start */
    
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);
    }
    
/* jshint ignore:end */
}(function ($) {

    
'use strict';

    
// Defaults
    
$.minicolors = {
        
defaults: {
            
animationSpeed50,
            
animationEasing'swing',
            
changenull,
            
changeDelay0,
            
control'hue',
            
dataUristrue,
            
defaultValue'',
            
format'hex',
            
hidenull,
            
hideSpeed100,
            
inlinefalse,
            
keywords'',
            
letterCase'lowercase',
            
opacityfalse,
            
position'bottom left',
            
shownull,
            
showSpeed100,
            
theme'default'
        
}
    };

    
// Public methods
    
$.extend($.fn, {
        
minicolors: function(methoddata) {

            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(truesettingsdata));
                        });
                    }
                    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' ) {
                                if( 
data.opacity ) {
                                    $(
this).attr('data-opacity'keepWithin(data.opacity01));
                                }
                                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(inputsettings) {

        var 
minicolors = $('<div class="minicolors" />'),
            
defaults = $.minicolors.defaults,
            
opacity input.attr('data-opacity'),
            
size;

        
// Do nothing if already initialized
        
if( input.data('minicolors-initialized') ) return;

        
// Handle settings
        
settings = $.extend(true, {}, defaultssettings);

        
// The wrapper
        
minicolors
            
.addClass('minicolors-theme-' settings.theme)
            .
toggleClass('minicolors-with-opacity'settings.opacity)
            .
toggleClass('minicolors-no-data-uris'settings.dataUris !== true);

        
// 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"><span class="minicolors-swatch-color"></span></span>');
            
input.next('.minicolors-swatch').on('click', function(event) {
                
event.preventDefault();
                
input.focus();
            });
        }

        
// Prevent text selection in IE
        
input.parent().find('.minicolors-panel').on('selectstart', function() { return false; }).end();

        
// Inline controls
        
if( settings.inline input.parent().addClass('minicolors-inline');

        
updateFromInput(inputfalse);

        
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(),
            
panel minicolors.find('.minicolors-panel'),
            
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');
        
panel
            
.stop(truetrue)
            .
fadeIn(settings.showSpeed, function() {
                if( 
settings.show settings.show.call(input.get(0));
            });

    }

    
// Hides all dropdown panels
    
function hide() {

        $(
'.minicolors-focus').each( function() {

            var 
minicolors = $(this),
                
input minicolors.find('.minicolors-input'),
                
panel minicolors.find('.minicolors-panel'),
                
settings input.data('minicolors-settings');

            
panel.fadeOut(settings.hideSpeed, function() {
                if( 
settings.hide settings.hide.call(input.get(0));
                
minicolors.removeClass('minicolors-focus');
            });

        });
    }

    
// Moves the selected picker
    
function move(targeteventanimate) {

        var 
input target.parents('.minicolors').find('.minicolors-input'),
            
settings input.data('minicolors-settings'),
            
picker target.find('[class$=-picker]'),
            
offsetX target.offset().left,
            
offsetY target.offset().top,
            
Math.round(event.pageX offsetX),
            
Math.round(event.pageY offsetY),
            
duration animate settings.animationSpeed 0,
            
wxwyrphi;

        
// Touch support
        
if( event.originalEvent.changedTouches ) {
            
event.originalEvent.changedTouches[0].pageX offsetX;
            
event.originalEvent.changedTouches[0].pageY offsetY;
        }

        
// Constrain picker to its container
        
if( 0;
        if( 
0;
        if( 
target.width() ) target.width();
        if( 
target.height() ) 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;
            
Math.sqrt(wx wx wy wy);
            
phi Math.atan2(wywx);
            if( 
phi phi += Math.PI 2;
            if( 
75 ) {
                
75;
                
75 - (75 Math.cos(phi));
                
75 - (75 Math.sin(phi));
            }
            
Math.round(x);
            
Math.round(y);
        }

        
// Move the picker
        
if( target.is('.minicolors-grid') ) {
            
picker
                
.stop(true)
                .
animate({
                    
top'px',
                    
left'px'
                
}, durationsettings.animationEasing, function() {
                    
updateFromControl(inputtarget);
                });
        } else {
            
picker
                
.stop(true)
                .
animate({
                    
top'px'
                
}, durationsettings.animationEasing, function() {
                    
updateFromControl(inputtarget);
                });
        }

    }

    
// Sets the input based on the color picker values
    
function updateFromControl(inputtarget) {

        function 
getCoords(pickercontainer) {

            var 
lefttop;
            if( !
picker.length || !container ) return null;
            
left picker.offset().left;
            
top picker.offset().top;

            return {
                
xleft container.offset().left + (picker.outerWidth() / 2),
                
ytop container.offset().top + (picker.outerHeight() / 2)
            };

        }

        var 
huesaturationbrightnessxyrphi,

            
hex input.val(),
            
opacity input.attr('data-opacity'),
            
value,

            
// Helpful references
            
minicolors input.parent(),
            
settings input.data('minicolors-settings'),
            
swatch minicolors.find('.minicolors-swatch'),

            
// Panel objects
            
grid minicolors.find('.minicolors-grid'),
            
slider minicolors.find('.minicolors-slider'),
            
opacitySlider minicolors.find('.minicolors-opacity-slider'),

            
// Picker objects
            
gridPicker grid.find('[class$=-picker]'),
            
sliderPicker slider.find('[class$=-picker]'),
            
opacityPicker opacitySlider.find('[class$=-picker]'),

            
// Picker positions
            
gridPos getCoords(gridPickergrid),
            
sliderPos getCoords(sliderPickerslider),
            
opacityPos getCoords(opacityPickeropacitySlider);

        
// 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
                    
= (grid.width() / 2) - gridPos.x;
                    
= (grid.height() / 2) - gridPos.y;
                    
Math.sqrt(y);
                    
phi Math.atan2(yx);
                    if( 
phi phi += Math.PI 2;
                    if( 
75 ) {
                        
75;
                        
gridPos.69 - (75 Math.cos(phi));
                        
gridPos.69 - (75 Math.sin(phi));
                    }
                    
saturation keepWithin(0.750100);
                    
hue keepWithin(phi 180 Math.PI0360);
                    
brightness keepWithin(100 Math.floor(sliderPos.* (100 slider.height())), 0100);
                    
hex hsb2hex({
                        
hhue,
                        
ssaturation,
                        
bbrightness
                    
});

                    
// Update UI
                    
slider.css('backgroundColor'hsb2hex({ hhuessaturationb100 }));
                    break;

                case 
'saturation':
                    
// Calculate hue, saturation, and brightness
                    
hue keepWithin(parseInt(gridPos.* (360 grid.width()), 10), 0360);
                    
saturation keepWithin(100 Math.floor(sliderPos.* (100 slider.height())), 0100);
                    
brightness keepWithin(100 Math.floor(gridPos.* (100 grid.height())), 0100);
                    
hex hsb2hex({
                        
hhue,
                        
ssaturation,
                        
bbrightness
                    
});

                    
// Update UI
                    
slider.css('backgroundColor'hsb2hex({ hhues100bbrightness }));
                    
minicolors.find('.minicolors-grid-inner').css('opacity'saturation 100);
                    break;

                case 
'brightness':
                    
// Calculate hue, saturation, and brightness
                    
hue keepWithin(parseInt(gridPos.* (360 grid.width()), 10), 0360);
                    
saturation keepWithin(100 Math.floor(gridPos.* (100 grid.height())), 0100);
                    
brightness keepWithin(100 Math.floor(sliderPos.* (100 slider.height())), 0100);
                    
hex hsb2hex({
                        
hhue,
                        
ssaturation,
                        
bbrightness
                    
});

                    
// Update UI
                    
slider.css('backgroundColor'hsb2hex({ hhuessaturationb100 }));
                    
minicolors.find('.minicolors-grid-inner').css('opacity'- (brightness 100));
                    break;

                default:
                    
// Calculate hue, saturation, and brightness
                    
hue keepWithin(360 parseInt(sliderPos.* (360 slider.height()), 10), 0360);
                    
saturation keepWithin(Math.floor(gridPos.* (100 grid.width())), 0100);
                    
brightness keepWithin(100 Math.floor(gridPos.* (100 grid.height())), 0100);
                    
hex hsb2hex({
                        
hhue,
                        
ssaturation,
                        
bbrightness
                    
});

                    
// Update UI
                    
grid.css('backgroundColor'hsb2hex({ hhues100b100 }));
                    break;

            }

            
// Handle opacity
            
if( settings.opacity ) {
                
opacity parseFloat(- (opacityPos.opacitySlider.height())).toFixed(2);
            } else {
                
opacity 1;
            }
            if( 
settings.opacity input.attr('data-opacity'opacity);

            
// Set color string
            
if( settings.format === 'rgb' ) {
                
// Returns RGB(A) string
                
var rgb hex2rgb(hex),
                    
opacity input.attr('data-opacity') === '' keepWithinparseFloatinput.attr('data-opacity') ).toFixed(2), 0);
                if( 
isNaNopacity ) || !settings.opacity opacity 1;

                if( 
input.minicolors('rgbObject').<= && rgb && settings.opacity) {
                    
// Set RGBA string if alpha
                    
value 'rgba(' rgb.', ' rgb.', ' rgb.', ' parseFloatopacity ) + ')';
                } else {
                    
// Set RGB string (alpha = 1)
                    
value 'rgb(' rgb.', ' rgb.', ' rgb.')';
                }
            } else {
                
// Returns hex color
                
value convertCasehexsettings.letterCase );
            }

            
// Update value from picker
            
input.valvalue );
        }

        
// Set swatch color
        
swatch.find('span').css({
            
backgroundColorhex,
            
opacityopacity
        
});

        
// Handle change event
        
doChange(inputvalueopacity);

    }

    
// Sets the color picker values from the input
    
function updateFromInput(inputpreserveInputValue) {

        var 
hex,
            
hsb,
            
opacity,
            
keywords,
            
alpha,
            
value,
            
xyrphi,

            
// Helpful references
            
minicolors input.parent(),
            
settings input.data('minicolors-settings'),
            
swatch minicolors.find('.minicolors-swatch'),

            
// Panel objects
            
grid minicolors.find('.minicolors-grid'),
            
slider minicolors.find('.minicolors-slider'),
            
opacitySlider minicolors.find('.minicolors-opacity-slider'),

            
// Picker objects
            
gridPicker grid.find('[class$=-picker]'),
            
sliderPicker slider.find('[class$=-picker]'),
            
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), 01);
            if( 
alpha ) {
                
input.attr('data-opacity'alpha);
            }
        } else {
            
hex convertCase(parseHex(input.val(), true), settings.letterCase);
        }

        if( !
hex ){
            
hex convertCase(parseInput(settings.defaultValuetrue), settings.letterCase);
        }
        
hsb hex2hsb(hex);

        
// Get array of lowercase keywords
        
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
            return $.
trim(a.toLowerCase());
        });

        
// Set color string
        
if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -) {
            
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') === '' keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 01);
            if( 
isNaN(opacity) ) opacity 1;
            
input.attr('data-opacity'opacity);
            
swatch.find('span').css('opacity'opacity);

            
// Set opacity picker position
            
keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0opacitySlider.height());
            
opacityPicker.css('top''px');
        }

        
// Set opacity to zero if input value is transparent
        
if( input.val().toLowerCase() === 'transparent' ) {
            
swatch.find('span').css('opacity'0);
        }

        
// Update swatch
        
swatch.find('span').css('backgroundColor'hex);

        
// Determine picker locations
        
switch(settings.control) {

            case 
'wheel':
                
// Set grid position
                
keepWithin(Math.ceil(hsb.0.75), 0grid.height() / 2);
                
phi hsb.Math.PI 180;
                
keepWithin(75 Math.cos(phi) * r0grid.width());
                
keepWithin(75 Math.sin(phi) * r0grid.height());
                
gridPicker.css({
                    
top'px',
                    
left'px'
                
});

                
// Set slider position
                
150 - (hsb./ (100 grid.height()));
                if( 
hex === '' 0;
                
sliderPicker.css('top''px');

                
// Update panel color
                
slider.css('backgroundColor'hsb2hex({ hhsb.hshsb.sb100 }));
                break;

            case 
'saturation':
                
// Set grid position
                
keepWithin((hsb.h) / 120150);
                
keepWithin(grid.height() - Math.ceil(hsb./ (100 grid.height())), 0grid.height());
                
gridPicker.css({
                    
top'px',
                    
left'px'
                
});

                
// Set slider position
                
keepWithin(slider.height() - (hsb.* (slider.height() / 100)), 0slider.height());
                
sliderPicker.css('top''px');

                
// Update UI
                
slider.css('backgroundColor'hsb2hex({ hhsb.hs100bhsb.}));
                
minicolors.find('.minicolors-grid-inner').css('opacity'hsb.100);
                break;

            case 
'brightness':
                
// Set grid position
                
keepWithin((hsb.h) / 120150);
                
keepWithin(grid.height() - Math.ceil(hsb./ (100 grid.height())), 0grid.height());
                
gridPicker.css({
                    
top'px',
                    
left'px'
                
});

                
// Set slider position
                
keepWithin(slider.height() - (hsb.* (slider.height() / 100)), 0slider.height());
                
sliderPicker.css('top''px');

                
// Update UI
                
slider.css('backgroundColor'hsb2hex({ hhsb.hshsb.sb100 }));
                
minicolors.find('.minicolors-grid-inner').css('opacity'- (hsb.100));
                break;

            default:
                
// Set grid position
                
keepWithin(Math.ceil(hsb./ (100 grid.width())), 0grid.width());
                
keepWithin(grid.height() - Math.ceil(hsb./ (100 grid.height())), 0grid.height());
                
gridPicker.css({
                    
top'px',
                    
left'px'
                
});

                
// Set slider position
                
keepWithin(slider.height() - (hsb./ (360 slider.height())), 0slider.height());
                
sliderPicker.css('top''px');

                
// Update panel color
                
grid.css('backgroundColor'hsb2hex({ hhsb.hs100b100 }));
                break;

        }

        
// Fire change event, but only if minicolors is fully initialized
        
if( input.data('minicolors-initialized') ) {
            
doChange(inputvalueopacity);
        }

    }

    
// Runs the change and changeDelay callbacks
    
function doChange(inputvalueopacity) {

        var 
settings input.data('minicolors-settings'),
            
lastChange input.data('minicolors-lastChange');

        
// Only run if it actually changed
        
if( !lastChange || lastChange.value !== value || lastChange.opacity !== opacity ) {

            
// Remember last-changed value
            
input.data('minicolors-lastChange', {
                
valuevalue,
                
opacityopacity
            
});

            
// 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), valueopacity);
                    }, 
settings.changeDelay));
                } else {
                    
// Call immediately
                    
settings.change.call(input.get(0), valueopacity);
                }
            }
            
input.trigger('change').trigger('input');
        }

    }

    
// Generates an RGB(A) object based on the input's value
    
function rgbObject(input) {
        var 
hex parseHex($(input).val(), true),
            
rgb hex2rgb(hex),
            
opacity = $(input).attr('data-opacity');
        if( !
rgb ) return null;
        if( 
opacity !== undefined ) $.extend(rgb, { aparseFloat(opacity) });
        return 
rgb;
    }

    
// Generates an RGB(A) string based on the input's value
    
function rgbString(inputalpha) {
        var 
hex parseHex($(input).val(), true),
            
rgb hex2rgb(hex),
            
opacity = $(input).attr('data-opacity');
        if( !
rgb ) return null;
        if( 
opacity === undefined opacity 1;
        if( 
alpha ) {
            return 
'rgba(' rgb.', ' rgb.', ' rgb.', ' parseFloat(opacity) + ')';
        } else {
            return 
'rgb(' rgb.', ' rgb.', ' rgb.')';
        }
    }

    
// Converts to the letter case specified in settings
    
function convertCase(stringletterCase) {
        return 
letterCase === 'uppercase' string.toUpperCase() : string.toLowerCase();
    }

    
// Parses a string and returns a valid hex string when possible
    
function parseHex(stringexpand) {
        
string string.replace(/^#/g, '');
        
if( !string.match(/^[A-F0-9]{3,6}/ig) ) return '';
        if( 
string.length !== && string.length !== ) return '';
        if( 
string.length === && 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(stringobj) {

        var 
values string.replace(/[^d,.]/g''),
            
rgba values.split(','),
            
output;

        
rgba[0] = keepWithin(parseInt(rgba[0], 10), 0255);
        
rgba[1] = keepWithin(parseInt(rgba[1], 10), 0255);
        
rgba[2] = keepWithin(parseInt(rgba[2], 10), 0255);
        if( 
rgba[3] ) {
            
rgba[3] = keepWithin(parseFloat(rgba[3], 10), 01);
        }

        
// Return RGBA object
        
if( obj ) {
            return {
                
rrgba[0],
                
grgba[1],
                
brgba[2],
                
argba[3] ? rgba[3] : null
            
};
        }

        
// Return RGBA string
        
if( typeof(rgba[3]) !== 'undefined' && rgba[3] <= ) {
            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(stringexpand) {
        if( 
isRgb(string) ) {
            
// Returns a valid rgb(a) string
            
return parseRgb(string);
        } else {
            return 
parseHex(stringexpand);
        }
    }

    
// Keeps value within min and max
    
function keepWithin(valueminmax) {
        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) {
        var 
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 
Math.round(hsb.h);
        var 
Math.round(hsb.255 100);
        var 
Math.round(hsb.255 100);
        if(
=== 0) {
            
rgb.rgb.rgb.v;
        } else {
            var 
t1 v;
            var 
t2 = (255 s) * 255;
            var 
t3 = (t1 t2) * (60) / 60;
            if( 
=== 360 0;
            if( 
60 ) { rgb.t1rgb.t2rgb.t2 t3; }
            else if( 
120 ) {rgb.t1rgb.t2rgb.t1 t3; }
            else if( 
180 ) {rgb.t1rgb.t2rgb.t2 t3; }
            else if( 
240 ) {rgb.t1rgb.t2rgb.t1 t3; }
            else if( 
300 ) {rgb.t1rgb.t2rgb.t2 t3; }
            else if( 
360 ) {rgb.t1rgb.t2rgb.t1 t3; }
            else { 
rgb.0rgb.0rgb.0; }
        }
        return {
            
rMath.round(rgb.r),
            
gMath.round(rgb.g),
            
bMath.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(nrval) {
            if (
val.length === 1hex[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.=== hsb.360;
        return 
hsb;
    }

    
// Converts an RGB object to an HSB object
    
function rgb2hsb(rgb) {
        var 
hsb = { h0s0b};
        var 
min Math.min(rgb.rrgb.grgb.b);
        var 
max Math.max(rgb.rrgb.grgb.b);
        var 
delta max min;
        
hsb.max;
        
hsb.max !== 255 delta max 0;
        if( 
hsb.!== ) {
            if( 
rgb.=== max ) {
                
hsb.= (rgb.rgb.b) / delta;
            } else if( 
rgb.=== max ) {
                
hsb.+ (rgb.rgb.r) / delta;
            } else {
                
hsb.+ (rgb.rgb.g) / delta;
            }
        } else {
            
hsb.= -1;
        }
        
hsb.*= 60;
        if( 
hsb.) {
            
hsb.+= 360;
        }
        
hsb.*= 100/255;
        
hsb.*= 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 {
            
/* jshint ignore:start */
            
rhex >> 16,
            
g: (hex 0x00FF00) >> 8,
            
b: (hex 0x0000FF)
            
/* jshint ignore:end */
        
};
    }

    
// 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();
            $(
document).data('minicolors-target'target);
            
move(targeteventtrue);
        })
        
// Move pickers
        
.on('mousemove.minicolors touchmove.minicolors', function(event) {
            var 
target = $(document).data('minicolors-target');
            if( 
target move(targetevent);
        })
        
// Stop moving
        
.on('mouseup.minicolors touchend.minicolors', function() {
            $(
this).removeData('minicolors-target');
        })
        
// Show panel when swatch is clicked
        
.on('mousedown.minicolors touchstart.minicolors''.minicolors-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),
                
settings input.data('minicolors-settings'),
                
keywords,
                
hex,
                
rgba,
                
swatchOpacity,
                
value;

            if( !
input.data('minicolors-initialized') ) return;

            
// Get array of lowercase keywords
            
keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
                return $.
trim(a.toLowerCase());
            });

            
// Set color string
            
if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -) {
                
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.',' rgba.',' rgba.',' input.attr('data-opacity') + ')') :
                        
parseRgb('rgb(' rgba.',' rgba.',' rgba.')');
                } 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-swatch > span')
                .
css('opacity'swatchOpacity);

            
// Set input value
            
input.val(value);

            
// Is it blank?
            
if( input.val() === '' input.val(parseInput(settings.defaultValuetrue));

            
// Adjust case
            
input.valconvertCase(input.val(), settings.letterCase) );

        })
        
// Handle keypresses
        
.on('keydown.minicolors''.minicolors-input', function(event) {
            var 
input = $(this);
            if( !
input.data('minicolors-initialized') ) return;
            switch(
event.keyCode) {
                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(inputtrue);
        })
        
// Update on paste
        
.on('paste.minicolors''.minicolors-input', function() {
            var 
input = $(this);
            if( !
input.data('minicolors-initialized') ) return;
            
setTimeout( function() {
                
updateFromInput(inputtrue);
            }, 
1);
        });

}));
?>
Онлайн: 1
Реклама