Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Håkon Nordli
Sep 23, 2015
  7351
(14 votes)

Dojo – a color picker widget

Now and then, a web editor needs to pick a color either in a block or a page. There are several ways to pick colors, for instance you can use the built in dijit widget for picking colors, http://dojotoolkit.org/reference-guide/1.10/dijit/ColorPalette.html, or just add a dropdown.

In my opinion, I think the built-in ColorPalette from Dojo is too difficult and not as extendable. That is why I have created my own color picker. I have refactored the code and shared the property on github.

Here is a screen dump from editmode:

clip_image001

This is a lightweight widget where you as a developer can decide which colors that will be available. In the templateString all the colors are visible through the A-tag.

<div class=\"dijitInline\">\
<ul data-dojo-attach-point=\"colorPickerList\" class=\"colorPickerList\">\
<li><a href=\"#\" data-color=\"#7cb5ec\" style=\"background-color:#7cb5ec;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#434348\" style=\"background-color:#434348;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#90ed7d\" style=\"background-color:#90ed7d;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#f7a35c\" style=\"background-color:#f7a35c;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#8085e9\" style=\"background-color:#8085e9;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#f15c80\" style=\"background-color:#f15c80;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#e4d354\" style=\"background-color:#e4d354;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#8085e8\" style=\"background-color:#8085e8;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#8d4653\" style=\"background-color:#8d4653;\"><span>Color name 1</span></a></li>\
<li><a href=\"#\" data-color=\"#91e8e1\" style=\"background-color:#91e8e1;\"><span>Color name 1</span></a></li>\
</ul>\
</div>

As you can see, the data-color attribute holds the color, and the style attribute is for showing the color. Notice the span-tag which holds the color name. This way it is more accessible.

If you are going to use this in a project, I suggest that you to put the colors in the CSS and SASS/LESS variables, which may be used several places in your project. If you are not using SASS, LESS or other style preprocessors, I recommend you to have a look at it.

To add the color picker to a project just add the descriptor file, css file and the dojo javascript file to the project code. Then you can start using it by adding the UIHint ColorPickerEditor. Also notice that I use string as a property. There is no need for a custom property in this case.

[UIHint("ColorPickerEditor")]
[Display(GroupName = SystemTabNames.Content, Order = 25)]
public virtual string ColorPicker { get; set; }

There is a more detailed description on git on how to add the widget. Please have a look!

The widget is tested for EPiServer 8 and 9.

The property is available on Github and is open for everyone to use. Please give me feedback if you find any bugs.

Sep 23, 2015

Comments

Sep 24, 2015 07:44 AM

Thanks Håkon!

This is much desired. Dojo palette lacks documentation and gives you a headache.

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog