MCPcopy
hub / github.com/GrapesJS/grapesjs / updateUI

Function updateUI

packages/core/src/utils/ColorPicker.ts:793–862  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

791 }
792
793 function updateUI() {
794 textInput.removeClass('sp-validation-error');
795
796 updateHelperLocations();
797
798 // Update dragger background color (gradients take care of saturation and value).
799 var flatColor = tinycolor.fromRatio({ h: currentHue, s: 1, v: 1 });
800 dragger.css('background-color', flatColor.toHexString());
801
802 // Get a format that alpha will be included in (hex and names ignore alpha)
803 var format = currentPreferredFormat;
804 if (currentAlpha < 1 && !(currentAlpha === 0 && format === 'name')) {
805 if (format === 'hex' || format === 'hex3' || format === 'hex6' || format === 'name') {
806 format = 'rgb';
807 }
808 }
809
810 var realColor = get({ format: format }),
811 displayColor = '';
812
813 //reset background info for preview element
814 previewElement.removeClass('sp-clear-display');
815 previewElement.css('background-color', 'transparent');
816
817 if (!realColor && allowEmpty) {
818 // Update the replaced elements background with icon indicating no color selection
819 previewElement.addClass('sp-clear-display');
820 } else {
821 var realHex = realColor.toHexString(),
822 realRgb = realColor.toRgbString();
823
824 // Update the replaced elements background color (with actual selected color)
825 if (rgbaSupport || realColor.alpha === 1) {
826 previewElement.css('background-color', realRgb);
827 } else {
828 previewElement.css('background-color', 'transparent');
829 previewElement.css('filter', realColor.toFilter());
830 }
831
832 if (opts.showAlpha) {
833 var rgb = realColor.toRgb();
834 rgb.a = 0;
835 var realAlpha = tinycolor(rgb).toRgbString();
836 var gradient = 'linear-gradient(left, ' + realAlpha + ', ' + realHex + ')';
837
838 if (IE) {
839 alphaSliderInner.css('filter', tinycolor(realAlpha).toFilter({ gradientType: 1 }, realHex));
840 } else {
841 alphaSliderInner.css('background', '-webkit-' + gradient);
842 alphaSliderInner.css('background', '-moz-' + gradient);
843 alphaSliderInner.css('background', '-ms-' + gradient);
844 // Use current syntax gradient on unprefixed property.
845 alphaSliderInner.css('background', 'linear-gradient(to right, ' + realAlpha + ', ' + realHex + ')');
846 }
847 }
848
849 displayColor = realColor.toString(format);
850 }

Callers 4

initializeFunction · 0.85
showFunction · 0.85
setFunction · 0.85
moveFunction · 0.85

Calls 8

updateHelperLocationsFunction · 0.85
tinycolorFunction · 0.85
drawPaletteFunction · 0.85
drawInitialFunction · 0.85
removeClassMethod · 0.80
toStringMethod · 0.80
getFunction · 0.70
addClassMethod · 0.45

Tested by

no test coverage detected