1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
<html>
<head>
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.0.3
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
<div id="cls-Ext.ColorPalette"></div>/**
* @class Ext.ColorPalette
* @extends Ext.Component
* Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
* Here's an example of typical usage:
* <pre><code>
var cp = new Ext.ColorPalette({value:'993300'}); // initial selected color
cp.render('my-div');
cp.on('select', function(palette, selColor){
// do something with selColor
});
</code></pre>
* @constructor
* Create a new ColorPalette
* @param {Object} config The config object
* @xtype colorpalette
*/
Ext.ColorPalette = function(config){
Ext.ColorPalette.superclass.constructor.call(this, config);
this.addEvents(
<div id="event-Ext.ColorPalette-select"></div>/**
* @event select
* Fires when a color is selected
* @param {ColorPalette} this
* @param {String} color The 6-digit color hex code (without the # symbol)
*/
'select'
);
if(this.handler){
this.on('select', this.handler, this.scope, true);
}
};
Ext.extend(Ext.ColorPalette, Ext.Component, {
<div id="cfg-Ext.ColorPalette-tpl"></div>/**
* @cfg {String} tpl An existing XTemplate instance to be used in place of the default template for rendering the component.
*/
<div id="cfg-Ext.ColorPalette-itemCls"></div>/**
* @cfg {String} itemCls
* The CSS class to apply to the containing element (defaults to 'x-color-palette')
*/
itemCls : 'x-color-palette',
<div id="cfg-Ext.ColorPalette-value"></div>/**
* @cfg {String} value
* The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
* the hex codes are case-sensitive.
*/
value : null,
clickEvent :'click',
// private
ctype : 'Ext.ColorPalette',
<div id="cfg-Ext.ColorPalette-allowReselect"></div>/**
* @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the {@link #select} event
*/
allowReselect : false,
<div id="prop-Ext.ColorPalette-colors"></div>/**
* <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
* of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
* the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
* of colors with the width setting until the box is symmetrical.</p>
* <p>You can override individual colors if needed:</p>
* <pre><code>
var cp = new Ext.ColorPalette();
cp.colors[0] = 'FF0000'; // change the first box to red
</code></pre>
Or you can provide a custom array of your own for complete control:
<pre><code>
var cp = new Ext.ColorPalette();
cp.colors = ['000000', '993300', '333300'];
</code></pre>
* @type Array
*/
colors : [
'000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
'800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
],
<div id="cfg-Ext.ColorPalette-handler"></div>/**
* @cfg {Function} handler
* Optional. A function that will handle the select event of this palette.
* The handler is passed the following parameters:<div class="mdetail-params"><ul>
* <li><code>palette</code> : ColorPalette<div class="sub-desc">The {@link #palette Ext.ColorPalette}.</div></li>
* <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>
* </ul></div>
*/
<div id="cfg-Ext.ColorPalette-scope"></div>/**
* @cfg {Object} scope
* The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
* function will be called. Defaults to this ColorPalette instance.
*/
// private
onRender : function(container, position){
var t = this.tpl || new Ext.XTemplate(
'<tpl for="."><a href="#" class="color-{.}" hidefocus="on"><em><span style="background:#{.}" unselectable="on"> </span></em></a></tpl>'
);
var el = document.createElement('div');
el.id = this.getId();
el.className = this.itemCls;
t.overwrite(el, this.colors);
container.dom.insertBefore(el, position);
this.el = Ext.get(el);
this.mon(this.el, this.clickEvent, this.handleClick, this, {delegate: 'a'});
if(this.clickEvent != 'click'){
this.mon(this.el, 'click', Ext.emptyFn, this, {delegate: 'a', preventDefault: true});
}
},
// private
afterRender : function(){
Ext.ColorPalette.superclass.afterRender.call(this);
if(this.value){
var s = this.value;
this.value = null;
this.select(s);
}
},
// private
handleClick : function(e, t){
e.preventDefault();
if(!this.disabled){
var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
this.select(c.toUpperCase());
}
},
<div id="method-Ext.ColorPalette-select"></div>/**
* Selects the specified color in the palette (fires the {@link #select} event)
* @param {String} color A valid 6-digit color hex code (# will be stripped if included)
*/
select : function(color){
color = color.replace('#', '');
if(color != this.value || this.allowReselect){
var el = this.el;
if(this.value){
el.child('a.color-'+this.value).removeClass('x-color-palette-sel');
}
el.child('a.color-'+color).addClass('x-color-palette-sel');
this.value = color;
this.fireEvent('select', this, color);
}
}
<div id="cfg-Ext.ColorPalette-autoEl"></div>/**
* @cfg {String} autoEl @hide
*/
});
Ext.reg('colorpalette', Ext.ColorPalette);
</pre>
</body>
</html>
|