]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/ColorPalette.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit.ColorPalette"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dijit.ColorPalette"] = true;
10 dojo
.provide("dijit.ColorPalette");
11 dojo
.require("dijit._Widget");
12 dojo
.require("dijit._Templated");
13 dojo
.require("dojo.colors");
14 dojo
.require("dojo.i18n");
15 dojo
.require("dojo.string");
16 dojo
.require("dijit._PaletteMixin");
17 dojo
.requireLocalization("dojo", "colors", null, "ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
20 dojo
.declare("dijit.ColorPalette",
21 [dijit
._Widget
, dijit
._Templated
, dijit
._PaletteMixin
],
24 // A keyboard accessible color-picking widget
26 // Grid showing various colors, so the user can pick a certain color.
27 // Can be used standalone, or as a popup.
30 // | <div dojoType="dijit.ColorPalette"></div>
33 // | var picker = new dijit.ColorPalette({ },srcNode);
34 // | picker.startup();
37 // palette: [const] String
38 // Size of grid, either "7x10" or "3x4".
41 // _palettes: [protected] Map
42 // This represents the value of the colors.
43 // The first level is a hashmap of the different palettes available.
44 // The next two dimensions represent the columns and rows of colors.
46 "7x10": [["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"]],
54 "3x4": [["white", "lime", "green", "blue"],
55 ["silver", "yellow", "fuchsia", "navy"],
56 ["gray", "red", "purple", "black"]]
59 // templateString: String
60 // The template of this widget.
61 templateString
: dojo
.cache("dijit", "templates/ColorPalette.html", "<div class=\"dijitInline dijitColorPalette\">\n\t<table class=\"dijitPaletteTable\" cellSpacing=\"0\" cellPadding=\"0\">\n\t\t<tbody dojoAttachPoint=\"gridNode\"></tbody>\n\t</table>\n</div>\n"),
63 baseClass
: "dijitColorPalette",
65 buildRendering: function(){
66 // Instantiate the template, which makes a skeleton into which we'll insert a bunch of
68 this.inherited(arguments
);
70 // Creates <img> nodes in each cell of the template.
71 // Pass in "customized" dijit._Color constructor for specified palette and high-contrast vs. normal mode
73 this._palettes
[this.palette
],
74 dojo
.i18n
.getLocalization("dojo", "colors", this.lang
),
75 dojo
.declare(dijit
._Color
, {
76 hc
: dojo
.hasClass(dojo
.body(), "dijit_a11y"),
83 dojo
.declare("dijit._Color", dojo
.Color
, {
85 // Object associated with each cell in a ColorPalette palette.
86 // Implements dijit.Dye.
88 // Template for each cell in normal (non-high-contrast mode). Each cell contains a wrapper
89 // node for showing the border (called dijitPaletteImg for back-compat), and dijitColorPaletteSwatch
90 // for showing the color.
92 "<span class='dijitInline dijitPaletteImg'>" +
93 "<img src='${blankGif}' alt='${alt}' class='dijitColorPaletteSwatch' style='background-color: ${color}'/>" +
96 // Template for each cell in high contrast mode. Each cell contains an image with the whole palette,
97 // but scrolled and clipped to show the correct color only
99 "<span class='dijitInline dijitPaletteImg' style='position: relative; overflow: hidden; height: 12px; width: 14px;'>" +
100 "<img src='${image}' alt='${alt}' style='position: absolute; left: ${left}px; top: ${top}px; ${size}'/>" +
103 // _imagePaths: [protected] Map
104 // This is stores the path to the palette images used for high-contrast mode display
106 "7x10": dojo
.moduleUrl("dijit.themes", "a11y/colors7x10.png"),
107 "3x4": dojo
.moduleUrl("dijit.themes", "a11y/colors3x4.png")
110 constructor: function(/*String*/alias
, /*Number*/ row
, /*Number*/ col
){
114 this.setColor(dojo
.Color
.named
[alias
]);
117 getValue: function(){
119 // Note that although dijit._Color is initialized with a value like "white" getValue() always
120 // returns a hex value
124 fillCell: function(/*DOMNode*/ cell
, /*String*/ blankGif
){
125 var html
= dojo
.string
.substitute(this.hc
? this.hcTemplate
: this.template
, {
126 // substitution variables for normal mode
131 // variables used for high contrast mode
132 image
: this._imagePaths
[this.palette
].toString(),
133 left
: this._col
* -20 - 5,
134 top
: this._row
* -20 - 5,
135 size
: this.palette
== "7x10" ? "height: 145px; width: 206px" : "height: 64px; width: 86px"
138 dojo
.place(html
, cell
);