X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..c8256059947f3aa8f5b0a9a2acf55e2142bb4742:/pkgs/pkg-menu-debug.js?ds=sidebyside diff --git a/pkgs/pkg-menu-debug.js b/pkgs/pkg-menu-debug.js index dec91c75..71028f54 100644 --- a/pkgs/pkg-menu-debug.js +++ b/pkgs/pkg-menu-debug.js @@ -1,736 +1,722 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.2.1 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ -/** - * @class Ext.layout.MenuLayout - * @extends Ext.layout.ContainerLayout - *
Layout manager used by {@link Ext.menu.Menu}. Generally this class should not need to be used directly.
- */ - Ext.layout.MenuLayout = Ext.extend(Ext.layout.ContainerLayout, { - monitorResize: true, - - setContainer : function(ct){ - this.monitorResize = !ct.floating; - Ext.layout.MenuLayout.superclass.setContainer.call(this, ct); - }, - - renderItem : function(c, position, target){ - if (!this.itemTpl) { - this.itemTpl = Ext.layout.MenuLayout.prototype.itemTpl = new Ext.XTemplate( - 'A menu object. This is the container to which you may add menu items. Menu can also serve as a base class - * when you want a specialized menu based off of another component (like {@link Ext.menu.DateMenu} for example).
- *Menus may contain either {@link Ext.menu.Item menu items}, or general {@link Ext.Component Component}s.
- *To make a contained general {@link Ext.Component Component} line up with other {@link Ext.menu.Item menu items} - * specify iconCls: 'no-icon'. This reserves a space for an icon, and indents the Component in line - * with the other menu items. See {@link Ext.form.ComboBox}.{@link Ext.form.ComboBox#getListParent getListParent} - * for an example.
- *By default, Menus are absolutely positioned, floating Components. By configuring a Menu with - * {@link #floating}:false, a Menu may be used as child of a Container.
- * - * @xtype menu - */ -Ext.menu.Menu = Ext.extend(Ext.Container, { - /** - * @cfg {Object} defaults - * A config object that will be applied to all items added to this container either via the {@link #items} - * config or via the {@link #add} method. The defaults config can contain any number of - * name/value property pairs to be added to each item, and should be valid for the types of items - * being added to the menu. - */ - /** - * @cfg {Mixed} items - * An array of items to be added to this menu. Menus may contain either {@link Ext.menu.Item menu items}, - * or general {@link Ext.Component Component}s. - */ - /** - * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120) - */ - minWidth : 120, - /** - * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" - * for bottom-right shadow (defaults to "sides") - */ - shadow : "sides", - /** - * @cfg {String} subMenuAlign The {@link Ext.Element#alignTo} anchor position value to use for submenus of - * this menu (defaults to "tl-tr?") - */ - subMenuAlign : "tl-tr?", - /** - * @cfg {String} defaultAlign The default {@link Ext.Element#alignTo} anchor position value for this menu - * relative to its element of origin (defaults to "tl-bl?") - */ - defaultAlign : "tl-bl?", - /** - * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false) - */ - allowOtherMenus : false, - /** - * @cfg {Boolean} ignoreParentClicks True to ignore clicks on any item in this menu that is a parent item (displays - * a submenu) so that the submenu is not dismissed when clicking the parent item (defaults to false). - */ - ignoreParentClicks : false, - /** - * @cfg {Boolean} enableScrolling True to allow the menu container to have scroller controls if the menu is too long (defaults to true). - */ - enableScrolling: true, - /** - * @cfg {Number} maxHeight The maximum height of the menu. Only applies when enableScrolling is set to True (defaults to null). - */ - maxHeight: null, - /** - * @cfg {Number} scrollIncrement The amount to scroll the menu. Only applies when enableScrolling is set to True (defaults to 24). - */ - scrollIncrement: 24, - /** - * @cfg {Boolean} showSeparator True to show the icon separator. (defaults to true). - */ - showSeparator: true, - /** - * @cfg {Array} defaultOffsets An array specifying the [x, y] offset in pixels by which to - * change the default Menu popup position after aligning according to the {@link #defaultAlign} - * configuration. Defaults to [0, 0]. - */ - defaultOffsets : [0, 0], - - - /** - * @cfg {Boolean} floating - * May be specified as false to create a Menu which may be used as a child item of another Container - * instead of a free-floating {@link Ext.Layer Layer}. (defaults to true). - */ - floating: true, // Render as a Layer by default - - // private - hidden: true, - layout: 'menu', - hideMode: 'offsets', // Important for laying out Components - scrollerHeight: 8, - autoLayout: true, // Provided for backwards compat - defaultType: 'menuitem', - - initComponent: function(){ - if(Ext.isArray(this.initialConfig)){ - Ext.apply(this, {items:this.initialConfig}); - } - this.addEvents( - /** - * @event click - * Fires when this menu is clicked (or when the enter key is pressed while it is active) - * @param {Ext.menu.Menu} this - * @param {Ext.menu.Item} menuItem The menu item that was clicked - * @param {Ext.EventObject} e - */ - 'click', - /** - * @event mouseover - * Fires when the mouse is hovering over this menu - * @param {Ext.menu.Menu} this - * @param {Ext.EventObject} e - * @param {Ext.menu.Item} menuItem The menu item that was clicked - */ - 'mouseover', - /** - * @event mouseout - * Fires when the mouse exits this menu - * @param {Ext.menu.Menu} this - * @param {Ext.EventObject} e - * @param {Ext.menu.Item} menuItem The menu item that was clicked - */ - 'mouseout', - /** - * @event itemclick - * Fires when a menu item contained in this menu is clicked - * @param {Ext.menu.BaseItem} baseItem The BaseItem that was clicked - * @param {Ext.EventObject} e - */ - 'itemclick' - ); - Ext.menu.MenuMgr.register(this); - if(this.floating){ - Ext.EventManager.onWindowResize(this.hide, this); - }else{ - if(this.initialConfig.hidden !== false){ - this.hidden = false; - } - this.internalDefaults = {hideOnClick: false}; - } - Ext.menu.Menu.superclass.initComponent.call(this); - if(this.autoLayout){ - this.on({ - add: this.doLayout, - remove: this.doLayout, - scope: this - }); - } - }, - - //private - getLayoutTarget : function() { - return this.ul; - }, - - // private - onRender : function(ct, position){ - if(!ct){ - ct = Ext.getBody(); - } - - var dh = { - id: this.getId(), - cls: 'x-menu ' + ((this.floating) ? 'x-menu-floating x-layer ' : '') + (this.cls || '') + (this.plain ? ' x-menu-plain' : '') + (this.showSeparator ? '' : ' x-menu-nosep'), - style: this.style, - cn: [ - {tag: 'a', cls: 'x-menu-focus', href: '#', onclick: 'return false;', tabIndex: '-1'}, - {tag: 'ul', cls: 'x-menu-list'} - ] - }; - if(this.floating){ - this.el = new Ext.Layer({ - shadow: this.shadow, - dh: dh, - constrain: false, - parentEl: ct, - zindex:15000 - }); - }else{ - this.el = ct.createChild(dh); - } - Ext.menu.Menu.superclass.onRender.call(this, ct, position); - - if(!this.keyNav){ - this.keyNav = new Ext.menu.MenuNav(this); - } - // generic focus element - this.focusEl = this.el.child('a.x-menu-focus'); - this.ul = this.el.child('ul.x-menu-list'); - this.mon(this.ul, { - scope: this, - click: this.onClick, - mouseover: this.onMouseOver, - mouseout: this.onMouseOut - }); - if(this.enableScrolling){ - this.mon(this.el, { - scope: this, - delegate: '.x-menu-scroller', - click: this.onScroll, - mouseover: this.deactivateActive - }); - } - }, - - // private - findTargetItem : function(e){ - var t = e.getTarget(".x-menu-list-item", this.ul, true); - if(t && t.menuItemId){ - return this.items.get(t.menuItemId); - } - }, - - // private - onClick : function(e){ - var t = this.findTargetItem(e); - if(t){ - if(t.isFormField){ - this.setActiveItem(t); - }else{ - if(t.menu && this.ignoreParentClicks){ - t.expandMenu(); - e.preventDefault(); - }else if(t.onClick){ - t.onClick(e); - this.fireEvent("click", this, t, e); - } - } - } - }, - - // private - setActiveItem : function(item, autoExpand){ - if(item != this.activeItem){ - this.deactivateActive(); - if((this.activeItem = item).isFormField){ - item.focus(); - }else{ - item.activate(autoExpand); - } - }else if(autoExpand){ - item.expandMenu(); - } - }, - - deactivateActive: function(){ - var a = this.activeItem; - if(a){ - if(a.isFormField){ - //Fields cannot deactivate, but Combos must collapse - if(a.collapse){ - a.collapse(); - } - }else{ - a.deactivate(); - } - delete this.activeItem; - } - }, - - // private - tryActivate : function(start, step){ - var items = this.items; - for(var i = start, len = items.length; i >= 0 && i < len; i+= step){ - var item = items.get(i); - if(!item.disabled && (item.canActivate || item.isFormField)){ - this.setActiveItem(item, false); - return item; - } - } - return false; - }, - - // private - onMouseOver : function(e){ - var t = this.findTargetItem(e); - if(t){ - if(t.canActivate && !t.disabled){ - this.setActiveItem(t, true); - } - } - this.over = true; - this.fireEvent("mouseover", this, e, t); - }, - - // private - onMouseOut : function(e){ - var t = this.findTargetItem(e); - if(t){ - if(t == this.activeItem && t.shouldDeactivate && t.shouldDeactivate(e)){ - this.activeItem.deactivate(); - delete this.activeItem; - } - } - this.over = false; - this.fireEvent("mouseout", this, e, t); - }, - - // private - onScroll: function(e, t){ - if(e){ - e.stopEvent(); - } - var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top'); - ul.scrollTop += this.scrollIncrement * (top ? -1 : 1); - if(top ? ul.scrollTop <= 0 : ul.scrollTop + this.activeMax >= ul.scrollHeight){ - this.onScrollerOut(null, t); - } - }, - - // private - onScrollerIn: function(e, t){ - var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top'); - if(top ? ul.scrollTop > 0 : ul.scrollTop + this.activeMax < ul.scrollHeight){ - Ext.fly(t).addClass(['x-menu-item-active', 'x-menu-scroller-active']); - } - }, - - // private - onScrollerOut: function(e, t){ - Ext.fly(t).removeClass(['x-menu-item-active', 'x-menu-scroller-active']); - }, - - /** - * Displays this menu relative to another element - * @param {Mixed} element The element to align to - * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to - * the element (defaults to this.defaultAlign) - * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined) - */ - show : function(el, pos, parentMenu){ - if(this.floating){ - this.parentMenu = parentMenu; - if(!this.el){ - this.render(); - this.doLayout(false, true); - } - if(this.fireEvent('beforeshow', this) !== false){ - this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign, this.defaultOffsets), parentMenu, false); - } - }else{ - Ext.menu.Menu.superclass.show.call(this); - } - }, - - /** - * Displays this menu at a specific xy position - * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based) - * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined) - */ - showAt : function(xy, parentMenu, /* private: */_e){ - this.parentMenu = parentMenu; - if(!this.el){ - this.render(); - } - this.el.setXY(xy); - if(this.enableScrolling){ - this.constrainScroll(xy[1]); - } - this.el.show(); - Ext.menu.Menu.superclass.onShow.call(this); - if(Ext.isIE){ - this.layout.doAutoSize(); - if(!Ext.isIE8){ - this.el.repaint(); - } - } - this.hidden = false; - this.focus(); - this.fireEvent("show", this); - }, - - constrainScroll: function(y){ - var max, full = this.ul.setHeight('auto').getHeight(); - if(this.floating){ - max = this.maxHeight ? this.maxHeight : Ext.fly(this.el.dom.parentNode).getViewSize().height - y; - }else{ - max = this.getHeight(); - } - if(full > max && max > 0){ - this.activeMax = max - this.scrollerHeight * 2 - this.el.getFrameWidth('tb') - Ext.num(this.el.shadowOffset, 0); - this.ul.setHeight(this.activeMax); - this.createScrollers(); - this.el.select('.x-menu-scroller').setDisplayed(''); - }else{ - this.ul.setHeight(full); - this.el.select('.x-menu-scroller').setDisplayed('none'); - } - this.ul.dom.scrollTop = 0; - }, - - createScrollers: function(){ - if(!this.scroller){ - this.scroller = { - pos: 0, - top: this.el.insertFirst({ - tag: 'div', - cls: 'x-menu-scroller x-menu-scroller-top', - html: ' ' - }), - bottom: this.el.createChild({ - tag: 'div', - cls: 'x-menu-scroller x-menu-scroller-bottom', - html: ' ' - }) - }; - this.scroller.top.hover(this.onScrollerIn, this.onScrollerOut, this); - this.scroller.topRepeater = new Ext.util.ClickRepeater(this.scroller.top, { - listeners: { - click: this.onScroll.createDelegate(this, [null, this.scroller.top], false) - } - }); - this.scroller.bottom.hover(this.onScrollerIn, this.onScrollerOut, this); - this.scroller.bottomRepeater = new Ext.util.ClickRepeater(this.scroller.bottom, { - listeners: { - click: this.onScroll.createDelegate(this, [null, this.scroller.bottom], false) - } - }); - } - }, - - onLayout: function(){ - if(this.isVisible()){ - if(this.enableScrolling){ - this.constrainScroll(this.el.getTop()); - } - if(this.floating){ - this.el.sync(); - } - } - }, - - focus : function(){ - if(!this.hidden){ - this.doFocus.defer(50, this); - } - }, - - doFocus : function(){ - if(!this.hidden){ - this.focusEl.focus(); - } - }, - - /** - * Hides this menu and optionally all parent menus - * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false) - */ - hide : function(deep){ - this.deepHide = deep; - Ext.menu.Menu.superclass.hide.call(this); - delete this.deepHide; - }, - - // private - onHide: function(){ - Ext.menu.Menu.superclass.onHide.call(this); - this.deactivateActive(); - if(this.el && this.floating){ - this.el.hide(); - } - if(this.deepHide === true && this.parentMenu){ - this.parentMenu.hide(true); - } - }, - - // private - lookupComponent: function(c){ - if(Ext.isString(c)){ - c = (c == 'separator' || c == '-') ? new Ext.menu.Separator() : new Ext.menu.TextItem(c); - this.applyDefaults(c); - }else{ - if(Ext.isObject(c)){ - c = this.getMenuItem(c); - }else if(c.tagName || c.el){ // element. Wrap it. - c = new Ext.BoxComponent({ - el: c - }); - } - } - return c; - }, - - applyDefaults : function(c){ - if(!Ext.isString(c)){ - c = Ext.menu.Menu.superclass.applyDefaults.call(this, c); - var d = this.internalDefaults; - if(d){ - if(c.events){ - Ext.applyIf(c.initialConfig, d); - Ext.apply(c, d); - }else{ - Ext.applyIf(c, d); - } - } - } - return c; - }, - - // private - getMenuItem: function(config){ - if(!config.isXType){ - if(!config.xtype && Ext.isBoolean(config.checked)){ - return new Ext.menu.CheckItem(config) - } - return Ext.create(config, this.defaultType); - } - return config; - }, - - /** - * Adds a separator bar to the menu - * @return {Ext.menu.Item} The menu item that was added - */ - addSeparator : function(){ - return this.add(new Ext.menu.Separator()); - }, - - /** - * Adds an {@link Ext.Element} object to the menu - * @param {Mixed} el The element or DOM node to add, or its id - * @return {Ext.menu.Item} The menu item that was added - */ - addElement : function(el){ - return this.add(new Ext.menu.BaseItem(el)); - }, - - /** - * Adds an existing object based on {@link Ext.menu.BaseItem} to the menu - * @param {Ext.menu.Item} item The menu item to add - * @return {Ext.menu.Item} The menu item that was added - */ - addItem : function(item){ - return this.add(item); - }, - - /** - * Creates a new {@link Ext.menu.Item} based an the supplied config object and adds it to the menu - * @param {Object} config A MenuItem config object - * @return {Ext.menu.Item} The menu item that was added - */ - addMenuItem : function(config){ - return this.add(this.getMenuItem(config)); - }, - - /** - * Creates a new {@link Ext.menu.TextItem} with the supplied text and adds it to the menu - * @param {String} text The text to display in the menu item - * @return {Ext.menu.Item} The menu item that was added - */ - addText : function(text){ - return this.add(new Ext.menu.TextItem(text)); - }, - - //private - onDestroy : function(){ - Ext.menu.Menu.superclass.onDestroy.call(this); - Ext.menu.MenuMgr.unregister(this); - Ext.EventManager.removeResizeListener(this.hide, this); - if(this.keyNav) { - this.keyNav.disable(); - } - var s = this.scroller; - if(s){ - Ext.destroy(s.topRepeater, s.bottomRepeater, s.top, s.bottom); - } - } -}); - -Ext.reg('menu', Ext.menu.Menu); - -// MenuNav is a private utility class used internally by the Menu -Ext.menu.MenuNav = Ext.extend(Ext.KeyNav, function(){ - function up(e, m){ - if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){ - m.tryActivate(m.items.length-1, -1); - } - } - function down(e, m){ - if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){ - m.tryActivate(0, 1); - } - } - return { - constructor: function(menu){ - Ext.menu.MenuNav.superclass.constructor.call(this, menu.el); - this.scope = this.menu = menu; - }, - - doRelay : function(e, h){ - var k = e.getKey(); -// Keystrokes within a form Field (e.g.: down in a Combo) do not navigate. Allow only TAB - if (this.menu.activeItem && this.menu.activeItem.isFormField && k != e.TAB) { - return false; - } - if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){ - this.menu.tryActivate(0, 1); - return false; - } - return h.call(this.scope || this, e, this.menu); - }, - - tab: function(e, m) { - e.stopEvent(); - if (e.shiftKey) { - up(e, m); - } else { - down(e, m); - } - }, - - up : up, - - down : down, - - right : function(e, m){ - if(m.activeItem){ - m.activeItem.expandMenu(true); - } - }, - - left : function(e, m){ - m.hide(); - if(m.parentMenu && m.parentMenu.activeItem){ - m.parentMenu.activeItem.activate(); - } - }, - - enter : function(e, m){ - if(m.activeItem){ - e.stopPropagation(); - m.activeItem.onClick(e); - m.fireEvent("click", this, m.activeItem); - return true; - } - } - }; -}());/** +/** + * @class Ext.menu.Menu + * @extends Ext.Container + *A menu object. This is the container to which you may add menu items. Menu can also serve as a base class + * when you want a specialized menu based off of another component (like {@link Ext.menu.DateMenu} for example).
+ *Menus may contain either {@link Ext.menu.Item menu items}, or general {@link Ext.Component Component}s.
+ *To make a contained general {@link Ext.Component Component} line up with other {@link Ext.menu.Item menu items} + * specify iconCls: 'no-icon'. This reserves a space for an icon, and indents the Component in line + * with the other menu items. See {@link Ext.form.ComboBox}.{@link Ext.form.ComboBox#getListParent getListParent} + * for an example.
+ *By default, Menus are absolutely positioned, floating Components. By configuring a Menu with + * {@link #floating}:false, a Menu may be used as child of a Container.
+ * + * @xtype menu + */ +Ext.menu.Menu = Ext.extend(Ext.Container, { + /** + * @cfg {Object} defaults + * A config object that will be applied to all items added to this container either via the {@link #items} + * config or via the {@link #add} method. The defaults config can contain any number of + * name/value property pairs to be added to each item, and should be valid for the types of items + * being added to the menu. + */ + /** + * @cfg {Mixed} items + * An array of items to be added to this menu. Menus may contain either {@link Ext.menu.Item menu items}, + * or general {@link Ext.Component Component}s. + */ + /** + * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120) + */ + minWidth : 120, + /** + * @cfg {Boolean/String} shadow True or 'sides' for the default effect, 'frame' for 4-way shadow, and 'drop' + * for bottom-right shadow (defaults to 'sides') + */ + shadow : 'sides', + /** + * @cfg {String} subMenuAlign The {@link Ext.Element#alignTo} anchor position value to use for submenus of + * this menu (defaults to 'tl-tr?') + */ + subMenuAlign : 'tl-tr?', + /** + * @cfg {String} defaultAlign The default {@link Ext.Element#alignTo} anchor position value for this menu + * relative to its element of origin (defaults to 'tl-bl?') + */ + defaultAlign : 'tl-bl?', + /** + * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false) + */ + allowOtherMenus : false, + /** + * @cfg {Boolean} ignoreParentClicks True to ignore clicks on any item in this menu that is a parent item (displays + * a submenu) so that the submenu is not dismissed when clicking the parent item (defaults to false). + */ + ignoreParentClicks : false, + /** + * @cfg {Boolean} enableScrolling True to allow the menu container to have scroller controls if the menu is too long (defaults to true). + */ + enableScrolling : true, + /** + * @cfg {Number} maxHeight The maximum height of the menu. Only applies when enableScrolling is set to True (defaults to null). + */ + maxHeight : null, + /** + * @cfg {Number} scrollIncrement The amount to scroll the menu. Only applies when enableScrolling is set to True (defaults to 24). + */ + scrollIncrement : 24, + /** + * @cfg {Boolean} showSeparator True to show the icon separator. (defaults to true). + */ + showSeparator : true, + /** + * @cfg {Array} defaultOffsets An array specifying the [x, y] offset in pixels by which to + * change the default Menu popup position after aligning according to the {@link #defaultAlign} + * configuration. Defaults to [0, 0]. + */ + defaultOffsets : [0, 0], + + /** + * @cfg {Boolean} plain + * True to remove the incised line down the left side of the menu. Defaults to false. + */ + plain : false, + + /** + * @cfg {Boolean} floating + *By default, a Menu configured as floating:true
+ * will be rendered as an {@link Ext.Layer} (an absolutely positioned,
+ * floating Component with zindex=15000).
+ * If configured as floating:false
, the Menu may be
+ * used as child item of another Container instead of a free-floating
+ * {@link Ext.Layer Layer}.
+ */
+ floating : true,
+
+
+ /**
+ * @cfg {Number} zIndex
+ * zIndex to use when the menu is floating.
+ */
+ zIndex: 15000,
+
+ // private
+ hidden : true,
+
+ /**
+ * @cfg {String/Object} layout
+ * This class assigns a default layout (layout:'menu'
).
+ * Developers may override this configuration option if another layout is required.
+ * See {@link Ext.Container#layout} for additional information.
+ */
+ layout : 'menu',
+ hideMode : 'offsets', // Important for laying out Components
+ scrollerHeight : 8,
+ autoLayout : true, // Provided for backwards compat
+ defaultType : 'menuitem',
+ bufferResize : false,
+
+ initComponent : function(){
+ if(Ext.isArray(this.initialConfig)){
+ Ext.apply(this, {items:this.initialConfig});
+ }
+ this.addEvents(
+ /**
+ * @event click
+ * Fires when this menu is clicked (or when the enter key is pressed while it is active)
+ * @param {Ext.menu.Menu} this
+ * @param {Ext.menu.Item} menuItem The menu item that was clicked
+ * @param {Ext.EventObject} e
+ */
+ 'click',
+ /**
+ * @event mouseover
+ * Fires when the mouse is hovering over this menu
+ * @param {Ext.menu.Menu} this
+ * @param {Ext.EventObject} e
+ * @param {Ext.menu.Item} menuItem The menu item that was clicked
+ */
+ 'mouseover',
+ /**
+ * @event mouseout
+ * Fires when the mouse exits this menu
+ * @param {Ext.menu.Menu} this
+ * @param {Ext.EventObject} e
+ * @param {Ext.menu.Item} menuItem The menu item that was clicked
+ */
+ 'mouseout',
+ /**
+ * @event itemclick
+ * Fires when a menu item contained in this menu is clicked
+ * @param {Ext.menu.BaseItem} baseItem The BaseItem that was clicked
+ * @param {Ext.EventObject} e
+ */
+ 'itemclick'
+ );
+ Ext.menu.MenuMgr.register(this);
+ if(this.floating){
+ Ext.EventManager.onWindowResize(this.hide, this);
+ }else{
+ if(this.initialConfig.hidden !== false){
+ this.hidden = false;
+ }
+ this.internalDefaults = {hideOnClick: false};
+ }
+ Ext.menu.Menu.superclass.initComponent.call(this);
+ if(this.autoLayout){
+ var fn = this.doLayout.createDelegate(this, []);
+ this.on({
+ add: fn,
+ remove: fn
+ });
+ }
+ },
+
+ //private
+ getLayoutTarget : function() {
+ return this.ul;
+ },
+
+ // private
+ onRender : function(ct, position){
+ if(!ct){
+ ct = Ext.getBody();
+ }
+
+ var dh = {
+ id: this.getId(),
+ cls: 'x-menu ' + ((this.floating) ? 'x-menu-floating x-layer ' : '') + (this.cls || '') + (this.plain ? ' x-menu-plain' : '') + (this.showSeparator ? '' : ' x-menu-nosep'),
+ style: this.style,
+ cn: [
+ {tag: 'a', cls: 'x-menu-focus', href: '#', onclick: 'return false;', tabIndex: '-1'},
+ {tag: 'ul', cls: 'x-menu-list'}
+ ]
+ };
+ if(this.floating){
+ this.el = new Ext.Layer({
+ shadow: this.shadow,
+ dh: dh,
+ constrain: false,
+ parentEl: ct,
+ zindex: this.zIndex
+ });
+ }else{
+ this.el = ct.createChild(dh);
+ }
+ Ext.menu.Menu.superclass.onRender.call(this, ct, position);
+
+ if(!this.keyNav){
+ this.keyNav = new Ext.menu.MenuNav(this);
+ }
+ // generic focus element
+ this.focusEl = this.el.child('a.x-menu-focus');
+ this.ul = this.el.child('ul.x-menu-list');
+ this.mon(this.ul, {
+ scope: this,
+ click: this.onClick,
+ mouseover: this.onMouseOver,
+ mouseout: this.onMouseOut
+ });
+ if(this.enableScrolling){
+ this.mon(this.el, {
+ scope: this,
+ delegate: '.x-menu-scroller',
+ click: this.onScroll,
+ mouseover: this.deactivateActive
+ });
+ }
+ },
+
+ // private
+ findTargetItem : function(e){
+ var t = e.getTarget('.x-menu-list-item', this.ul, true);
+ if(t && t.menuItemId){
+ return this.items.get(t.menuItemId);
+ }
+ },
+
+ // private
+ onClick : function(e){
+ var t = this.findTargetItem(e);
+ if(t){
+ if(t.isFormField){
+ this.setActiveItem(t);
+ }else if(t instanceof Ext.menu.BaseItem){
+ if(t.menu && this.ignoreParentClicks){
+ t.expandMenu();
+ e.preventDefault();
+ }else if(t.onClick){
+ t.onClick(e);
+ this.fireEvent('click', this, t, e);
+ }
+ }
+ }
+ },
+
+ // private
+ setActiveItem : function(item, autoExpand){
+ if(item != this.activeItem){
+ this.deactivateActive();
+ if((this.activeItem = item).isFormField){
+ item.focus();
+ }else{
+ item.activate(autoExpand);
+ }
+ }else if(autoExpand){
+ item.expandMenu();
+ }
+ },
+
+ deactivateActive : function(){
+ var a = this.activeItem;
+ if(a){
+ if(a.isFormField){
+ //Fields cannot deactivate, but Combos must collapse
+ if(a.collapse){
+ a.collapse();
+ }
+ }else{
+ a.deactivate();
+ }
+ delete this.activeItem;
+ }
+ },
+
+ // private
+ tryActivate : function(start, step){
+ var items = this.items;
+ for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
+ var item = items.get(i);
+ if(!item.disabled && (item.canActivate || item.isFormField)){
+ this.setActiveItem(item, false);
+ return item;
+ }
+ }
+ return false;
+ },
+
+ // private
+ onMouseOver : function(e){
+ var t = this.findTargetItem(e);
+ if(t){
+ if(t.canActivate && !t.disabled){
+ this.setActiveItem(t, true);
+ }
+ }
+ this.over = true;
+ this.fireEvent('mouseover', this, e, t);
+ },
+
+ // private
+ onMouseOut : function(e){
+ var t = this.findTargetItem(e);
+ if(t){
+ if(t == this.activeItem && t.shouldDeactivate && t.shouldDeactivate(e)){
+ this.activeItem.deactivate();
+ delete this.activeItem;
+ }
+ }
+ this.over = false;
+ this.fireEvent('mouseout', this, e, t);
+ },
+
+ // private
+ onScroll : function(e, t){
+ if(e){
+ e.stopEvent();
+ }
+ var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
+ ul.scrollTop += this.scrollIncrement * (top ? -1 : 1);
+ if(top ? ul.scrollTop <= 0 : ul.scrollTop + this.activeMax >= ul.scrollHeight){
+ this.onScrollerOut(null, t);
+ }
+ },
+
+ // private
+ onScrollerIn : function(e, t){
+ var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
+ if(top ? ul.scrollTop > 0 : ul.scrollTop + this.activeMax < ul.scrollHeight){
+ Ext.fly(t).addClass(['x-menu-item-active', 'x-menu-scroller-active']);
+ }
+ },
+
+ // private
+ onScrollerOut : function(e, t){
+ Ext.fly(t).removeClass(['x-menu-item-active', 'x-menu-scroller-active']);
+ },
+
+ /**
+ * If {@link #floating}=true
, shows this menu relative to
+ * another element using {@link #showat}, otherwise uses {@link Ext.Component#show}.
+ * @param {Mixed} element The element to align to
+ * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
+ * the element (defaults to this.defaultAlign)
+ * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
+ */
+ show : function(el, pos, parentMenu){
+ if(this.floating){
+ this.parentMenu = parentMenu;
+ if(!this.el){
+ this.render();
+ this.doLayout(false, true);
+ }
+ this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign, this.defaultOffsets), parentMenu);
+ }else{
+ Ext.menu.Menu.superclass.show.call(this);
+ }
+ },
+
+ /**
+ * Displays this menu at a specific xy position and fires the 'show' event if a
+ * handler for the 'beforeshow' event does not return false cancelling the operation.
+ * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
+ * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
+ */
+ showAt : function(xy, parentMenu){
+ if(this.fireEvent('beforeshow', this) !== false){
+ this.parentMenu = parentMenu;
+ if(!this.el){
+ this.render();
+ }
+ if(this.enableScrolling){
+ // set the position so we can figure out the constrain value.
+ this.el.setXY(xy);
+ //constrain the value, keep the y coordinate the same
+ xy[1] = this.constrainScroll(xy[1]);
+ xy = [this.el.adjustForConstraints(xy)[0], xy[1]];
+ }else{
+ //constrain to the viewport.
+ xy = this.el.adjustForConstraints(xy);
+ }
+ this.el.setXY(xy);
+ this.el.show();
+ Ext.menu.Menu.superclass.onShow.call(this);
+ if(Ext.isIE){
+ // internal event, used so we don't couple the layout to the menu
+ this.fireEvent('autosize', this);
+ if(!Ext.isIE8){
+ this.el.repaint();
+ }
+ }
+ this.hidden = false;
+ this.focus();
+ this.fireEvent('show', this);
+ }
+ },
+
+ constrainScroll : function(y){
+ var max, full = this.ul.setHeight('auto').getHeight(),
+ returnY = y, normalY, parentEl, scrollTop, viewHeight;
+ if(this.floating){
+ parentEl = Ext.fly(this.el.dom.parentNode);
+ scrollTop = parentEl.getScroll().top;
+ viewHeight = parentEl.getViewSize().height;
+ //Normalize y by the scroll position for the parent element. Need to move it into the coordinate space
+ //of the view.
+ normalY = y - scrollTop;
+ max = this.maxHeight ? this.maxHeight : viewHeight - normalY;
+ if(full > viewHeight) {
+ max = viewHeight;
+ //Set returnY equal to (0,0) in view space by reducing y by the value of normalY
+ returnY = y - normalY;
+ } else if(max < full) {
+ returnY = y - (full - max);
+ max = full;
+ }
+ }else{
+ max = this.getHeight();
+ }
+ // Always respect maxHeight
+ if (this.maxHeight){
+ max = Math.min(this.maxHeight, max);
+ }
+ if(full > max && max > 0){
+ this.activeMax = max - this.scrollerHeight * 2 - this.el.getFrameWidth('tb') - Ext.num(this.el.shadowOffset, 0);
+ this.ul.setHeight(this.activeMax);
+ this.createScrollers();
+ this.el.select('.x-menu-scroller').setDisplayed('');
+ }else{
+ this.ul.setHeight(full);
+ this.el.select('.x-menu-scroller').setDisplayed('none');
+ }
+ this.ul.dom.scrollTop = 0;
+ return returnY;
+ },
+
+ createScrollers : function(){
+ if(!this.scroller){
+ this.scroller = {
+ pos: 0,
+ top: this.el.insertFirst({
+ tag: 'div',
+ cls: 'x-menu-scroller x-menu-scroller-top',
+ html: ' '
+ }),
+ bottom: this.el.createChild({
+ tag: 'div',
+ cls: 'x-menu-scroller x-menu-scroller-bottom',
+ html: ' '
+ })
+ };
+ this.scroller.top.hover(this.onScrollerIn, this.onScrollerOut, this);
+ this.scroller.topRepeater = new Ext.util.ClickRepeater(this.scroller.top, {
+ listeners: {
+ click: this.onScroll.createDelegate(this, [null, this.scroller.top], false)
+ }
+ });
+ this.scroller.bottom.hover(this.onScrollerIn, this.onScrollerOut, this);
+ this.scroller.bottomRepeater = new Ext.util.ClickRepeater(this.scroller.bottom, {
+ listeners: {
+ click: this.onScroll.createDelegate(this, [null, this.scroller.bottom], false)
+ }
+ });
+ }
+ },
+
+ onLayout : function(){
+ if(this.isVisible()){
+ if(this.enableScrolling){
+ this.constrainScroll(this.el.getTop());
+ }
+ if(this.floating){
+ this.el.sync();
+ }
+ }
+ },
+
+ focus : function(){
+ if(!this.hidden){
+ this.doFocus.defer(50, this);
+ }
+ },
+
+ doFocus : function(){
+ if(!this.hidden){
+ this.focusEl.focus();
+ }
+ },
+
+ /**
+ * Hides this menu and optionally all parent menus
+ * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
+ */
+ hide : function(deep){
+ if (!this.isDestroyed) {
+ this.deepHide = deep;
+ Ext.menu.Menu.superclass.hide.call(this);
+ delete this.deepHide;
+ }
+ },
+
+ // private
+ onHide : function(){
+ Ext.menu.Menu.superclass.onHide.call(this);
+ this.deactivateActive();
+ if(this.el && this.floating){
+ this.el.hide();
+ }
+ var pm = this.parentMenu;
+ if(this.deepHide === true && pm){
+ if(pm.floating){
+ pm.hide(true);
+ }else{
+ pm.deactivateActive();
+ }
+ }
+ },
+
+ // private
+ lookupComponent : function(c){
+ if(Ext.isString(c)){
+ c = (c == 'separator' || c == '-') ? new Ext.menu.Separator() : new Ext.menu.TextItem(c);
+ this.applyDefaults(c);
+ }else{
+ if(Ext.isObject(c)){
+ c = this.getMenuItem(c);
+ }else if(c.tagName || c.el){ // element. Wrap it.
+ c = new Ext.BoxComponent({
+ el: c
+ });
+ }
+ }
+ return c;
+ },
+
+ applyDefaults : function(c){
+ if(!Ext.isString(c)){
+ c = Ext.menu.Menu.superclass.applyDefaults.call(this, c);
+ var d = this.internalDefaults;
+ if(d){
+ if(c.events){
+ Ext.applyIf(c.initialConfig, d);
+ Ext.apply(c, d);
+ }else{
+ Ext.applyIf(c, d);
+ }
+ }
+ }
+ return c;
+ },
+
+ // private
+ getMenuItem : function(config){
+ if(!config.isXType){
+ if(!config.xtype && Ext.isBoolean(config.checked)){
+ return new Ext.menu.CheckItem(config)
+ }
+ return Ext.create(config, this.defaultType);
+ }
+ return config;
+ },
+
+ /**
+ * Adds a separator bar to the menu
+ * @return {Ext.menu.Item} The menu item that was added
+ */
+ addSeparator : function(){
+ return this.add(new Ext.menu.Separator());
+ },
+
+ /**
+ * Adds an {@link Ext.Element} object to the menu
+ * @param {Mixed} el The element or DOM node to add, or its id
+ * @return {Ext.menu.Item} The menu item that was added
+ */
+ addElement : function(el){
+ return this.add(new Ext.menu.BaseItem({
+ el: el
+ }));
+ },
+
+ /**
+ * Adds an existing object based on {@link Ext.menu.BaseItem} to the menu
+ * @param {Ext.menu.Item} item The menu item to add
+ * @return {Ext.menu.Item} The menu item that was added
+ */
+ addItem : function(item){
+ return this.add(item);
+ },
+
+ /**
+ * Creates a new {@link Ext.menu.Item} based an the supplied config object and adds it to the menu
+ * @param {Object} config A MenuItem config object
+ * @return {Ext.menu.Item} The menu item that was added
+ */
+ addMenuItem : function(config){
+ return this.add(this.getMenuItem(config));
+ },
+
+ /**
+ * Creates a new {@link Ext.menu.TextItem} with the supplied text and adds it to the menu
+ * @param {String} text The text to display in the menu item
+ * @return {Ext.menu.Item} The menu item that was added
+ */
+ addText : function(text){
+ return this.add(new Ext.menu.TextItem(text));
+ },
+
+ //private
+ onDestroy : function(){
+ Ext.EventManager.removeResizeListener(this.hide, this);
+ var pm = this.parentMenu;
+ if(pm && pm.activeChild == this){
+ delete pm.activeChild;
+ }
+ delete this.parentMenu;
+ Ext.menu.Menu.superclass.onDestroy.call(this);
+ Ext.menu.MenuMgr.unregister(this);
+ if(this.keyNav) {
+ this.keyNav.disable();
+ }
+ var s = this.scroller;
+ if(s){
+ Ext.destroy(s.topRepeater, s.bottomRepeater, s.top, s.bottom);
+ }
+ Ext.destroy(
+ this.el,
+ this.focusEl,
+ this.ul
+ );
+ }
+});
+
+Ext.reg('menu', Ext.menu.Menu);
+
+// MenuNav is a private utility class used internally by the Menu
+Ext.menu.MenuNav = Ext.extend(Ext.KeyNav, function(){
+ function up(e, m){
+ if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
+ m.tryActivate(m.items.length-1, -1);
+ }
+ }
+ function down(e, m){
+ if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
+ m.tryActivate(0, 1);
+ }
+ }
+ return {
+ constructor : function(menu){
+ Ext.menu.MenuNav.superclass.constructor.call(this, menu.el);
+ this.scope = this.menu = menu;
+ },
+
+ doRelay : function(e, h){
+ var k = e.getKey();
+// Keystrokes within a form Field (e.g.: down in a Combo) do not navigate. Allow only TAB
+ if (this.menu.activeItem && this.menu.activeItem.isFormField && k != e.TAB) {
+ return false;
+ }
+ if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
+ this.menu.tryActivate(0, 1);
+ return false;
+ }
+ return h.call(this.scope || this, e, this.menu);
+ },
+
+ tab: function(e, m) {
+ e.stopEvent();
+ if (e.shiftKey) {
+ up(e, m);
+ } else {
+ down(e, m);
+ }
+ },
+
+ up : up,
+
+ down : down,
+
+ right : function(e, m){
+ if(m.activeItem){
+ m.activeItem.expandMenu(true);
+ }
+ },
+
+ left : function(e, m){
+ m.hide();
+ if(m.parentMenu && m.parentMenu.activeItem){
+ m.parentMenu.activeItem.activate();
+ }
+ },
+
+ enter : function(e, m){
+ if(m.activeItem){
+ e.stopPropagation();
+ m.activeItem.onClick(e);
+ m.fireEvent('click', this, m.activeItem);
+ return true;
+ }
+ }
+ };
+}());
+/**
* @class Ext.menu.MenuMgr
* Provides a common registry of all menu items on a page so that they can be easily accessed by id.
* @singleton
@@ -756,7 +742,9 @@ Ext.menu.MenuMgr = function(){
c.each(function(m){
m.hide();
});
+ return true;
}
+ return false;
}
// private
@@ -780,7 +768,7 @@ Ext.menu.MenuMgr = function(){
if(m.parentMenu){
m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
m.parentMenu.activeChild = m;
- }else if(last && last.isVisible()){
+ }else if(last && !last.isDestroyed && last.isVisible()){
m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
}
}
@@ -829,9 +817,10 @@ Ext.menu.MenuMgr = function(){
/**
* Hides all menus that are currently visible
+ * @return {Boolean} success True if any active menus were hidden.
*/
hideAll : function(){
- hideAll();
+ return hideAll();
},
// private
@@ -840,18 +829,12 @@ Ext.menu.MenuMgr = function(){
init();
}
menus[menu.id] = menu;
- menu.on("beforehide", onBeforeHide);
- menu.on("hide", onHide);
- menu.on("beforeshow", onBeforeShow);
- menu.on("show", onShow);
- var g = menu.group;
- if(g && menu.events["checkchange"]){
- if(!groups[g]){
- groups[g] = [];
- }
- groups[g].push(menu);
- menu.on("checkchange", onCheck);
- }
+ menu.on({
+ beforehide: onBeforeHide,
+ hide: onHide,
+ beforeshow: onBeforeShow,
+ show: onShow
+ });
},
/**
@@ -882,11 +865,6 @@ Ext.menu.MenuMgr = function(){
menu.un("hide", onHide);
menu.un("beforeshow", onBeforeShow);
menu.un("show", onShow);
- var g = menu.group;
- if(g && menu.events["checkchange"]){
- groups[g].remove(menu);
- menu.un("checkchange", onCheck);
- }
},
// private
@@ -945,37 +923,7 @@ Ext.menu.MenuMgr = function(){
* @param {Object} config Configuration options
* @xtype menubaseitem
*/
-Ext.menu.BaseItem = function(config){
- Ext.menu.BaseItem.superclass.constructor.call(this, config);
-
- this.addEvents(
- /**
- * @event click
- * Fires when this item is clicked
- * @param {Ext.menu.BaseItem} this
- * @param {Ext.EventObject} e
- */
- 'click',
- /**
- * @event activate
- * Fires when this item is activated
- * @param {Ext.menu.BaseItem} this
- */
- 'activate',
- /**
- * @event deactivate
- * Fires when this item is deactivated
- * @param {Ext.menu.BaseItem} this
- */
- 'deactivate'
- );
-
- if(this.handler){
- this.on("click", this.handler, this.scope);
- }
-};
-
-Ext.extend(Ext.menu.BaseItem, Ext.Component, {
+Ext.menu.BaseItem = Ext.extend(Ext.Component, {
/**
* @property parentMenu
* @type Ext.menu.Menu
@@ -1006,7 +954,7 @@ Ext.extend(Ext.menu.BaseItem, Ext.Component, {
*/
hideOnClick : true,
/**
- * @cfg {Number} clickHideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
+ * @cfg {Number} clickHideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 1)
*/
clickHideDelay : 1,
@@ -1016,6 +964,34 @@ Ext.extend(Ext.menu.BaseItem, Ext.Component, {
// private
actionMode : "container",
+ initComponent : function(){
+ Ext.menu.BaseItem.superclass.initComponent.call(this);
+ this.addEvents(
+ /**
+ * @event click
+ * Fires when this item is clicked
+ * @param {Ext.menu.BaseItem} this
+ * @param {Ext.EventObject} e
+ */
+ 'click',
+ /**
+ * @event activate
+ * Fires when this item is activated
+ * @param {Ext.menu.BaseItem} this
+ */
+ 'activate',
+ /**
+ * @event deactivate
+ * Fires when this item is deactivated
+ * @param {Ext.menu.BaseItem} this
+ */
+ 'deactivate'
+ );
+ if(this.handler){
+ this.on("click", this.handler, this.scope);
+ }
+ },
+
// private
onRender : function(container, position){
Ext.menu.BaseItem.superclass.onRender.apply(this, arguments);
@@ -1023,9 +999,12 @@ Ext.extend(Ext.menu.BaseItem, Ext.Component, {
this.parentMenu = this.ownerCt;
}else{
this.container.addClass('x-menu-list-item');
- this.mon(this.el, 'click', this.onClick, this);
- this.mon(this.el, 'mouseenter', this.activate, this);
- this.mon(this.el, 'mouseleave', this.deactivate, this);
+ this.mon(this.el, {
+ scope: this,
+ click: this.onClick,
+ mouseenter: this.activate,
+ mouseleave: this.deactivate
+ });
}
},
@@ -1033,7 +1012,7 @@ Ext.extend(Ext.menu.BaseItem, Ext.Component, {
* Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
* config property). If an existing handler is already registered, it will be unregistered for you.
* @param {Function} handler The function that should be called on click
- * @param {Object} scope The scope that should be passed to the handler
+ * @param {Object} scope The scope (this
reference) in which the handler function is executed. Defaults to this menu item.
*/
setHandler : function(handler, scope){
if(this.handler){
@@ -1077,8 +1056,13 @@ Ext.extend(Ext.menu.BaseItem, Ext.Component, {
// private
handleClick : function(e){
+ var pm = this.parentMenu;
if(this.hideOnClick){
- this.parentMenu.hide.defer(this.clickHideDelay, this.parentMenu, [true]);
+ if(pm.floating){
+ pm.hide.defer(this.clickHideDelay, pm, [true]);
+ }else{
+ pm.deactivateActive();
+ }
}
},
@@ -1098,14 +1082,7 @@ Ext.reg('menubaseitem', Ext.menu.BaseItem);/**
* is applied as a config object (and should contain a text property).
* @xtype menutextitem
*/
-Ext.menu.TextItem = function(cfg){
- if(typeof cfg == 'string'){
- cfg = {text: cfg}
- }
- Ext.menu.TextItem.superclass.constructor.call(this, cfg);
-};
-
-Ext.extend(Ext.menu.TextItem, Ext.menu.BaseItem, {
+Ext.menu.TextItem = Ext.extend(Ext.menu.BaseItem, {
/**
* @cfg {String} text The text to display for this item (defaults to '')
*/
@@ -1117,6 +1094,13 @@ Ext.extend(Ext.menu.TextItem, Ext.menu.BaseItem, {
* @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
*/
itemCls : "x-menu-text",
+
+ constructor : function(config){
+ if(typeof config == 'string'){
+ config = {text: config}
+ }
+ Ext.menu.TextItem.superclass.constructor.call(this, config);
+ },
// private
onRender : function(){
@@ -1136,11 +1120,7 @@ Ext.reg('menutextitem', Ext.menu.TextItem);/**
* @param {Object} config Configuration options
* @xtype menuseparator
*/
-Ext.menu.Separator = function(config){
- Ext.menu.Separator.superclass.constructor.call(this, config);
-};
-
-Ext.extend(Ext.menu.Separator, Ext.menu.BaseItem, {
+Ext.menu.Separator = Ext.extend(Ext.menu.BaseItem, {
/**
* @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
*/
@@ -1166,210 +1146,216 @@ Ext.extend(Ext.menu.Separator, Ext.menu.BaseItem, {
Ext.menu.Separator.superclass.onRender.apply(this, arguments);
}
});
-Ext.reg('menuseparator', Ext.menu.Separator);/**
- * @class Ext.menu.Item
- * @extends Ext.menu.BaseItem
- * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
- * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
- * activation and click handling.
- * @constructor
- * Creates a new Item
- * @param {Object} config Configuration options
- * @xtype menuitem
- */
-Ext.menu.Item = function(config){
- Ext.menu.Item.superclass.constructor.call(this, config);
- if(this.menu){
- this.menu = Ext.menu.MenuMgr.get(this.menu);
- }
-};
-Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, {
- /**
- * @property menu
- * @type Ext.menu.Menu
- * The submenu associated with this Item if one was configured.
- */
- /**
- * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
- * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
- */
- /**
- * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
- * icon is specified {@link #iconCls} should not be.
- */
- /**
- * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
- * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
- */
- /**
- * @cfg {String} text The text to display in this item (defaults to '').
- */
- /**
- * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
- */
- /**
- * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
- */
- /**
- * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
- */
- itemCls : 'x-menu-item',
- /**
- * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
- */
- canActivate : true,
- /**
- * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
- */
- showDelay: 200,
- // doc'd in BaseItem
- hideDelay: 200,
-
- // private
- ctype: 'Ext.menu.Item',
-
- // private
- onRender : function(container, position){
- if (!this.itemTpl) {
- this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
- '',
- ' target="{hrefTarget}"',
- '',
- '>',
- '',
- ''
- );
- }
- var a = this.getTemplateArgs();
- this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
- this.iconEl = this.el.child('img.x-menu-item-icon');
- this.textEl = this.el.child('.x-menu-item-text');
- Ext.menu.Item.superclass.onRender.call(this, container, position);
- },
-
- getTemplateArgs: function() {
- return {
- id: this.id,
- cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
- href: this.href || '#',
- hrefTarget: this.hrefTarget,
- icon: this.icon || Ext.BLANK_IMAGE_URL,
- iconCls: this.iconCls || '',
- text: this.itemText||this.text||' '
- };
- },
-
- /**
- * Sets the text to display in this menu item
- * @param {String} text The text to display
- */
- setText : function(text){
- this.text = text||' ';
- if(this.rendered){
- this.textEl.update(this.text);
- this.parentMenu.layout.doAutoSize();
- }
- },
-
- /**
- * Sets the CSS class to apply to the item's icon element
- * @param {String} cls The CSS class to apply
- */
- setIconClass : function(cls){
- var oldCls = this.iconCls;
- this.iconCls = cls;
- if(this.rendered){
- this.iconEl.replaceClass(oldCls, this.iconCls);
- }
- },
-
- //private
- beforeDestroy: function(){
- if (this.menu){
- this.menu.destroy();
- }
- Ext.menu.Item.superclass.beforeDestroy.call(this);
- },
-
- // private
- handleClick : function(e){
- if(!this.href){ // if no link defined, stop the event automatically
- e.stopEvent();
- }
- Ext.menu.Item.superclass.handleClick.apply(this, arguments);
- },
-
- // private
- activate : function(autoExpand){
- if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
- this.focus();
- if(autoExpand){
- this.expandMenu();
- }
- }
- return true;
- },
-
- // private
- shouldDeactivate : function(e){
- if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
- if(this.menu && this.menu.isVisible()){
- return !this.menu.getEl().getRegion().contains(e.getPoint());
- }
- return true;
- }
- return false;
- },
-
- // private
- deactivate : function(){
- Ext.menu.Item.superclass.deactivate.apply(this, arguments);
- this.hideMenu();
- },
-
- // private
- expandMenu : function(autoActivate){
- if(!this.disabled && this.menu){
- clearTimeout(this.hideTimer);
- delete this.hideTimer;
- if(!this.menu.isVisible() && !this.showTimer){
- this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
- }else if (this.menu.isVisible() && autoActivate){
- this.menu.tryActivate(0, 1);
- }
- }
- },
-
- // private
- deferExpand : function(autoActivate){
- delete this.showTimer;
- this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
- if(autoActivate){
- this.menu.tryActivate(0, 1);
- }
- },
-
- // private
- hideMenu : function(){
- clearTimeout(this.showTimer);
- delete this.showTimer;
- if(!this.hideTimer && this.menu && this.menu.isVisible()){
- this.hideTimer = this.deferHide.defer(this.hideDelay, this);
- }
- },
-
- // private
- deferHide : function(){
- delete this.hideTimer;
- if(this.menu.over){
- this.parentMenu.setActiveItem(this, false);
- }else{
- this.menu.hide();
- }
- }
-});
+Ext.reg('menuseparator', Ext.menu.Separator);/**
+ * @class Ext.menu.Item
+ * @extends Ext.menu.BaseItem
+ * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
+ * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
+ * activation and click handling.
+ * @constructor
+ * Creates a new Item
+ * @param {Object} config Configuration options
+ * @xtype menuitem
+ */
+Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {
+ /**
+ * @property menu
+ * @type Ext.menu.Menu
+ * The submenu associated with this Item if one was configured.
+ */
+ /**
+ * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
+ * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
+ */
+ /**
+ * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
+ * icon is specified {@link #iconCls} should not be.
+ */
+ /**
+ * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
+ * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
+ */
+ /**
+ * @cfg {String} text The text to display in this item (defaults to '').
+ */
+ /**
+ * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
+ */
+ /**
+ * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
+ */
+ /**
+ * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
+ */
+ itemCls : 'x-menu-item',
+ /**
+ * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
+ */
+ canActivate : true,
+ /**
+ * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
+ */
+ showDelay: 200,
+ // doc'd in BaseItem
+ hideDelay: 200,
+
+ // private
+ ctype: 'Ext.menu.Item',
+
+ initComponent : function(){
+ Ext.menu.Item.superclass.initComponent.call(this);
+ if(this.menu){
+ this.menu = Ext.menu.MenuMgr.get(this.menu);
+ this.menu.ownerCt = this;
+ }
+ },
+
+ // private
+ onRender : function(container, position){
+ if (!this.itemTpl) {
+ this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
+ ' ',
- '',
+ ' target="{hrefTarget}"',
+ '',
+ '>',
+ '',
+ ''
+ );
+ }
+ var a = this.getTemplateArgs();
+ this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
+ this.iconEl = this.el.child('img.x-menu-item-icon');
+ this.textEl = this.el.child('.x-menu-item-text');
+ if(!this.href) { // if no link defined, prevent the default anchor event
+ this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
+ }
+ Ext.menu.Item.superclass.onRender.call(this, container, position);
+ },
+
+ getTemplateArgs: function() {
+ return {
+ id: this.id,
+ cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
+ href: this.href || '#',
+ hrefTarget: this.hrefTarget,
+ icon: this.icon || Ext.BLANK_IMAGE_URL,
+ iconCls: this.iconCls || '',
+ text: this.itemText||this.text||' '
+ };
+ },
+
+ /**
+ * Sets the text to display in this menu item
+ * @param {String} text The text to display
+ */
+ setText : function(text){
+ this.text = text||' ';
+ if(this.rendered){
+ this.textEl.update(this.text);
+ this.parentMenu.layout.doAutoSize();
+ }
+ },
+
+ /**
+ * Sets the CSS class to apply to the item's icon element
+ * @param {String} cls The CSS class to apply
+ */
+ setIconClass : function(cls){
+ var oldCls = this.iconCls;
+ this.iconCls = cls;
+ if(this.rendered){
+ this.iconEl.replaceClass(oldCls, this.iconCls);
+ }
+ },
+
+ //private
+ beforeDestroy: function(){
+ if (this.menu){
+ delete this.menu.ownerCt;
+ this.menu.destroy();
+ }
+ Ext.menu.Item.superclass.beforeDestroy.call(this);
+ },
+
+ // private
+ handleClick : function(e){
+ if(!this.href){ // if no link defined, stop the event automatically
+ e.stopEvent();
+ }
+ Ext.menu.Item.superclass.handleClick.apply(this, arguments);
+ },
+
+ // private
+ activate : function(autoExpand){
+ if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
+ this.focus();
+ if(autoExpand){
+ this.expandMenu();
+ }
+ }
+ return true;
+ },
+
+ // private
+ shouldDeactivate : function(e){
+ if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
+ if(this.menu && this.menu.isVisible()){
+ return !this.menu.getEl().getRegion().contains(e.getPoint());
+ }
+ return true;
+ }
+ return false;
+ },
+
+ // private
+ deactivate : function(){
+ Ext.menu.Item.superclass.deactivate.apply(this, arguments);
+ this.hideMenu();
+ },
+
+ // private
+ expandMenu : function(autoActivate){
+ if(!this.disabled && this.menu){
+ clearTimeout(this.hideTimer);
+ delete this.hideTimer;
+ if(!this.menu.isVisible() && !this.showTimer){
+ this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
+ }else if (this.menu.isVisible() && autoActivate){
+ this.menu.tryActivate(0, 1);
+ }
+ }
+ },
+
+ // private
+ deferExpand : function(autoActivate){
+ delete this.showTimer;
+ this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
+ if(autoActivate){
+ this.menu.tryActivate(0, 1);
+ }
+ },
+
+ // private
+ hideMenu : function(){
+ clearTimeout(this.showTimer);
+ delete this.showTimer;
+ if(!this.hideTimer && this.menu && this.menu.isVisible()){
+ this.hideTimer = this.deferHide.defer(this.hideDelay, this);
+ }
+ },
+
+ // private
+ deferHide : function(){
+ delete this.hideTimer;
+ if(this.menu.over){
+ this.parentMenu.setActiveItem(this, false);
+ }else{
+ this.menu.hide();
+ }
+ }
+});
Ext.reg('menuitem', Ext.menu.Item);/**
* @class Ext.menu.CheckItem
* @extends Ext.menu.Item
@@ -1379,37 +1365,7 @@ Ext.reg('menuitem', Ext.menu.Item);/**
* @param {Object} config Configuration options
* @xtype menucheckitem
*/
-Ext.menu.CheckItem = function(config){
- Ext.menu.CheckItem.superclass.constructor.call(this, config);
- this.addEvents(
- /**
- * @event beforecheckchange
- * Fires before the checked value is set, providing an opportunity to cancel if needed
- * @param {Ext.menu.CheckItem} this
- * @param {Boolean} checked The new checked value that will be set
- */
- "beforecheckchange" ,
- /**
- * @event checkchange
- * Fires after the checked value has been set
- * @param {Ext.menu.CheckItem} this
- * @param {Boolean} checked The checked value that was set
- */
- "checkchange"
- );
- /**
- * A function that handles the checkchange event. The function is undefined by default, but if an implementation
- * is provided, it will be called automatically when the checkchange event fires.
- * @param {Ext.menu.CheckItem} this
- * @param {Boolean} checked The checked value that was set
- * @method checkHandler
- */
- if(this.checkHandler){
- this.on('checkchange', this.checkHandler, this.scope);
- }
- Ext.menu.MenuMgr.registerCheckable(this);
-};
-Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
+Ext.menu.CheckItem = Ext.extend(Ext.menu.Item, {
/**
* @cfg {String} group
* All check items with the same group name will automatically be grouped into a single-select
@@ -1433,6 +1389,37 @@ Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
// private
ctype: "Ext.menu.CheckItem",
+
+ initComponent : function(){
+ Ext.menu.CheckItem.superclass.initComponent.call(this);
+ this.addEvents(
+ /**
+ * @event beforecheckchange
+ * Fires before the checked value is set, providing an opportunity to cancel if needed
+ * @param {Ext.menu.CheckItem} this
+ * @param {Boolean} checked The new checked value that will be set
+ */
+ "beforecheckchange" ,
+ /**
+ * @event checkchange
+ * Fires after the checked value has been set
+ * @param {Ext.menu.CheckItem} this
+ * @param {Boolean} checked The checked value that was set
+ */
+ "checkchange"
+ );
+ /**
+ * A function that handles the checkchange event. The function is undefined by default, but if an implementation
+ * is provided, it will be called automatically when the checkchange event fires.
+ * @param {Ext.menu.CheckItem} this
+ * @param {Boolean} checked The checked value that was set
+ * @method checkHandler
+ */
+ if(this.checkHandler){
+ this.on('checkchange', this.checkHandler, this.scope);
+ }
+ Ext.menu.MenuMgr.registerCheckable(this);
+ },
// private
onRender : function(c){
@@ -1458,12 +1445,13 @@ Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
* @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
*/
setChecked : function(state, suppressEvent){
- if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
+ var suppress = suppressEvent === true;
+ if(this.checked != state && (suppress || this.fireEvent("beforecheckchange", this, state) !== false)){
if(this.container){
this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
}
this.checked = state;
- if(suppressEvent !== true){
+ if(!suppress){
this.fireEvent("checkchange", this, state);
}
}
@@ -1477,152 +1465,224 @@ Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
}
});
-Ext.reg('menucheckitem', Ext.menu.CheckItem);/**
- * @class Ext.menu.DateMenu
- * @extends Ext.menu.Menu
- * A menu containing a {@link Ext.DatePicker} Component.
- * @xtype datemenu
- */
- Ext.menu.DateMenu = Ext.extend(Ext.menu.Menu, {
- /**
- * @cfg {Boolean} enableScrolling
- * @hide
- */
- enableScrolling: false,
-
- /**
- * @cfg {Boolean} hideOnClick
- * False to continue showing the menu after a date is selected, defaults to true.
- */
- hideOnClick: true,
-
- /**
- * @cfg {Number} maxHeight
- * @hide
- */
- /**
- * @cfg {Number} scrollIncrement
- * @hide
- */
- /**
- * @property picker
- * @type DatePicker
- * The {@link Ext.DatePicker} instance for this DateMenu
- */
- cls: 'x-date-menu',
-
- /**
- * @event click
- * @hide
- */
-
- /**
- * @event itemclick
- * @hide
- */
-
- initComponent: function(){
- this.on('beforeshow', this.onBeforeShow, this);
- if(this.strict = (Ext.isIE7 && Ext.isStrict)){
- this.on('show', this.onShow, this, {single: true, delay: 20});
- }
- Ext.apply(this, {
- plain: true,
- showSeparator: false,
- items: this.picker = new Ext.DatePicker(Ext.apply({
- internalRender: this.strict || !Ext.isIE,
- ctCls: 'x-menu-date-item'
- }, this.initialConfig))
- });
- this.picker.purgeListeners();
- Ext.menu.DateMenu.superclass.initComponent.call(this);
- this.relayEvents(this.picker, ["select"]);
- this.on('select', this.menuHide, this);
- if(this.handler){
- this.on('select', this.handler, this.scope || this);
- }
- },
-
- menuHide: function() {
- if(this.hideOnClick){
- this.hide(true);
- }
- },
-
- onBeforeShow: function(){
- if(this.picker){
- this.picker.hideMonthPicker(true);
- }
- },
-
- onShow: function(){
- var el = this.picker.getEl();
- el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode
- }
- });
- Ext.reg('datemenu', Ext.menu.DateMenu);/**
- * @class Ext.menu.ColorMenu
- * @extends Ext.menu.Menu
- * A menu containing a {@link Ext.ColorPalette} Component.
- * @xtype colormenu
- */
- Ext.menu.ColorMenu = Ext.extend(Ext.menu.Menu, {
- /**
- * @cfg {Boolean} enableScrolling
- * @hide
- */
- enableScrolling: false,
-
- /**
- * @cfg {Boolean} hideOnClick
- * False to continue showing the menu after a color is selected, defaults to true.
- */
- hideOnClick: true,
-
- /**
- * @cfg {Number} maxHeight
- * @hide
- */
- /**
- * @cfg {Number} scrollIncrement
- * @hide
- */
- /**
- * @property palette
- * @type ColorPalette
- * The {@link Ext.ColorPalette} instance for this ColorMenu
- */
-
-
- /**
- * @event click
- * @hide
- */
-
- /**
- * @event itemclick
- * @hide
- */
-
- initComponent: function(){
- Ext.apply(this, {
- plain: true,
- showSeparator: false,
- items: this.palette = new Ext.ColorPalette(this.initialConfig)
- });
- this.palette.purgeListeners();
- Ext.menu.ColorMenu.superclass.initComponent.call(this);
- this.relayEvents(this.palette, ['select']);
- this.on('select', this.menuHide, this);
- if(this.handler){
- this.on('select', this.handler, this.scope || this)
- }
- },
-
- menuHide: function(){
- if(this.hideOnClick){
- this.hide(true);
- }
- }
-});
-Ext.reg('colormenu', Ext.menu.ColorMenu);
\ No newline at end of file
+Ext.reg('menucheckitem', Ext.menu.CheckItem);/**
+ * @class Ext.menu.DateMenu
+ * @extends Ext.menu.Menu
+ * ',
+ '
A menu containing an {@link Ext.DatePicker} Component.
+ *Notes:
picker
: DatePickerdate
: Date{@link #handler}
+ * function will be called. Defaults to this DateMenu instance.
+ */
+ /**
+ * @cfg {Boolean} hideOnClick
+ * False to continue showing the menu after a date is selected, defaults to true.
+ */
+ hideOnClick : true,
+
+ /**
+ * @cfg {String} pickerId
+ * An id to assign to the underlying date picker. Defaults to null.
+ */
+ pickerId : null,
+
+ /**
+ * @cfg {Number} maxHeight
+ * @hide
+ */
+ /**
+ * @cfg {Number} scrollIncrement
+ * @hide
+ */
+ /**
+ * The {@link Ext.DatePicker} instance for this DateMenu
+ * @property picker
+ * @type DatePicker
+ */
+ cls : 'x-date-menu',
+
+ /**
+ * @event click
+ * @hide
+ */
+
+ /**
+ * @event itemclick
+ * @hide
+ */
+
+ initComponent : function(){
+ this.on('beforeshow', this.onBeforeShow, this);
+ if(this.strict = (Ext.isIE7 && Ext.isStrict)){
+ this.on('show', this.onShow, this, {single: true, delay: 20});
+ }
+ Ext.apply(this, {
+ plain: true,
+ showSeparator: false,
+ items: this.picker = new Ext.DatePicker(Ext.applyIf({
+ internalRender: this.strict || !Ext.isIE,
+ ctCls: 'x-menu-date-item',
+ id: this.pickerId
+ }, this.initialConfig))
+ });
+ this.picker.purgeListeners();
+ Ext.menu.DateMenu.superclass.initComponent.call(this);
+ /**
+ * @event select
+ * Fires when a date is selected from the {@link #picker Ext.DatePicker}
+ * @param {DatePicker} picker The {@link #picker Ext.DatePicker}
+ * @param {Date} date The selected date
+ */
+ this.relayEvents(this.picker, ['select']);
+ this.on('show', this.picker.focus, this.picker);
+ this.on('select', this.menuHide, this);
+ if(this.handler){
+ this.on('select', this.handler, this.scope || this);
+ }
+ },
+
+ menuHide : function() {
+ if(this.hideOnClick){
+ this.hide(true);
+ }
+ },
+
+ onBeforeShow : function(){
+ if(this.picker){
+ this.picker.hideMonthPicker(true);
+ }
+ },
+
+ onShow : function(){
+ var el = this.picker.getEl();
+ el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode
+ }
+ });
+ Ext.reg('datemenu', Ext.menu.DateMenu);
+ /**
+ * @class Ext.menu.ColorMenu
+ * @extends Ext.menu.Menu
+ * A menu containing a {@link Ext.ColorPalette} Component.
+ *Notes:
palette
: ColorPalettecolor
: String{@link #handler}
+ * function will be called. Defaults to this ColorMenu instance.
+ */
+
+ /**
+ * @cfg {Boolean} hideOnClick
+ * False to continue showing the menu after a color is selected, defaults to true.
+ */
+ hideOnClick : true,
+
+ cls : 'x-color-menu',
+
+ /**
+ * @cfg {String} paletteId
+ * An id to assign to the underlying color palette. Defaults to null.
+ */
+ paletteId : null,
+
+ /**
+ * @cfg {Number} maxHeight
+ * @hide
+ */
+ /**
+ * @cfg {Number} scrollIncrement
+ * @hide
+ */
+ /**
+ * @property palette
+ * @type ColorPalette
+ * The {@link Ext.ColorPalette} instance for this ColorMenu
+ */
+
+
+ /**
+ * @event click
+ * @hide
+ */
+
+ /**
+ * @event itemclick
+ * @hide
+ */
+
+ initComponent : function(){
+ Ext.apply(this, {
+ plain: true,
+ showSeparator: false,
+ items: this.palette = new Ext.ColorPalette(Ext.applyIf({
+ id: this.paletteId
+ }, this.initialConfig))
+ });
+ this.palette.purgeListeners();
+ Ext.menu.ColorMenu.superclass.initComponent.call(this);
+ /**
+ * @event select
+ * Fires when a color is selected from the {@link #palette Ext.ColorPalette}
+ * @param {Ext.ColorPalette} palette The {@link #palette Ext.ColorPalette}
+ * @param {String} color The 6-digit color hex code (without the # symbol)
+ */
+ this.relayEvents(this.palette, ['select']);
+ this.on('select', this.menuHide, this);
+ if(this.handler){
+ this.on('select', this.handler, this.scope || this);
+ }
+ },
+
+ menuHide : function(){
+ if(this.hideOnClick){
+ this.hide(true);
+ }
+ }
+});
+Ext.reg('colormenu', Ext.menu.ColorMenu);