protected override void Render(HtmlTextWriter output) { IHuebeeConfiguration siteConfiguration = GetSiteConfiguration(_configuration.Sites); string options = (siteConfiguration != null) ? CompileConfiguration(siteConfiguration) : CompileConfiguration(_configuration); output.Write("<div class=\"o-colorpicker\">"); base.Render(output); output.Write("</div>"); output.Write("<script>var huebeeColorInput = document.querySelector('.o-colorpicker'); if(huebeeColorInput && huebeeColorInput.firstChild) { var huebeePicker = new SitecoreHuebee.Picker(huebeeColorInput.firstChild, { " + options + ", \"staticOpen\": true }); }</script>"); }
private string CompileConfiguration(IHuebeeConfiguration configuration) { string options = string.Empty; if (!string.IsNullOrWhiteSpace(configuration.Notation)) { options += $"\"notation\": '{configuration.Notation}',"; } if (!string.IsNullOrWhiteSpace(configuration.Hue0)) { options += $"\"hue0\": {configuration.Hue0},"; } if (!string.IsNullOrWhiteSpace(configuration.Hues)) { options += $"\"hues\": {configuration.Hues},"; } if (!string.IsNullOrWhiteSpace(configuration.Saturations)) { options += $"\"saturations\": {configuration.Saturations},"; } if (!string.IsNullOrWhiteSpace(configuration.Shades)) { options += $"\"shades\": {configuration.Shades},"; } string customColors = string.Empty; if (configuration.CustomColors != null && configuration.CustomColors.Any()) { foreach (CustomColor color in configuration.CustomColors) { customColors += $"'{color.Code}',"; } if (customColors.Length > 0) { options += $"\"customColors\": [{customColors.Substring(0,customColors.Count() - 1)}],"; } } if (!string.IsNullOrEmpty(options)) { options = options.Substring(0, options.Count() - 1); } return(options); }
public ColorPickerField(IHuebeeConfiguration configuration) { _configuration = configuration; }