Вход Регистрация
Файл: templates/default/js/colorpicker.js
Строк: 999
<?php
/*
 * jQuery MiniColors: A tiny color picker built on jQuery
 *
 * Copyright Cory LaViska for A Beautiful Site, LLC. (http://www.abeautifulsite.net/)
 *
 * Dual-licensed under the MIT and GPL Version 2 licenses
 *
*/
if(jQuery) (function($) {
    
    
// Yay, MiniColors!
    
$.minicolors = {
        
// Default settings
        
defaultSettings: {
            
animationSpeed100,
            
animationEasing'swing',
            
changenull,
            
changeDelay0,
            
control'hue',
            
defaultValue'',
            
hidenull,
            
hideSpeed100,
            
inlinefalse,
            
letterCase'lowercase',
            
opacityfalse,
            
position'default',
            
shownull,
            
showSpeed100,
            
swatchPosition'left',
            
textfieldtrue,
            
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':
                    if( 
data === undefined ) {
                        
// Getter
                        
return $(this).attr('data-opacity');
                    } else {
                        
// Setter
                        
$(this).each( function() {
                            
refresh($(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() {
                            
refresh($(this).val(data));
                        });
                        return $(
this);
                    }
                
                
// Initializes the control
                
case 'create':
                default:
                    if( 
method !== 'create' data method;
                    $(
this).each( function() {
                        
init($(this), data);
                    });
                    return $(
this);
                
            }
            
        }
    });
    
    
// Initialize input elements
    
function init(inputsettings) {
        
        var 
minicolors = $('<span class="minicolors" />'),
            
defaultSettings = $.minicolors.defaultSettings;
        
        
// Do nothing if already initialized
        
if( input.data('minicolors-initialized') ) return;
        
        
// Handle settings
        
settings = $.extend(true, {}, defaultSettingssettings);
        
        
// The wrapper
        
minicolors
            
.addClass('minicolors-theme-' settings.theme)
            .
addClass('minicolors-swatch-position-' settings.swatchPosition)
            .
toggleClass('minicolors-swatch-left'settings.swatchPosition === 'left')
            .
toggleClass('minicolors-with-opacity'settings.opacity);
        
        
// Custom positioning
        
if( settings.position !== undefined ) {
            $.
each(settings.position.split(' '), function() {
                
minicolors.addClass('minicolors-position-' this);
            });
        }
        
        
// The input
        
input
            
.addClass('minicolors-input')
            .
data('minicolors-initialized'true)
            .
data('minicolors-settings'settings)
            .
prop('size'7)
            .
prop('maxlength'7)
            .
wrap(minicolors)
            .
after(
                
'<span class="minicolors-panel minicolors-slider-' settings.control '">' 
                    
'<span class="minicolors-slider">' 
                        
'<span class="minicolors-picker"></span>' +
                    
'</span>' 
                    
'<span class="minicolors-opacity-slider">' 
                        
'<span class="minicolors-picker"></span>' +
                    
'</span>' +
                    
'<span class="minicolors-grid">' +
                        
'<span class="minicolors-grid-inner"></span>' +
                        
'<span class="minicolors-picker"><span></span></span>' +
                    
'</span>' +
                
'</span>'
            
);
        
        
// Prevent text selection in IE
        
input.parent().find('.minicolors-panel').on('selectstart', function() { return false; }).end();
        
        
// Detect swatch position
        
if( settings.swatchPosition === 'left' ) {
            
// Left
            
input.before('<span class="minicolors-swatch"><span></span></span>');
        } else {
            
// Right
            
input.after('<span class="minicolors-swatch"><span></span></span>');
        }
        
        
// Disable textfield
        
if( !settings.textfield input.addClass('minicolors-hidden');
        
        
// Inline controls
        
if( settings.inline input.parent().addClass('minicolors-inline');
        
        
updateFromInput(inputfalsetrue);
        
    }
    
    
// 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')
            .
removeProp('maxlength')
            .
removeClass('minicolors-input');
        
        
// Remove the wrap and destroy whatever remains
        
minicolors.before(input).remove();
        
    }
    
    
// Refresh the specified control
    
function refresh(input) {
        
updateFromInput(input);
    }
    
    
// 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-input').each( function() {
            
            var 
input = $(this),
                
settings input.data('minicolors-settings'),
                
minicolors input.parent();
            
            
// Don't hide inline controls
            
if( settings.inline ) return;
            
            
minicolors.find('.minicolors-panel').fadeOut(settings.hideSpeed, function() {
                if(
minicolors.hasClass('minicolors-focus')) {
                    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 
huesaturationbrightnessrgbxyrphi,
            
            
hex input.val(),
            
opacity input.attr('data-opacity'),
            
            
// Helpful references
            
minicolors input.parent(),
            
settings input.data('minicolors-settings'),
            
panel minicolors.find('.minicolors-panel'),
            
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') ) {
            
            
// 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())), 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())), 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())), 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;
                
            }
        
            
// Adjust case
            
input.valconvertCase(hexsettings.letterCase) );
            
        }
        
        
// Handle opacity
        
if( target.is('.minicolors-opacity-slider') ) {
            if( 
settings.opacity ) {
                
opacity parseFloat(- (opacityPos.opacitySlider.height())).toFixed(2);
            } else {
                
opacity 1;
            }
            if( 
settings.opacity input.attr('data-opacity'opacity);
        }
        
        
// Set swatch color
        
swatch.find('SPAN').css({
            
backgroundColorhex,
            
opacityopacity
        
});
        
        
// Handle change event
        
doChange(inputhexopacity);
        
    }
    
    
// Sets the color picker values from the input
    
function updateFromInput(inputpreserveInputValuefirstRun) {
        
        var 
hex,
            
hsb,
            
opacity,
            
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
        
hex convertCase(parseHex(input.val(), true), settings.letterCase);
        if( !
hex hex convertCase(parseHex(settings.defaultValuetrue));
        
hsb hex2hsb(hex);
        
        
// Update input value
        
if( !preserveInputValue input.val(hex);
        
        
// 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');
        }
        
        
// 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;
                
        }
        
        
// Handle change event
        
if( !firstRun doChange(inputhexopacity);
        
    }
    
    
// Runs the change and changeDelay callbacks
    
function doChange(inputhexopacity) {
        
        var 
settings input.data('minicolors-settings');
        
        
// Only run if it actually changed
        
if( hex opacity !== input.data('minicolors-lastChange') ) {
            
            
// Remember last-changed value
            
input.data('minicolors-lastChange'hex opacity);
            
            
// 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), hexopacity);
                    }, 
settings.changeDelay));
                } else {
                    
// Call immediately
                    
settings.change.call(input.get(0), hexopacity);
                }
            }
            
        }
    
    }
    
    
// 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;
    }
    
    
// Genearates 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(/[^A-F0-9]/ig'');
        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;
    }
    
    
// Keeps value within min and max
    
function keepWithin(valueminmax) {
        if( 
value min value min;
        if( 
value max value max;
        return 
value;
    }
    
    
// 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 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 {
            
rhex >> 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();
            $(
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');
        })
        
// Toggle panel when swatch is clicked
        
.on('mousedown.minicolors touchstart.minicolors''.minicolors-swatch', function(event) {
            var 
input = $(this).parent().find('.minicolors-input'),
                
minicolors input.parent();
            if( 
minicolors.hasClass('minicolors-focus') ) {
                
hide(input);
            } else {
                
show(input);
            }
        })
        
// Show on focus
        
.on('focus.minicolors''.minicolors-input', function(event) {
            var 
input = $(this);
            if( !
input.data('minicolors-initialized') ) return;
            
show(input);
        })
        
// Fix hex on blur
        
.on('blur.minicolors''.minicolors-input', function(event) {
            var 
input = $(this),
                
settings input.data('minicolors-settings');
            if( !
input.data('minicolors-initialized') ) return;
            
            
// Parse Hex
            
input.val(parseHex(input.val(), true));
            
            
// Is it blank?
            
if( input.val() === '' input.val(parseHex(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 
27// esc
                    
hide();
                    
input.blur();
                    break;
            }
        })
        
// Update on keyup
        
.on('keyup.minicolors''.minicolors-input', function(event) {
            var 
input = $(this);
            if( !
input.data('minicolors-initialized') ) return;
            
updateFromInput(inputtrue);
        })
        
// Update on paste
        
.on('paste.minicolors''.minicolors-input', function(event) {
            var 
input = $(this);
            if( !
input.data('minicolors-initialized') ) return;
            
setTimeout( function() {
                
updateFromInput(inputtrue);
            }, 
1);
        });
    
})(
jQuery);
?>
Онлайн: 0
Реклама