Debian Codegraph @

dijit/ColorPalette.js

raw symbols SCIP
1 define([
2 "require", // require.toUrl
3 "dojo/text!./templates/ColorPalette.html",
4 "./_Widget", // used also to load dijit/hccss for setting has("highcontrast")
5 "./_TemplatedMixin",
6 "./_PaletteMixin",
7 "./hccss", // has("highcontrast")
8 "dojo/i18n", // i18n.getLocalization
9 "dojo/_base/Color", // dojo.Color dojo.Color.named
10 "dojo/_base/declare", // declare
11 "dojo/dom-construct", // domConstruct.place
12 "dojo/string", // string.substitute
13 "dojo/i18n!dojo/nls/colors", // translations
14 "dojo/colors" // extend dojo.Color w/names of other colors
15 ], function(require, template, _Widget, _TemplatedMixin, _PaletteMixin, has, i18n, Color,
16 declare, domConstruct, string){
17
18 // module:
19 // dijit/ColorPalette
20
21 var ColorPalette = declare("dijit.ColorPalette", [_Widget, _TemplatedMixin, _PaletteMixin], {
22 // summary:
23 // A keyboard accessible color-picking widget
24 // description:
25 // Grid showing various colors, so the user can pick a certain color.
26 // Can be used standalone, or as a popup.
27 //
28 // example:
29 // | <div data-dojo-type="dijit/ColorPalette"></div>
30 //
31 // example:
32 // | var picker = new dijit.ColorPalette({ },srcNode);
33 // | picker.startup();
34
35
36 // palette: [const] String
37 // Size of grid, either "7x10" or "3x4".
38 palette: "7x10",
39
40 // _palettes: [protected] Map
41 // This represents the value of the colors.
42 // The first level is a hashmap of the different palettes available.
43 // The next two dimensions represent the columns and rows of colors.
44 _palettes: {
45 "7x10": [
46 ["white", "seashell", "cornsilk", "lemonchiffon", "lightyellow", "palegreen", "paleturquoise", "lightcyan", "lavender", "plum"],
47 ["lightgray", "pink", "bisque", "moccasin", "khaki", "lightgreen", "lightseagreen", "lightskyblue", "cornflowerblue", "violet"],
48 ["silver", "lightcoral", "sandybrown", "orange", "palegoldenrod", "chartreuse", "mediumturquoise", "skyblue", "mediumslateblue", "orchid"],
49 ["gray", "red", "orangered", "darkorange", "yellow", "limegreen", "darkseagreen", "royalblue", "slateblue", "mediumorchid"],
50 ["dimgray", "crimson", "chocolate", "coral", "gold", "forestgreen", "seagreen", "blue", "blueviolet", "darkorchid"],
51 ["darkslategray", "firebrick", "saddlebrown", "sienna", "olive", "green", "darkcyan", "mediumblue", "darkslateblue", "darkmagenta" ],
52 ["black", "darkred", "maroon", "brown", "darkolivegreen", "darkgreen", "midnightblue", "navy", "indigo", "purple"]
53 ],
54
55 "3x4": [
56 ["white", "lime", "green", "blue"],
57 ["silver", "yellow", "fuchsia", "navy"],
58 ["gray", "red", "purple", "black"]
59 ]
60 },
61
62 // templateString: String
63 // The template of this widget.
64 templateString: template,
65
66 baseClass: "dijitColorPalette",
67
68 _dyeFactory: function(value, row, col, title){
69 // Overrides _PaletteMixin._dyeFactory().
70 return new this._dyeClass(value, row, col, title);
71 },
72
73 buildRendering: function(){
74 // Instantiate the template, which makes a skeleton into which we'll insert a bunch of
75 // <img> nodes
76 this.inherited(arguments);
77
78 // Creates customized constructor for dye class (color of a single cell) for
79 // specified palette and high-contrast vs. normal mode. Used in _getDye().
80 this._dyeClass = declare(ColorPalette._Color, {
81 palette: this.palette
82 });
83
84 // Creates <img> nodes in each cell of the template.
85 this._preparePalette(
86 this._palettes[this.palette],
87 i18n.getLocalization("dojo", "colors", this.lang));
88 }
89 });
90
91 ColorPalette._Color = declare("dijit._Color", Color, {
92 // summary:
93 // Object associated with each cell in a ColorPalette palette.
94 // Implements dijit/Dye.
95
96 // Template for each cell in normal (non-high-contrast mode). Each cell contains a wrapper
97 // node for showing the border (called dijitPaletteImg for back-compat), and dijitColorPaletteSwatch
98 // for showing the color.
99 template: "<span class='dijitInline dijitPaletteImg'>" +
100 "<img src='${blankGif}' alt='${alt}' title='${title}' class='dijitColorPaletteSwatch' style='background-color: ${color}'/>" +
101 "</span>",
102
103 // Template for each cell in high contrast mode. Each cell contains an image with the whole palette,
104 // but scrolled and clipped to show the correct color only
105 hcTemplate: "<span class='dijitInline dijitPaletteImg' style='position: relative; overflow: hidden; height: 12px; width: 14px;'>" +
106 "<img src='${image}' alt='${alt}' title='${title}' style='position: absolute; left: ${left}px; top: ${top}px; ${size}'/>" +
107 "</span>",
108
109 // _imagePaths: [protected] Map
110 // This is stores the path to the palette images used for high-contrast mode display
111 _imagePaths: {
112 "7x10": require.toUrl("./themes/a11y/colors7x10.png"),
113 "3x4": require.toUrl("./themes/a11y/colors3x4.png")
114 },
115
116 constructor: function(alias, row, col, title){
117 // summary:
118 // Constructor for ColorPalette._Color
119 // alias: String
120 // English name of the color.
121 // row: Number
122 // Vertical position in grid.
123 // column: Number
124 // Horizontal position in grid.
125 // title: String
126 // Localized name of the color.
127 this._title = title;
128 this._row = row;
129 this._col = col;
130 this.setColor(Color.named[alias]);
131 },
132
133 getValue: function(){
134 // summary:
135 // Note that although dijit._Color is initialized with a value like "white" getValue() always
136 // returns a hex value
137 return this.toHex();
138 },
139
140 fillCell: function(/*DOMNode*/ cell, /*String*/ blankGif){
141 var html = string.substitute(has("highcontrast") ? this.hcTemplate : this.template, {
142 // substitution variables for normal mode
143 color: this.toHex(),
144 blankGif: blankGif,
145 alt: this._title,
146 title: this._title,
147
148 // variables used for high contrast mode
149 image: this._imagePaths[this.palette].toString(),
150 left: this._col * -20 - 5,
151 top: this._row * -20 - 5,
152 size: this.palette == "7x10" ? "height: 145px; width: 206px" : "height: 64px; width: 86px"
153 });
154
155 domConstruct.place(html, cell);
156 }
157 });
158
159 return ColorPalette;
160 });