diff --git a/libraries/cms/html/behavior.php b/libraries/cms/html/behavior.php index 1c07cf22c1fbc..1ccc6d9a144a5 100644 --- a/libraries/cms/html/behavior.php +++ b/libraries/cms/html/behavior.php @@ -577,8 +577,11 @@ public static function colorpicker() jQuery(document).ready(function (){ jQuery('.minicolors').each(function() { jQuery(this).minicolors({ + alpha: jQuery(this).attr('data-alpha') || false, control: jQuery(this).attr('data-control') || 'hue', - position: jQuery(this).attr('data-position') || 'right', + keywords: jQuery(this).attr('data-keywords') || '', + opacity: jQuery(this).attr('data-validate') === 'color' ? false : jQuery(this).attr('data-alpha') || false, + position: jQuery(this).attr('data-position') || 'default', theme: 'bootstrap' }); }); diff --git a/libraries/joomla/form/fields/color.php b/libraries/joomla/form/fields/color.php index 98328c982aae3..2b83a8321c91e 100644 --- a/libraries/joomla/form/fields/color.php +++ b/libraries/joomla/form/fields/color.php @@ -40,7 +40,23 @@ class JFormFieldColor extends JFormField * @var mixed * @since 3.2 */ - protected $position = 'right'; + protected $position = 'default'; + + /** + * The keywords. + * + * @var string + * @since 3.5 + */ + protected $keywords = ''; + + /** + * The alpha. + * + * @var boolean + * @since 3.5 + */ + protected $alpha = false; /** * The colors. @@ -72,6 +88,8 @@ public function __get($name) switch ($name) { case 'control': + case 'keywords': + case 'alpha': case 'exclude': case 'colors': case 'split': @@ -98,6 +116,10 @@ public function __set($name, $value) case 'split': $value = (int) $value; case 'control': + case 'keywords': + $this->$name = (string) $value; + break; + case 'alpha': case 'exclude': case 'colors': $this->$name = (string) $value; @@ -128,10 +150,12 @@ public function setup(SimpleXMLElement $element, $value, $group = null) if ($return) { - $this->control = isset($this->element['control']) ? (string) $this->element['control'] : 'hue'; - $this->position = isset($this->element['position']) ? (string) $this->element['position'] : 'right'; - $this->colors = (string) $this->element['colors']; - $this->split = isset($this->element['split']) ? (int) $this->element['split'] : 3; + $this->control = isset($this->element['control']) ? (string) $this->element['control'] : 'hue'; + $this->position = isset($this->element['position']) ? (string) $this->element['position'] : 'default'; + $this->keywords = isset($this->element['keywords']) ? (string) $this->element['keywords'] : ''; + $this->alpha = isset($this->element['alpha']) ? $this->element['alpha'] : false; + $this->colors = (string) $this->element['colors']; + $this->split = isset($this->element['split']) ? (int) $this->element['split'] : 3; } return $return; @@ -152,22 +176,48 @@ protected function getInput() // Control value can be: hue (default), saturation, brightness, wheel or simple $control = $this->control; - // Position of the panel can be: right (default), left, top or bottom + // Position of the panel can be: right (default), left, top or bottom (default rtl is left) $position = ' data-position="' . $this->position . '"'; - $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; + // Validation of data can be: color (hex color value) + $validate = $this->validate ? ' data-validate="' . $this->validate . '"' : ''; + + $onchange = ! empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; $class = $this->class; $required = $this->required ? ' required aria-required="true"' : ''; $disabled = $this->disabled ? ' disabled' : ''; $autofocus = $this->autofocus ? ' autofocus' : ''; $color = strtolower($this->value); + $color = ! $color ? '' : $color; - if (!$color || in_array($color, array('none', 'transparent'))) + if (in_array($color, array('none', 'transparent'))) { - $color = 'none'; + $color = 'transparent'; + $alpha = '0'; + } + elseif (in_array($color, array('inherit', 'initial'))) + { + $color = $color; + $alpha = '1'; + } + elseif (strpos($color, 'rgba') !== false) + { + $color_rgba = str_replace(array('rgba(', ')'), '', $color); + $rgba_array = explode(',', $color_rgba); + + $hex_R = dechex($rgba_array[0]); + $hex_G = dechex($rgba_array[1]); + $hex_B = dechex($rgba_array[2]); + $alpha = $rgba_array[3]; + + $R = (strlen($hex_R) < 2) ? '0' . $hex_R : $hex_R; + $G = (strlen($hex_G) < 2) ? '0' . $hex_G : $hex_G; + $B = (strlen($hex_B) < 2) ? '0' . $hex_B : $hex_B; + + $color = '#' . $R . $G . $B; } - elseif ($color['0'] != '#') + elseif ($color && $color['0'] != '#') { $color = '#' . $color; } @@ -179,10 +229,10 @@ protected function getInput() $colors = strtolower($this->colors); - if (empty($colors)) + if (empty($colors) && ! $this->colors) { $colors = array( - 'none', + 'transparent', '#049cdb', '#46a546', '#9d261d', @@ -203,7 +253,7 @@ protected function getInput() $split = $this->split; - if (!$split) + if ( ! $split) { $count = count($colors); @@ -223,14 +273,14 @@ protected function getInput() $split = $split ? $split : 3; $html = array(); - $html[] = ''; + . $readonly . $disabled . $required . $onchange . $autocomplete . $autofocus . $validate + . $alpha . $opacity . $keywords . $direction . '/>'; } } } diff --git a/media/jui/css/jquery.minicolors.css b/media/jui/css/jquery.minicolors.css index 5dfa4c4b1437c..8de8d94f27722 100644 --- a/media/jui/css/jquery.minicolors.css +++ b/media/jui/css/jquery.minicolors.css @@ -246,6 +246,15 @@ width: 65px; margin: 0px; } +.minicolors-theme-bootstrap .hex{ + width: 65px; +} +.minicolors-theme-bootstrap .hex-keywords{ + width: 100px; +} +.minicolors-theme-bootstrap .rgba{ + width: auto; +} /* When the input is disabled */ .minicolors-theme-bootstrap .minicolors-input[disabled] { @@ -298,8 +307,8 @@ .minicolors-theme-bootstrap .minicolors-slider, .minicolors-theme-bootstrap .minicolors-opacity-slider { - top: 6px; - left: 157px; + top: 6px; + margin-left: 5px; } .minicolors-theme-bootstrap .minicolors-grid { diff --git a/media/jui/js/jquery.minicolors.js b/media/jui/js/jquery.minicolors.js index cc3f34974a3bd..6a0ce63e3a526 100644 --- a/media/jui/js/jquery.minicolors.js +++ b/media/jui/js/jquery.minicolors.js @@ -1,17 +1,24 @@ /* + * BASED ON: * 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 * + * ADAPTED BY: + * Cyril Rezé for Joomla! CMS (2015) - Search for JUI Tags for any new lines and code change */ if(jQuery) (function($) { - + // Yay, MiniColors! $.minicolors = { // Default settings defaultSettings: { + /**/ + /* Original: not exist */ + alpha: false, + /**/ animationSpeed: 100, animationEasing: 'swing', change: null, @@ -20,6 +27,10 @@ if(jQuery) (function($) { defaultValue: '', hide: null, hideSpeed: 100, + /**/ + /* Original: not exist */ + keywords: '', + /**/ inline: false, letterCase: 'lowercase', opacity: false, @@ -31,25 +42,25 @@ if(jQuery) (function($) { theme: 'default' } }; - + // 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': if( data === undefined ) { @@ -62,16 +73,16 @@ if(jQuery) (function($) { }); 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 ) { @@ -85,12 +96,12 @@ if(jQuery) (function($) { }); 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 ) { @@ -103,7 +114,7 @@ if(jQuery) (function($) { }); return $(this); } - + // Initializes the control case 'create': default: @@ -112,52 +123,90 @@ if(jQuery) (function($) { init($(this), data); }); return $(this); - + } - + } }); - + // Initialize input elements function init(input, settings) { - + var minicolors = $(''), defaultSettings = $.minicolors.defaultSettings; - + // Do nothing if already initialized if( input.data('minicolors-initialized') ) return; - + + // Reverse default position of the picket in case of rtl language + if( jQuery(document.querySelector("html")).attr('dir') == 'rtl' ) + { + if ( settings.position === 'default' ) settings.position = 'left'; + } + // Handle settings settings = $.extend(true, {}, defaultSettings, settings); - + + // Reverse left/right swatch position in case of rtl language + if( jQuery(document.querySelector("html")).attr('dir') == 'rtl' ) + { + if ( settings.swatchPosition === 'left' ) settings.swatchPosition = 'right'; + } + // 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); }); } - + + /**/ + /* Original: not exist */ + var validate = input.attr('data-validate'); + + if ( validate === 'color' ) { + $input_class = 'hex'; + $input_size = '7'; + $input_maxlength = '7'; + } else { + $input_class = settings.alpha ? 'rgba' : 'hex-keywords'; + $input_size = settings.alpha ? '25' : '11'; + $input_maxlength = settings.alpha ? '25' : '11'; + } + /**/ + // The input input + /**/ + /* Original: .addClass('minicolors-input') + */ + .addClass('minicolors-input ' + $input_class) + /**/ .data('minicolors-initialized', true) .data('minicolors-settings', settings) + /**/ + /* Original: .prop('size', 7) .prop('maxlength', 7) + */ + .prop('size', $input_size) + .prop('maxlength', $input_maxlength) + /**/ .wrap(minicolors) .after( - '' + - '' + + '' + + '' + '' + - '' + - '' + + '' + + '' + '' + '' + '' + @@ -166,10 +215,10 @@ if(jQuery) (function($) { '' + '' ); - + // Prevent text selection in IE input.parent().find('.minicolors-panel').on('selectstart', function() { return false; }).end(); - + // Detect swatch position if( settings.swatchPosition === 'left' ) { // Left @@ -178,22 +227,22 @@ if(jQuery) (function($) { // Right input.after(''); } - + // Disable textfield if( !settings.textfield ) input.addClass('minicolors-hidden'); - + // Inline controls if( settings.inline ) input.parent().addClass('minicolors-inline'); - + updateFromInput(input, false, true); - + } - + // Returns the input back to its original state function destroy(input) { - + var minicolors = input.parent(); - + // Revert the input element input .removeData('minicolors-initialized') @@ -201,67 +250,67 @@ if(jQuery) (function($) { .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') || + if( !input.data('minicolors-initialized') || + input.prop('disabled') || + minicolors.hasClass('minicolors-inline') || minicolors.hasClass('minicolors-focus') ) return; - + hide(); - + minicolors.addClass('minicolors-focus'); panel .stop(true, true) .fadeIn(settings.showSpeed, function() { if( settings.show ) settings.show.call(input); }); - + } - + // 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); } minicolors.removeClass('minicolors-focus'); - }); - + }); + }); } - + // Moves the selected picker function move(target, event, animate) { - + var input = target.parents('.minicolors').find('.minicolors-input'), settings = input.data('minicolors-settings'), picker = target.find('[class$=-picker]'), @@ -271,20 +320,20 @@ if(jQuery) (function($) { y = Math.round(event.pageY - offsetY), duration = animate ? settings.animationSpeed : 0, wx, wy, r, phi; - - + + // 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; @@ -300,7 +349,7 @@ if(jQuery) (function($) { x = Math.round(x); y = Math.round(y); } - + // Move the picker if( target.is('.minicolors-grid') ) { picker @@ -320,58 +369,63 @@ if(jQuery) (function($) { 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, rgb, x, y, r, phi, - + 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(gridPicker, grid), sliderPos = getCoords(sliderPicker, slider), opacityPos = getCoords(opacityPicker, opacitySlider); - + // Handle colors + /**/ + /* Original: if( target.is('.minicolors-grid, .minicolors-slider') ) { - + */ + 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; @@ -392,11 +446,11 @@ if(jQuery) (function($) { 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())), 0, 360); @@ -407,12 +461,12 @@ if(jQuery) (function($) { 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())), 0, 360); @@ -423,12 +477,12 @@ if(jQuery) (function($) { 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())), 0, 360); @@ -439,89 +493,156 @@ if(jQuery) (function($) { s: saturation, b: brightness }); - + // Update UI grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 })); break; - + } - - // Adjust case - input.val( convertCase(hex, settings.letterCase) ); - - } - - // Handle opacity - if( target.is('.minicolors-opacity-slider') ) { - if( settings.opacity ) { - opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2); + + /**/ + /* Original: in a separated target '.minicolors-opacity-slider' (before "Set swatch color") + // Handle opacity + if( target.is('.minicolors-opacity-slider') ) { + // This code below to handle opacity + } + */ + // Handle opacity + if ( settings.opacity ) { + opacity = parseFloat( 1 - ( opacityPos.y / opacitySlider.height() ) ).toFixed(2); } else { opacity = 1; } - if( settings.opacity ) input.attr('data-opacity', opacity); + if ( settings.opacity ) input.attr('data-opacity', opacity); + /**/ + + /**/ + /* Original: + // Adjust case + input.val( convertCase(hex, settings.letterCase) ); + */ + var rgb = hex2rgb(hex), + validate = input.attr('data-validate'), + opacity = input.attr('data-opacity') === '' ? 1 : keepWithin( parseFloat( input.attr('data-opacity') ).toFixed(2), 0, 1 ); + if ( isNaN( opacity ) ) opacity = 1; + + if ( validate === 'color' ) { + // Adjust case + value = convertCase( hex, settings.letterCase ); + } else { + if ( opacity == 0 && settings.keywords.indexOf('transparent') >= 0 ) { + // Set transparent if alpha is zero + value = 'transparent'; + } else if ( opacity && input.minicolors('rgbObject').a < 1 && rgb ) { + // Set a rgba string + value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat( opacity ) + ')'; + } else { + // Use hex color (opacity is 100%) and ajust case + value = convertCase( hex, settings.letterCase ); + } + } + // Update value from picker + input.val( value ); + /**/ } - + // Set swatch color swatch.find('SPAN').css({ backgroundColor: hex, opacity: opacity }); - + // Handle change event doChange(input, hex, opacity); - + } - + // Sets the color picker values from the input function updateFromInput(input, preserveInputValue, firstRun) { - + var hex, hsb, opacity, x, y, r, phi, - + // 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.defaultValue, true)); hsb = hex2hsb(hex); - + + /**/ + /* Original: // Update input value if( !preserveInputValue ) input.val(hex); - + */ + var rgb = hex2rgb(hex), + validate = input.attr('data-validate'), + opacity = input.attr('data-opacity') === '' ? 1 : keepWithin( parseFloat( input.attr('data-opacity') ).toFixed(2), 0, 1 ); + if ( isNaN(opacity) ) opacity = 1; + + if ( validate === 'color' ) { + // Returns hex color + value = hex; + } else { + if ( settings.keywords.indexOf(input.val()) >= 0 ) { + // Transparent ('none' will return 'transparent') and CSS-wide keywords + value = input.val(); + } else if ( opacity && input.minicolors('rgbObject').a < 1 && rgb ) { + // Creates rgba string + value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat( opacity ) + ')'; + } else { + // Returns hex color + value = 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', opacity); - + // Set opacity picker position y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height()); opacityPicker.css('top', y + 'px'); } - + + /**/ + /* Original: not exist */ + if (input.val() === '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 r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2); @@ -532,16 +653,16 @@ if(jQuery) (function($) { 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); @@ -549,18 +670,18 @@ if(jQuery) (function($) { 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); @@ -568,17 +689,17 @@ if(jQuery) (function($) { 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()); @@ -587,33 +708,33 @@ if(jQuery) (function($) { 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; - + } - + // Handle change event if( !firstRun ) doChange(input, hex, opacity); - + } - + // Runs the change and changeDelay callbacks function doChange(input, hex, opacity) { - + 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 ) { @@ -627,11 +748,11 @@ if(jQuery) (function($) { settings.change.call(input, hex, opacity); } } - + } - + } - + // Generates an RGB(A) object based on the input's value function rgbObject(input) { var hex = parseHex($(input).val(), true), @@ -641,7 +762,7 @@ if(jQuery) (function($) { if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) }); return rgb; } - + // Genearates an RGB(A) string based on the input's value function rgbString(input, alpha) { var hex = parseHex($(input).val(), true), @@ -655,12 +776,12 @@ if(jQuery) (function($) { 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(/[^A-F0-9]/ig, ''); @@ -670,14 +791,23 @@ if(jQuery) (function($) { } return '#' + string; } - + + /**/ + /* Original: not exist */ + // Checks if a string is a valid rgba string + function isRgba(string) { + rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); + return (rgb && rgb.length === 4) ? true : ''; + } + /**/ + // Keeps value within min and max function keepWithin(value, min, max) { 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 = {}; @@ -705,7 +835,7 @@ if(jQuery) (function($) { b: Math.round(rgb.b) }; } - + // Converts an RGB object to a hex string function rgb2hex(rgb) { var hex = [ @@ -718,19 +848,19 @@ if(jQuery) (function($) { }); 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 }; @@ -758,7 +888,7 @@ if(jQuery) (function($) { 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); @@ -768,7 +898,7 @@ if(jQuery) (function($) { b: (hex & 0x0000FF) }; } - + // Handle events $(document) // Hide on clicks outside of the control @@ -814,16 +944,44 @@ if(jQuery) (function($) { var input = $(this), settings = input.data('minicolors-settings'); if( !input.data('minicolors-initialized') ) return; - + + /**/ + /* Original: // Parse Hex input.val(parseHex(input.val(), true)); - + */ + var opacity = input.minicolors('rgbObject').a ? input.minicolors('rgbObject').a : '1', + validate = input.attr('data-validate'), + rgba = isRgba(input.val(), true), + hex = parseHex(input.val(), true); + + if ( validate === 'color' ) { + // Returns hex color + value = hex; + } else { + if ( settings.keywords.indexOf(input.val()) >= 0 ) { + // Transparent ('none' will return 'transparent') and CSS-wide keywords + value = input.val() === 'none' ? 'transparent' : input.val(); + } else if ( opacity && opacity < 1 && rgba ) { + // Generates rgba string + value = rgbString(input.val(), true); + } else if ( hex && input.val() !== 'transparent') { + // Returns hex color + value = hex; + } else { + // Input value is not an accepted color value + value = ''; + } + } + // Set input value + input.val(value); + /**/ + // Is it blank? if( input.val() === '' ) input.val(parseHex(settings.defaultValue, true)); - + // Adjust case input.val( convertCase(input.val(), settings.letterCase) ); - }) // Handle keypresses .on('keydown.minicolors', '.minicolors-input', function(event) { @@ -853,5 +1011,5 @@ if(jQuery) (function($) { updateFromInput(input, true); }, 1); }); - -})(jQuery); \ No newline at end of file + +})(jQuery); diff --git a/media/jui/js/jquery.minicolors.min.js b/media/jui/js/jquery.minicolors.min.js index 62816ad4b3a41..53c5205e06b72 100644 --- a/media/jui/js/jquery.minicolors.min.js +++ b/media/jui/js/jquery.minicolors.min.js @@ -1,9 +1,14 @@ -if(jQuery)(function($){$.minicolors={defaultSettings:{animationSpeed:100,animationEasing:'swing',change:null,changeDelay:0,control:'hue',defaultValue:'',hide:null,hideSpeed:100,inline:false,letterCase:'lowercase',opacity:false,position:'default',show:null,showSpeed:100,swatchPosition:'left',textfield:true,theme:'default'}};$.extend($.fn,{minicolors:function(method,data){switch(method){case'destroy':$(this).each(function(){destroy($(this));});return $(this);case'hide':hide();return $(this);case'opacity':if(data===undefined){return $(this).attr('data-opacity');}else{$(this).each(function(){refresh($(this).attr('data-opacity',data));});return $(this);} +if(jQuery)(function($){$.minicolors={defaultSettings:{alpha:false,animationSpeed:100,animationEasing:'swing',change:null,changeDelay:0,control:'hue',defaultValue:'',hide:null,hideSpeed:100,keywords:'',inline:false,letterCase:'lowercase',opacity:false,position:'default',show:null,showSpeed:100,swatchPosition:'left',textfield:true,theme:'default'}};$.extend($.fn,{minicolors:function(method,data){switch(method){case'destroy':$(this).each(function(){destroy($(this));});return $(this);case'hide':hide();return $(this);case'opacity':if(data===undefined){return $(this).attr('data-opacity');}else{$(this).each(function(){refresh($(this).attr('data-opacity',data));});return $(this);} case'rgbObject':return rgbObject($(this),method==='rgbaObject');case'rgbString':case'rgbaString':return rgbString($(this),method==='rgbaString') case'settings':if(data===undefined){return $(this).data('minicolors-settings');}else{$(this).each(function(){var settings=$(this).data('minicolors-settings')||{};destroy($(this));$(this).minicolors($.extend(true,settings,data));});return $(this);} case'show':show($(this).eq(0));return $(this);case'value':if(data===undefined){return $(this).val();}else{$(this).each(function(){refresh($(this).val(data));});return $(this);} -case'create':default:if(method!=='create')data=method;$(this).each(function(){init($(this),data);});return $(this);}}});function init(input,settings){var minicolors=$(''),defaultSettings=$.minicolors.defaultSettings;if(input.data('minicolors-initialized'))return;settings=$.extend(true,{},defaultSettings,settings);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);if(settings.position!==undefined){$.each(settings.position.split(' '),function(){minicolors.addClass('minicolors-position-'+this);});} -input.addClass('minicolors-input').data('minicolors-initialized',true).data('minicolors-settings',settings).prop('size',7).prop('maxlength',7).wrap(minicolors).after(''+''+''+''+''+''+''+''+''+''+''+'');input.parent().find('.minicolors-panel').on('selectstart',function(){return false;}).end();if(settings.swatchPosition==='left'){input.before('');}else{input.after('');} +case'create':default:if(method!=='create')data=method;$(this).each(function(){init($(this),data);});return $(this);}}});function init(input,settings){var minicolors=$(''),defaultSettings=$.minicolors.defaultSettings;if(input.data('minicolors-initialized'))return;if(jQuery(document.querySelector("html")).attr('dir')=='rtl') +{if(settings.position==='default')settings.position='left';} +settings=$.extend(true,{},defaultSettings,settings);if(jQuery(document.querySelector("html")).attr('dir')=='rtl') +{if(settings.swatchPosition==='left')settings.swatchPosition='right';} +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);if(settings.position!==undefined){$.each(settings.position.split(' '),function(){minicolors.addClass('minicolors-position-'+this);});} +var validate=input.attr('data-validate');if(validate==='color'){$input_class='hex';$input_size='7';$input_maxlength='7';}else{$input_class=settings.alpha?'rgba':'hex-keywords';$input_size=settings.alpha?'25':'11';$input_maxlength=settings.alpha?'25':'11';} +input.addClass('minicolors-input '+$input_class).data('minicolors-initialized',true).data('minicolors-settings',settings).prop('size',$input_size).prop('maxlength',$input_maxlength).wrap(minicolors).after(''+''+''+''+''+''+''+''+''+''+''+'');input.parent().find('.minicolors-panel').on('selectstart',function(){return false;}).end();if(settings.swatchPosition==='left'){input.before('');}else{input.after('');} if(!settings.textfield)input.addClass('minicolors-hidden');if(settings.inline)input.parent().addClass('minicolors-inline');updateFromInput(input,false,true);} function destroy(input){var minicolors=input.parent();input.removeData('minicolors-initialized').removeData('minicolors-settings').removeProp('size').removeProp('maxlength').removeClass('minicolors-input');minicolors.before(input).remove();} function refresh(input){updateFromInput(input);} @@ -14,15 +19,18 @@ function move(target,event,animate){var input=target.parents('.minicolors').find if(x<0)x=0;if(y<0)y=0;if(x>target.width())x=target.width();if(y>target.height())y=target.height();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);} if(target.is('.minicolors-grid')){picker.stop(true).animate({top:y+'px',left:x+'px'},duration,settings.animationEasing,function(){updateFromControl(input,target);});}else{picker.stop(true).animate({top:y+'px'},duration,settings.animationEasing,function(){updateFromControl(input,target);});}} -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,rgb,x,y,r,phi,hex=input.val(),opacity=input.attr('data-opacity'),minicolors=input.parent(),settings=input.data('minicolors-settings'),panel=minicolors.find('.minicolors-panel'),swatch=minicolors.find('.minicolors-swatch'),grid=minicolors.find('.minicolors-grid'),slider=minicolors.find('.minicolors-slider'),opacitySlider=minicolors.find('.minicolors-opacity-slider'),gridPicker=grid.find('[class$=-picker]'),sliderPicker=slider.find('[class$=-picker]'),opacityPicker=opacitySlider.find('[class$=-picker]'),gridPos=getCoords(gridPicker,grid),sliderPos=getCoords(sliderPicker,slider),opacityPos=getCoords(opacityPicker,opacitySlider);if(target.is('.minicolors-grid, .minicolors-slider')){switch(settings.control){case'wheel':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});slider.css('backgroundColor',hsb2hex({h:hue,s:saturation,b:100}));break;case'saturation':hue=keepWithin(parseInt(gridPos.x*(360/grid.width())),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});slider.css('backgroundColor',hsb2hex({h:hue,s:100,b:brightness}));minicolors.find('.minicolors-grid-inner').css('opacity',saturation/100);break;case'brightness':hue=keepWithin(parseInt(gridPos.x*(360/grid.width())),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});slider.css('backgroundColor',hsb2hex({h:hue,s:saturation,b:100}));minicolors.find('.minicolors-grid-inner').css('opacity',1-(brightness/100));break;default:hue=keepWithin(360-parseInt(sliderPos.y*(360/slider.height())),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});grid.css('backgroundColor',hsb2hex({h:hue,s:100,b:100}));break;} -input.val(convertCase(hex,settings.letterCase));} -if(target.is('.minicolors-opacity-slider')){if(settings.opacity){opacity=parseFloat(1-(opacityPos.y/opacitySlider.height())).toFixed(2);}else{opacity=1;} -if(settings.opacity)input.attr('data-opacity',opacity);} +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,rgb,x,y,r,phi,hex=input.val(),opacity=input.attr('data-opacity'),minicolors=input.parent(),settings=input.data('minicolors-settings'),panel=minicolors.find('.minicolors-panel'),swatch=minicolors.find('.minicolors-swatch'),grid=minicolors.find('.minicolors-grid'),slider=minicolors.find('.minicolors-slider'),opacitySlider=minicolors.find('.minicolors-opacity-slider'),gridPicker=grid.find('[class$=-picker]'),sliderPicker=slider.find('[class$=-picker]'),opacityPicker=opacitySlider.find('[class$=-picker]'),gridPos=getCoords(gridPicker,grid),sliderPos=getCoords(sliderPicker,slider),opacityPos=getCoords(opacityPicker,opacitySlider);if(target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider')){switch(settings.control){case'wheel':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});slider.css('backgroundColor',hsb2hex({h:hue,s:saturation,b:100}));break;case'saturation':hue=keepWithin(parseInt(gridPos.x*(360 / grid.width())),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});slider.css('backgroundColor',hsb2hex({h:hue,s:100,b:brightness}));minicolors.find('.minicolors-grid-inner').css('opacity',saturation / 100);break;case'brightness':hue=keepWithin(parseInt(gridPos.x*(360 / grid.width())),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});slider.css('backgroundColor',hsb2hex({h:hue,s:saturation,b:100}));minicolors.find('.minicolors-grid-inner').css('opacity',1-(brightness / 100));break;default:hue=keepWithin(360-parseInt(sliderPos.y*(360 / slider.height())),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});grid.css('backgroundColor',hsb2hex({h:hue,s:100,b:100}));break;} +if(settings.opacity){opacity=parseFloat(1-(opacityPos.y / opacitySlider.height())).toFixed(2);}else{opacity=1;} +if(settings.opacity)input.attr('data-opacity',opacity);var rgb=hex2rgb(hex),validate=input.attr('data-validate'),opacity=input.attr('data-opacity')===''?1:keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2),0,1);if(isNaN(opacity))opacity=1;if(validate==='color'){value=convertCase(hex,settings.letterCase);}else{if(opacity==0&&settings.keywords.indexOf('transparent')>=0){value='transparent';}else if(opacity&&input.minicolors('rgbObject').a<1&&rgb){value='rgba('+rgb.r+', '+rgb.g+', '+rgb.b+', '+parseFloat(opacity)+')';}else{value=convertCase(hex,settings.letterCase);}} +input.val(value);} swatch.find('SPAN').css({backgroundColor:hex,opacity:opacity});doChange(input,hex,opacity);} -function updateFromInput(input,preserveInputValue,firstRun){var hex,hsb,opacity,x,y,r,phi,minicolors=input.parent(),settings=input.data('minicolors-settings'),swatch=minicolors.find('.minicolors-swatch'),grid=minicolors.find('.minicolors-grid'),slider=minicolors.find('.minicolors-slider'),opacitySlider=minicolors.find('.minicolors-opacity-slider'),gridPicker=grid.find('[class$=-picker]'),sliderPicker=slider.find('[class$=-picker]'),opacityPicker=opacitySlider.find('[class$=-picker]');hex=convertCase(parseHex(input.val(),true),settings.letterCase);if(!hex)hex=convertCase(parseHex(settings.defaultValue,true));hsb=hex2hsb(hex);if(!preserveInputValue)input.val(hex);if(settings.opacity){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',opacity);y=keepWithin(opacitySlider.height()-(opacitySlider.height()*opacity),0,opacitySlider.height());opacityPicker.css('top',y+'px');} -swatch.find('SPAN').css('backgroundColor',hex);switch(settings.control){case'wheel':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'});y=150-(hsb.b/(100/grid.height()));if(hex==='')y=0;sliderPicker.css('top',y+'px');slider.css('backgroundColor',hsb2hex({h:hsb.h,s:hsb.s,b:100}));break;case'saturation':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'});y=keepWithin(slider.height()-(hsb.s*(slider.height()/100)),0,slider.height());sliderPicker.css('top',y+'px');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':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'});y=keepWithin(slider.height()-(hsb.b*(slider.height()/100)),0,slider.height());sliderPicker.css('top',y+'px');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: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'});y=keepWithin(slider.height()-(hsb.h/(360/slider.height())),0,slider.height());sliderPicker.css('top',y+'px');grid.css('backgroundColor',hsb2hex({h:hsb.h,s:100,b:100}));break;} +function updateFromInput(input,preserveInputValue,firstRun){var hex,hsb,opacity,x,y,r,phi,minicolors=input.parent(),settings=input.data('minicolors-settings'),swatch=minicolors.find('.minicolors-swatch'),grid=minicolors.find('.minicolors-grid'),slider=minicolors.find('.minicolors-slider'),opacitySlider=minicolors.find('.minicolors-opacity-slider'),gridPicker=grid.find('[class$=-picker]'),sliderPicker=slider.find('[class$=-picker]'),opacityPicker=opacitySlider.find('[class$=-picker]');hex=convertCase(parseHex(input.val(),true),settings.letterCase);if(!hex)hex=convertCase(parseHex(settings.defaultValue,true));hsb=hex2hsb(hex);var rgb=hex2rgb(hex),validate=input.attr('data-validate'),opacity=input.attr('data-opacity')===''?1:keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2),0,1);if(isNaN(opacity))opacity=1;if(validate==='color'){value=hex;}else{if(settings.keywords.indexOf(input.val())>=0){value=input.val();}else if(opacity&&input.minicolors('rgbObject').a<1&&rgb){value='rgba('+rgb.r+', '+rgb.g+', '+rgb.b+', '+parseFloat(opacity)+')';}else{value=hex;}} +if(!preserveInputValue){input.val(value);} +if(settings.opacity){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',opacity);y=keepWithin(opacitySlider.height()-(opacitySlider.height()*opacity),0,opacitySlider.height());opacityPicker.css('top',y+'px');} +if(input.val()==='transparent'){swatch.find('SPAN').css('opacity',0);} +swatch.find('SPAN').css('backgroundColor',hex);switch(settings.control){case'wheel':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'});y=150-(hsb.b /(100 / grid.height()));if(hex==='')y=0;sliderPicker.css('top',y+'px');slider.css('backgroundColor',hsb2hex({h:hsb.h,s:hsb.s,b:100}));break;case'saturation':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'});y=keepWithin(slider.height()-(hsb.s*(slider.height()/ 100)),0,slider.height());sliderPicker.css('top',y+'px');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':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'});y=keepWithin(slider.height()-(hsb.b*(slider.height()/ 100)),0,slider.height());sliderPicker.css('top',y+'px');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: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'});y=keepWithin(slider.height()-(hsb.h /(360 / slider.height())),0,slider.height());sliderPicker.css('top',y+'px');grid.css('backgroundColor',hsb2hex({h:hsb.h,s:100,b:100}));break;} if(!firstRun)doChange(input,hex,opacity);} function doChange(input,hex,opacity){var settings=input.data('minicolors-settings');if(hex+opacity!==input.data('minicolors-lastChange')){input.data('minicolors-lastChange',hex+opacity);if(settings.change){if(settings.changeDelay){clearTimeout(input.data('minicolors-changeTimeout'));input.data('minicolors-changeTimeout',setTimeout(function(){settings.change.call(input,hex,opacity);},settings.changeDelay));}else{settings.change.call(input,hex,opacity);}}}} 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,{a:parseFloat(opacity)});return rgb;} @@ -30,8 +38,9 @@ function rgbString(input,alpha){var hex=parseHex($(input).val(),true),rgb=hex2rg function convertCase(string,letterCase){return letterCase==='uppercase'?string.toUpperCase():string.toLowerCase();} function parseHex(string,expand){string=string.replace(/[^A-F0-9]/ig,'');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;} +function isRgba(string){rgb=string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);return(rgb&&rgb.length===4)?true:'';} function keepWithin(value,min,max){if(valuemax)value=max;return value;} -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;} +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;} @@ -42,8 +51,9 @@ return{r:Math.round(rgb.r),g:Math.round(rgb.g),b:Math.round(rgb.b)};} 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('');} function hsb2hex(hsb){return rgb2hex(hsb2rgb(hsb));} function hex2hsb(hex){var hsb=rgb2hsb(hex2rgb(hex));if(hsb.s===0)hsb.h=360;return hsb;} -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;} +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;} function hex2rgb(hex){hex=parseInt(((hex.indexOf('#')>-1)?hex.substring(1):hex),16);return{r:hex>>16,g:(hex&0x00FF00)>>8,b:(hex&0x0000FF)};} -$(document).on('mousedown.minicolors touchstart.minicolors',function(event){if(!$(event.target).parents().add(event.target).hasClass('minicolors')){hide();}}).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(target,event,true);}).on('mousemove.minicolors touchmove.minicolors',function(event){var target=$(document).data('minicolors-target');if(target)move(target,event);}).on('mouseup.minicolors touchend.minicolors',function(){$(this).removeData('minicolors-target');}).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);}}).on('focus.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;show(input);}).on('blur.minicolors','.minicolors-input',function(event){var input=$(this),settings=input.data('minicolors-settings');if(!input.data('minicolors-initialized'))return;input.val(parseHex(input.val(),true));if(input.val()==='')input.val(parseHex(settings.defaultValue,true));input.val(convertCase(input.val(),settings.letterCase));}).on('keydown.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;switch(event.keyCode){case 9:hide();break;case 27:hide();input.blur();break;}}).on('keyup.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;updateFromInput(input,true);}).on('paste.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;setTimeout(function(){updateFromInput(input,true);},1);});})(jQuery); \ No newline at end of file +$(document).on('mousedown.minicolors touchstart.minicolors',function(event){if(!$(event.target).parents().add(event.target).hasClass('minicolors')){hide();}}).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(target,event,true);}).on('mousemove.minicolors touchmove.minicolors',function(event){var target=$(document).data('minicolors-target');if(target)move(target,event);}).on('mouseup.minicolors touchend.minicolors',function(){$(this).removeData('minicolors-target');}).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);}}).on('focus.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;show(input);}).on('blur.minicolors','.minicolors-input',function(event){var input=$(this),settings=input.data('minicolors-settings');if(!input.data('minicolors-initialized'))return;var opacity=input.minicolors('rgbObject').a?input.minicolors('rgbObject').a:'1',validate=input.attr('data-validate'),rgba=isRgba(input.val(),true),hex=parseHex(input.val(),true);if(validate==='color'){value=hex;}else{if(settings.keywords.indexOf(input.val())>=0){value=input.val()==='none'?'transparent':input.val();}else if(opacity&&opacity<1&&rgba){value=rgbString(input.val(),true);}else if(hex&&input.val()!=='transparent'){value=hex;}else{value='';}} +input.val(value);if(input.val()==='')input.val(parseHex(settings.defaultValue,true));input.val(convertCase(input.val(),settings.letterCase));}).on('keydown.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;switch(event.keyCode){case 9:hide();break;case 27:hide();input.blur();break;}}).on('keyup.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;updateFromInput(input,true);}).on('paste.minicolors','.minicolors-input',function(event){var input=$(this);if(!input.data('minicolors-initialized'))return;setTimeout(function(){updateFromInput(input,true);},1);});})(jQuery); diff --git a/media/jui/js/jquery.simplecolors.js b/media/jui/js/jquery.simplecolors.js index 0395f371d75e3..a3c4a9a2dc7c7 100644 --- a/media/jui/js/jquery.simplecolors.js +++ b/media/jui/js/jquery.simplecolors.js @@ -24,7 +24,7 @@ list += '
'; } else { var clss = 'simplecolors-swatch'; - if (color == 'none') { + if (color == 'none' || color == 'transparent') { clss += ' nocolor'; color = 'transparent'; } @@ -37,7 +37,7 @@ var color = this.select.val(); var clss = 'simplecolors-swatch'; - if (color == 'none') { + if (color == 'none' || color == 'transparent') { clss += ' nocolor'; color = 'transparent'; } @@ -63,7 +63,17 @@ show: function() { var panelpadding = 7; // Empirical value var pos = this.icon.offset(); - switch (this.select.attr('data-position')) { + + // Reverse default position of the picket in case of rtl language + if( jQuery(document.querySelector("html")).attr('dir') == 'rtl' + && this.select.attr('data-position') === 'default' ) + { + position = 'left'; + } else { + position = this.select.attr('data-position'); + } + + switch (position) { case 'top': this.panel.css({ left: pos.left - panelpadding, @@ -110,7 +120,7 @@ var bgcolor = ''; var clss = ''; if (target.parent().hasClass('nocolor')) { - color = 'none'; + color = 'transparent'; bgcolor = 'transparent'; clss = 'nocolor'; } else { diff --git a/media/jui/js/jquery.simplecolors.min.js b/media/jui/js/jquery.simplecolors.min.js index 748a98bd30296..4ee63697a2233 100644 --- a/media/jui/js/jquery.simplecolors.min.js +++ b/media/jui/js/jquery.simplecolors.min.js @@ -1,6 +1,10 @@ -(function($){var SimpleColorPicker=function(element,options){this.select=$(element);this.options=$.extend({},$.fn.simplecolors.defaults,options);this.select.hide();var list="";$("option",this.select).each(function(){var option=$(this);var color=option.val();if(option.text()=="-")list+="
";else{var clss="simplecolors-swatch";if(color=="none"){clss+=" nocolor";color="transparent"}if(option.attr("selected"))clss+=" active";list+=''}}); -var color=this.select.val();var clss="simplecolors-swatch";if(color=="none"){clss+=" nocolor";color="transparent"}this.icon=$('').insertAfter(this.select);this.icon.on("click",$.proxy(this.show,this));this.panel=$('').appendTo(document.body);this.panel.html(list);this.panel.on("click",$.proxy(this.click,this));$(document).on("mousedown",$.proxy(this.hide,this));this.panel.on("mousedown", -$.proxy(this.mousedown,this))};SimpleColorPicker.prototype={constructor:SimpleColorPicker,show:function(){var panelpadding=7;var pos=this.icon.offset();switch(this.select.attr("data-position")){case "top":this.panel.css({left:pos.left-panelpadding,top:pos.top-this.panel.outerHeight()-1});break;case "bottom":this.panel.css({left:pos.left-panelpadding,top:pos.top+this.icon.outerHeight()});break;case "left":this.panel.css({left:pos.left-this.panel.outerWidth(),top:pos.top-(this.panel.outerHeight()-this.icon.outerHeight())/ -2-1});break;case "right":default:this.panel.css({left:pos.left+this.icon.outerWidth(),top:pos.top-(this.panel.outerHeight()-this.icon.outerHeight())/2-1});break}this.panel.show(this.options.delay)},hide:function(){if(this.panel.css("display")!="none")this.panel.hide(this.options.delay)},click:function(e){var target=$(e.target);if(target.length===1)if(target[0].nodeName.toLowerCase()==="span"){var color="";var bgcolor="";var clss="";if(target.parent().hasClass("nocolor")){color="none";bgcolor="transparent"; -clss="nocolor"}else{color=this.rgb2hex(target.css("background-color"));bgcolor=color}target.parent().siblings().removeClass("active");target.parent().addClass("active");this.icon.removeClass("nocolor").addClass(clss);this.icon.find("span").css("background-color",bgcolor);this.hide();this.select.val(color).change()}},mousedown:function(e){e.stopPropagation();e.preventDefault()},rgb2hex:function(rgb){function hex(x){return("0"+parseInt(x,10).toString(16)).slice(-2)}var matches=rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); -if(matches===null)return rgb;else return"#"+hex(matches[1])+hex(matches[2])+hex(matches[3])}};$.fn.simplecolors=function(option){return this.each(function(){var $this=$(this),data=$this.data("simplecolors"),options=typeof option==="object"&&option;if(!data)$this.data("simplecolors",data=new SimpleColorPicker(this,options));if(typeof option==="string")data[option]()})};$.fn.simplecolors.Constructor=SimpleColorPicker;$.fn.simplecolors.defaults={delay:0}})(jQuery); +(function($){var SimpleColorPicker=function(element,options){this.select=$(element);this.options=$.extend({},$.fn.simplecolors.defaults,options);this.select.hide();var list='';$('option',this.select).each(function(){var option=$(this);var color=option.val();if(option.text()=='-'){list+='
';}else{var clss='simplecolors-swatch';if(color=='none'||color=='transparent'){clss+=' nocolor';color='transparent';} +if(option.attr('selected')){clss+=' active';} +list+='';}});var color=this.select.val();var clss='simplecolors-swatch';if(color=='none'||color=='transparent'){clss+=' nocolor';color='transparent';} +this.icon=$('').insertAfter(this.select);this.icon.on('click',$.proxy(this.show,this));this.panel=$('').appendTo(document.body);this.panel.html(list);this.panel.on('click',$.proxy(this.click,this));$(document).on('mousedown',$.proxy(this.hide,this));this.panel.on('mousedown',$.proxy(this.mousedown,this));};SimpleColorPicker.prototype={constructor:SimpleColorPicker,show:function(){var panelpadding=7;var pos=this.icon.offset();if(jQuery(document.querySelector("html")).attr('dir')=='rtl'&&this.select.attr('data-position')==='default') +{position='left';}else{position=this.select.attr('data-position');} +switch(position){case'top':this.panel.css({left:pos.left-panelpadding,top:pos.top-this.panel.outerHeight()-1});break;case'bottom':this.panel.css({left:pos.left-panelpadding,top:pos.top+this.icon.outerHeight()});break;case'left':this.panel.css({left:pos.left-this.panel.outerWidth(),top:pos.top-((this.panel.outerHeight()-this.icon.outerHeight())/ 2)-1});break;case'right':default:this.panel.css({left:pos.left+this.icon.outerWidth(),top:pos.top-((this.panel.outerHeight()-this.icon.outerHeight())/ 2)-1});break;} +this.panel.show(this.options.delay);},hide:function(){if(this.panel.css('display')!='none'){this.panel.hide(this.options.delay);}},click:function(e){var target=$(e.target);if(target.length===1){if(target[0].nodeName.toLowerCase()==='span'){var color='';var bgcolor='';var clss='';if(target.parent().hasClass('nocolor')){color='transparent';bgcolor='transparent';clss='nocolor';}else{color=this.rgb2hex(target.css('background-color'));bgcolor=color;} +target.parent().siblings().removeClass('active');target.parent().addClass('active');this.icon.removeClass('nocolor').addClass(clss);this.icon.find('span').css('background-color',bgcolor);this.hide();this.select.val(color).change();}}},mousedown:function(e){e.stopPropagation();e.preventDefault();},rgb2hex:function(rgb){function hex(x){return("0"+parseInt(x,10).toString(16)).slice(-2);} +var matches=rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(matches===null){return rgb;}else{return'#'+hex(matches[1])+hex(matches[2])+hex(matches[3]);}}};$.fn.simplecolors=function(option){return this.each(function(){var $this=$(this),data=$this.data('simplecolors'),options=typeof option==='object'&&option;if(!data){$this.data('simplecolors',(data=new SimpleColorPicker(this,options)));} +if(typeof option==='string'){data[option]();}});};$.fn.simplecolors.Constructor=SimpleColorPicker;$.fn.simplecolors.defaults={delay:0};})(jQuery);