4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-picker-Color-method-constructor'><span id='Ext-picker-Color'>/**
19 </span></span> * @class Ext.picker.Color
20 * @extends Ext.Component
21 * <p>ColorPicker provides a simple color palette for choosing colors. The picker can be rendered to any container.
22 * The available default to a standard 40-color palette; this can be customized with the {@link #colors} config.</p>
23 * <p>Typically you will need to implement a handler function to be notified when the user chooses a color from the
24 * picker; you can register the handler using the {@link #select} event, or by implementing the {@link #handler}
26 * <p>Here's an example of typical usage:</p>
27 * <pre><code>var cp = new Ext.picker.Color({
28 value: '993300', // initial selected color
32 cp.on('select', function(picker, selColor){
33 // do something with selColor
35 </code></pre>
36 * {@img Ext.picker.Color/Ext.picker.Color.png Ext.picker.Color component}
39 * Create a new ColorPicker
40 * @param {Object} config The config object
44 Ext.define('Ext.picker.Color', {
45 extend: 'Ext.Component',
46 requires: 'Ext.XTemplate',
47 alias: 'widget.colorpicker',
48 alternateClassName: 'Ext.ColorPalette',
50 <span id='Ext-picker-Color-cfg-componentCls'> /**
51 </span> * @cfg {String} componentCls
52 * The CSS class to apply to the containing element (defaults to 'x-color-picker')
54 componentCls : Ext.baseCSSPrefix + 'color-picker',
56 <span id='Ext-picker-Color-cfg-selectedCls'> /**
57 </span> * @cfg {String} selectedCls
58 * The CSS class to apply to the selected element
60 selectedCls: Ext.baseCSSPrefix + 'color-picker-selected',
62 <span id='Ext-picker-Color-cfg-value'> /**
63 </span> * @cfg {String} value
64 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
65 * the hex codes are case-sensitive.
69 <span id='Ext-picker-Color-cfg-clickEvent'> /**
70 </span> * @cfg {String} clickEvent
71 * The DOM event that will cause a color to be selected. This can be any valid event name (dblclick, contextmenu).
72 * Defaults to <tt>'click'</tt>.
76 <span id='Ext-picker-Color-cfg-allowReselect'> /**
77 </span> * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the {@link #select} event
79 allowReselect : false,
81 <span id='Ext-picker-Color-property-colors'> /**
82 </span> * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
83 * of colors, and each hex code should be unique. The width of the picker is controlled via CSS by adjusting
84 * the width property of the 'x-color-picker' class (or assigning a custom class), so you can balance the number
85 * of colors with the width setting until the box is symmetrical.</p>
86 * <p>You can override individual colors if needed:</p>
87 * <pre><code>
88 var cp = new Ext.picker.Color();
89 cp.colors[0] = 'FF0000'; // change the first box to red
90 </code></pre>
92 Or you can provide a custom array of your own for complete control:
93 <pre><code>
94 var cp = new Ext.picker.Color();
95 cp.colors = ['000000', '993300', '333300'];
96 </code></pre>
100 '000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
101 '800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
102 'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
103 'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
104 'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
107 <span id='Ext-picker-Color-cfg-handler'> /**
108 </span> * @cfg {Function} handler
109 * Optional. A function that will handle the select event of this picker.
110 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
111 * <li><code>picker</code> : ColorPicker<div class="sub-desc">The {@link #picker Ext.picker.Color}.</div></li>
112 * <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>
113 * </ul></div>
115 <span id='Ext-picker-Color-cfg-scope'> /**
116 </span> * @cfg {Object} scope
117 * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
118 * function will be called. Defaults to this ColorPicker instance.
121 colorRe: /(?:^|\s)color-(.{6})(?:\s|$)/,
123 constructor: function() {
124 this.renderTpl = Ext.create('Ext.XTemplate', '<tpl for="colors"><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" unselectable="on">&#160;</span></em></a></tpl>');
125 this.callParent(arguments);
129 initComponent : function(){
132 this.callParent(arguments);
134 <span id='Ext-picker-Color-event-select'> /**
135 </span> * @event select
136 * Fires when a color is selected
137 * @param {Ext.picker.Color} this
138 * @param {String} color The 6-digit color hex code (without the # symbol)
144 me.on('select', me.handler, me.scope, true);
150 onRender : function(container, position){
152 clickEvent = me.clickEvent;
154 Ext.apply(me.renderData, {
158 this.callParent(arguments);
160 me.mon(me.el, clickEvent, me.handleClick, me, {delegate: 'a'});
161 // always stop following the anchors
162 if(clickEvent != 'click'){
163 me.mon(me.el, 'click', Ext.emptyFn, me, {delegate: 'a', stopEvent: true});
168 afterRender : function(){
172 this.callParent(arguments);
176 me.select(value, true);
181 handleClick : function(event, target){
187 color = target.className.match(me.colorRe)[1];
188 me.select(color.toUpperCase());
192 <span id='Ext-picker-Color-method-select'> /**
193 </span> * Selects the specified color in the picker (fires the {@link #select} event)
194 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
195 * @param {Boolean} suppressEvent (optional) True to stop the select event from firing. Defaults to <tt>false</tt>.
197 select : function(color, suppressEvent){
200 selectedCls = me.selectedCls,
204 color = color.replace('#', '');
211 if (color != value || me.allowReselect) {
215 el.down('a.color-' + value).removeCls(selectedCls);
217 el.down('a.color-' + color).addCls(selectedCls);
219 if (suppressEvent !== true) {
220 me.fireEvent('select', me, color);
225 <span id='Ext-picker-Color-method-getValue'> /**
226 </span> * Get the currently selected color value.
227 * @return {String} value The selected value. Null if nothing is selected.
229 getValue: function(){
230 return this.value || null;