Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / src / widgets / menu / ColorMenu.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.menu.ColorMenu\r
9  * @extends Ext.menu.Menu\r
10  * <p>A menu containing a {@link Ext.ColorPalette} Component.</p>\r
11  * <p>Notes:</p><div class="mdetail-params"><ul>\r
12  * <li>Although not listed here, the <b>constructor</b> for this class\r
13  * accepts all of the configuration options of <b>{@link Ext.ColorPalette}</b>.</li>\r
14  * <li>If subclassing ColorMenu, any configuration options for the ColorPalette must be\r
15  * applied to the <tt><b>initialConfig</b></tt> property of the ColorMenu.\r
16  * Applying {@link Ext.ColorPalette ColorPalette} configuration settings to\r
17  * <b><tt>this</tt></b> will <b>not</b> affect the ColorPalette's configuration.</li>\r
18  * </ul></div> * \r
19  * @xtype colormenu\r
20  */\r
21  Ext.menu.ColorMenu = Ext.extend(Ext.menu.Menu, {\r
22     /** \r
23      * @cfg {Boolean} enableScrolling\r
24      * @hide \r
25      */\r
26     enableScrolling : false,\r
27     /**\r
28      * @cfg {Function} handler\r
29      * Optional. A function that will handle the select event of this menu.\r
30      * The handler is passed the following parameters:<div class="mdetail-params"><ul>\r
31      * <li><code>palette</code> : ColorPalette<div class="sub-desc">The {@link #palette Ext.ColorPalette}.</div></li>\r
32      * <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>\r
33      * </ul></div>\r
34      */\r
35     /**\r
36      * @cfg {Object} scope\r
37      * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>\r
38      * function will be called.  Defaults to this ColorMenu instance.\r
39      */    \r
40     \r
41     /** \r
42      * @cfg {Boolean} hideOnClick\r
43      * False to continue showing the menu after a color is selected, defaults to true.\r
44      */\r
45     hideOnClick : true,\r
46     \r
47     cls : 'x-color-menu',\r
48     \r
49     /** \r
50      * @cfg {String} paletteId\r
51      * An id to assign to the underlying color palette. Defaults to <tt>null</tt>.\r
52      */\r
53     paletteId : null,\r
54     \r
55     /** \r
56      * @cfg {Number} maxHeight\r
57      * @hide \r
58      */\r
59     /** \r
60      * @cfg {Number} scrollIncrement\r
61      * @hide \r
62      */\r
63     /**\r
64      * @property palette\r
65      * @type ColorPalette\r
66      * The {@link Ext.ColorPalette} instance for this ColorMenu\r
67      */\r
68     \r
69     \r
70     /**\r
71      * @event click\r
72      * @hide\r
73      */\r
74     \r
75     /**\r
76      * @event itemclick\r
77      * @hide\r
78      */\r
79     \r
80     initComponent : function(){\r
81         Ext.apply(this, {\r
82             plain: true,\r
83             showSeparator: false,\r
84             items: this.palette = new Ext.ColorPalette(Ext.applyIf({\r
85                 id: this.paletteId\r
86             }, this.initialConfig))\r
87         });\r
88         this.palette.purgeListeners();\r
89         Ext.menu.ColorMenu.superclass.initComponent.call(this);\r
90         /**\r
91          * @event select\r
92          * Fires when a color is selected from the {@link #palette Ext.ColorPalette}\r
93          * @param {Ext.ColorPalette} palette The {@link #palette Ext.ColorPalette}\r
94          * @param {String} color The 6-digit color hex code (without the # symbol)\r
95          */\r
96         this.relayEvents(this.palette, ['select']);\r
97         this.on('select', this.menuHide, this);\r
98         if(this.handler){\r
99             this.on('select', this.handler, this.scope || this);\r
100         }\r
101     },\r
102 \r
103     menuHide : function(){\r
104         if(this.hideOnClick){\r
105             this.hide(true);\r
106         }\r
107     }\r
108 });\r
109 Ext.reg('colormenu', Ext.menu.ColorMenu);\r