diff --git a/platform/features/layout/bundle.json b/platform/features/layout/bundle.json index a42bef49b8..3c86ca8421 100644 --- a/platform/features/layout/bundle.json +++ b/platform/features/layout/bundle.json @@ -88,7 +88,7 @@ { "property": "fill", "glyph": "X", - "control": "textfield", + "control": "color", "inclusive": true } ] diff --git a/platform/forms/bundle.json b/platform/forms/bundle.json index eb63e22432..f7a3c33ae4 100644 --- a/platform/forms/bundle.json +++ b/platform/forms/bundle.json @@ -60,6 +60,10 @@ { "key": "CompositeController", "implementation": "controllers/CompositeController.js" + }, + { + "key": "ColorController", + "implementation": "controllers/ColorController.js" } ] } diff --git a/platform/forms/res/templates/controls/color.html b/platform/forms/res/templates/controls/color.html index 4e44c8e84f..f880838a0c 100644 --- a/platform/forms/res/templates/controls/color.html +++ b/platform/forms/res/templates/controls/color.html @@ -1,3 +1,36 @@ - + \ No newline at end of file diff --git a/platform/forms/src/controllers/ColorController.js b/platform/forms/src/controllers/ColorController.js new file mode 100644 index 0000000000..6a8c88225a --- /dev/null +++ b/platform/forms/src/controllers/ColorController.js @@ -0,0 +1,81 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + var BASE_COLORS = [ + [ 136, 32, 32 ], + [ 224, 64, 64 ], + [ 240, 160, 72 ], + [ 255, 248, 96 ], + [ 128, 240, 72 ], + [ 128, 248, 248 ], + [ 88, 144, 224 ], + [ 0, 72, 240 ], + [ 136, 80, 240 ], + [ 224, 96, 248 ] + ], + GRADIENTS = [0.75, 0.50, 0.25, -0.25, -0.50, -0.75], + GROUPS = []; + + function toWebColor(triplet) { + return '#' + triplet.map(function (v) { + return (v < 16 ? '0' : '') + v.toString(16); + }).join(''); + } + + function toGradient(triplet, value) { + return triplet.map(function (v) { + return Math.round(value > 0 ? + (v + (255 - v) * value) : + (v * (1 + value)) + ); + }); + } + + function initializeGroups() { + var i, group; + + // Ten grayscale colors + group = []; + while (group.length < 10) { + group.push(toWebColor([ + Math.round(28.3333 * group.length), + Math.round(28.3333 * group.length), + Math.round(28.3333 * group.length) + ])); + } + GROUPS.push(group); + + // Ten basic colors + GROUPS.push(BASE_COLORS.map(toWebColor)); + + // ...and some gradients of those colors + group = []; + GRADIENTS.forEach(function (v) { + group = group.concat(BASE_COLORS.map(function (c) { + return toWebColor(toGradient(c, v)); + })); + }); + GROUPS.push(group); + } + + + + function ColorController() { + if (GROUPS.length === 0) { + initializeGroups(); + } + + return { + groups: function () { + return GROUPS; + } + }; + } + + return ColorController; + } +); \ No newline at end of file