1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
6 <meta http-equiv="content-type"
7 content="text/html; charset=us-ascii" />
9 <title>Color Picker</title>
10 <link rel="stylesheet"
21 <a href="index.html">Index</a> > <a href=
22 "colorPicker.html">ColorPickerHelper</a>
28 "margin-left: 1em; width: 232px; height: 206px; float: right;"
30 src="colorPicker.png" />Composer has a helper for simple
31 and convenient usage of its new color picker inside a
32 sidebar or extension. This helper allows to create
33 persistent color objects that carry information for a given
34 system color, for example the foreground color, the page's
35 background color, table cells' background color and so
38 <p style="clear: both;">The object is</p>
39 <pre><span class="objectName">ColorPickerHelper</span>
41 <span class="methodName">newPersistentColorObject:</span> function(aColorObjectId)
42 <span class="methodName">cleanPersistentColorObject</span>: function(aColorObjectId)
43 <span class="methodName">getCurrentColor</span>: function(aColorObjectId)
44 <span class="methodName">setLastPickedColor</span>: function(aColorObjectId, aColor)
45 <span class="methodName">isCancelled</span>: function(aColorObjectId)
46 <span class="methodName">openColorPicker</span>: function(aColorObjectId, aWindowTitle, aShowTransparency)</pre>
52 <li><a href="#mozTocId73209">Create a new persistent color
55 <li><a href="#mozTocId303492">Delete a persistent color
58 <li><a href="#mozTocId464951">Retrieve the selected color in
59 a color object</a></li>
61 <li><a href="#mozTocId299067">Set the last picked color for a
62 given color object</a></li>
64 <li><a href="#mozTocId400897">Show the color picker</a></li>
66 <li><a href="#mozTocId400897">Check if the color picker was
69 <li><a href="#mozTocId303457">Example</a></li>
72 <h2><a class="mozTocH2"
74 id="mozTocId73209"></a>Create a new persistent color
78 <table style="text-align: left;"
87 <td><code>newPersistentColorObject</code></td>
95 <li><code>aColorObjectId</code>, a unique
96 string identifying the color object</li>
102 <th>Return value</th>
104 <td><code>null</code> in case of error or failure,
105 the color object otherwise</td>
110 <p>List of predefined color object identifiers:</p>
113 <li>"<code>TextColor</code>" : color of the text</li>
115 <li>"<code>PageBackgroundColor</code>" : background color
118 <li>"<code>TableBackgroundColor</code>" : background of a
121 <li>"<code>TableCellBackgroundColor</code>" : background
124 <li>"<code>BorderColor</code>" : color of a border or
125 outline applied to an element</li>
129 <h2><a class="mozTocH2"
130 name="mozTocId303492"
131 id="mozTocId303492"></a>Delete a persistent color object</h2>
133 <div class="section">
134 <table class="methodTable"
135 style="text-align: left;"
143 <td><code>cleanPersistentColorObject</code></td>
151 <li><code>aColorObjectId</code>, a unique
152 string identifying the color object</li>
158 <th>Return value</th>
160 <td><code><span style=
161 "font-family: Arial,Helvetica,sans-serif;">no return
162 value</span></code></td>
168 <h2><a class="mozTocH2"
169 name="mozTocId464951"
170 id="mozTocId464951"></a>Retrieve the selected color in a
173 <div class="section">
174 <table style="text-align: left;"
183 <td><code>getCurrentColor</code></td>
191 <li><code>aColorObjectId</code>, a unique
192 string identifying the color object</li>
198 <th>Return value</th>
200 <td><code>null</code> in case of error or failure
201 (for instance if the corresponding color object does
202 not exist), the selected color in the corresponding
203 color object otherwise</td>
209 <h2><a class="mozTocH2"
210 name="mozTocId299067"
211 id="mozTocId299067"></a>Set the last picked color for a given
214 <div class="section">
215 <table class="methodTable"
216 style="text-align: left;"
224 <td><code>setLastPickedColor</code></td>
232 <li><code>aColorObjectId</code>, a unique
233 string identifying the color object</li>
235 <li><code>aColor</code>, a color (see the
237 "http://www.w3.org/TR/1998/REC-CSS2-19980512/syndata.html#color-units">
238 CSS definition of a color</a>)</li>
244 <th>Return value</th>
246 <td><code>null</code> in case of error or failure,
247 the color <code>aColor</code> otherwise</td>
253 <h2><a class="mozTocH2"
254 name="mozTocId400897"
255 id="mozTocId400897"></a>Show the color picker</h2>
257 <div class="section">
258 <table class="methodTable"
259 style="text-align: left;"
267 <td><code>openColorPicker</code></td>
275 <li><code>aColorObjectId</code>, a unique
276 string identifying the color object ; if the
277 color object for this identifier does not
278 already exist, a new color object is created
279 for that identifier</li>
282 <code>aWindowTitle</code><code><span style="font-family: Arial,Helvetica,sans-serif;">,</span></code>
283 a title for the color picker dialog</li>
285 <li><code>aShowTransparency</code>, a boolean
286 being true if the checkbox allowing to set the
287 color "transparent" has to be shown (for CSS
288 backgrounds for instance)</li>
294 <th>Return value</th>
296 <td><code>null</code> in case of error or failure,
297 the color object otherwise</td>
302 <p>It is possible to check if the color picker was closed by
303 the user on a Cancel action using the following method:</p>
306 <h2><a class="mozTocH2"
307 name="mozTocId400897"
308 id="mozTocId400897"></a>Check if the color picker was
311 <div class="section">
312 <table class="methodTable"
313 style="text-align: left;"
321 <td><code>isCancelled</code></td>
329 <li><code>aColorObjectId</code>, a unique
330 string identifying the color object</li>
336 <th>Return value</th>
338 <td><code><span style=
339 "font-family: Arial,Helvetica,sans-serif;">returns a
340 boolean is the last color picked shown for the color
341 object identifier was cancelled ; if there is no
342 color object for this identifier, an exception
343 NS_ERROR_NULL_POINTER is thrown</span></code></td>
349 <h2><a class="mozTocH2"
350 name="mozTocId303457"
351 id="mozTocId303457"></a>Example</h2>
353 <div class="section">
354 <pre>const kTEMPLATE_COLUMN_BG_COLOR = <code>"TemplateColumnBgColor";</code>
355 var colorHelper = window.top.ColorPickerHelper;
356 if (colorHelper.<code>newPersistentColorObject(</code>kTEMPLATE_COLUMN_BG_COLOR<code>))
358 colorHelper.openColorPicker( </code>kTEMPLATE_COLUMN_BG_COLOR<code>,
359 "Set the background color for the column",
361 if (colorHelper.isCancelled(</code>kTEMPLATE_COLUMN_BG_COLOR))
363 SetTemplateBgColor(colorHelper.getCurrentColor(kTEMPLATE_COLUMN_BG_COLOR));
366 <hr style="width: 100%; height: 2px;" />
370 <div class="section history">
372 <dt>Last Update:</dt>
374 <dd>2007-oct-26, 12:53pm CEST</dd>
376 <dt>2007-oct-26, 12:53pm CEST</dt>
378 <dd>initial revision (dglazman)</dd>