Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / src / widgets / Button.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 /**
8  * @class Ext.Button
9  * @extends Ext.BoxComponent
10  * Simple Button class
11  * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
12  * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
13  * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
14  * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
15  * The handler is passed the following parameters:<div class="mdetail-params"><ul>
16  * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
17  * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
18  * </ul></div>
19  * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
20  * See also {@link Ext.Panel}.<tt>{@link Ext.Panel#minButtonWidth minButtonWidth}</tt>.
21  * @cfg {String/Object} tooltip The tooltip for the button - can be a string to be used as innerHTML (html tags are accepted) or QuickTips config object
22  * @cfg {Boolean} hidden True to start hidden (defaults to false)
23  * @cfg {Boolean} disabled True to start disabled (defaults to false)
24  * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
25  * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
26  * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
27  * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
28  * @constructor
29  * Create a new button
30  * @param {Object} config The config object
31  * @xtype button
32  */
33 Ext.Button = Ext.extend(Ext.BoxComponent, {
34     /**
35      * Read-only. True if this button is hidden
36      * @type Boolean
37      */
38     hidden : false,
39     /**
40      * Read-only. True if this button is disabled
41      * @type Boolean
42      */
43     disabled : false,
44     /**
45      * Read-only. True if this button is pressed (only if enableToggle = true)
46      * @type Boolean
47      */
48     pressed : false,
49
50     /**
51      * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
52      */
53
54     /**
55      * @cfg {Boolean} allowDepress
56      * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
57      */
58
59     /**
60      * @cfg {Boolean} enableToggle
61      * True to enable pressed/not pressed toggling (defaults to false)
62      */
63     enableToggle : false,
64     /**
65      * @cfg {Function} toggleHandler
66      * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
67      * <li><b>button</b> : Ext.Button<div class="sub-desc">this Button object</div></li>
68      * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
69      * </ul>
70      */
71     /**
72      * @cfg {Mixed} menu
73      * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
74      */
75     /**
76      * @cfg {String} menuAlign
77      * The position to align the menu to (see {@link Ext.Element#alignTo} for more details, defaults to 'tl-bl?').
78      */
79     menuAlign : 'tl-bl?',
80
81     /**
82      * @cfg {String} overflowText If used in a {@link Ext.Toolbar Toolbar}, the
83      * text to be used if this item is shown in the overflow menu. See also
84      * {@link Ext.Toolbar.Item}.<code>{@link Ext.Toolbar.Item#overflowText overflowText}</code>.
85      */
86     /**
87      * @cfg {String} iconCls
88      * A css class which sets a background image to be used as the icon for this button
89      */
90     /**
91      * @cfg {String} type
92      * submit, reset or button - defaults to 'button'
93      */
94     type : 'button',
95
96     // private
97     menuClassTarget : 'tr:nth(2)',
98
99     /**
100      * @cfg {String} clickEvent
101      * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
102      * Defaults to <tt>'click'</tt>.
103      */
104     clickEvent : 'click',
105
106     /**
107      * @cfg {Boolean} handleMouseEvents
108      * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
109      */
110     handleMouseEvents : true,
111
112     /**
113      * @cfg {String} tooltipType
114      * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
115      */
116     tooltipType : 'qtip',
117
118     /**
119      * @cfg {String} buttonSelector
120      * <p>(Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the
121      * DOM structure created.</p>
122      * <p>When a custom {@link #template} is used, you  must ensure that this selector results in the selection of
123      * a focussable element.</p>
124      * <p>Defaults to <b><tt>'button:first-child'</tt></b>.</p>
125      */
126     buttonSelector : 'button:first-child',
127
128     /**
129      * @cfg {String} scale
130      * <p>(Optional) The size of the Button. Three values are allowed:</p>
131      * <ul class="mdetail-params">
132      * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
133      * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
134      * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
135      * </ul>
136      * <p>Defaults to <b><tt>'small'</tt></b>.</p>
137      */
138     scale : 'small',
139
140     /**
141      * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
142      * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
143      * executed. Defaults to this Button.
144      */
145
146     /**
147      * @cfg {String} iconAlign
148      * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
149      * <ul class="mdetail-params">
150      * <li>'top'<div class="sub-desc"></div></li>
151      * <li>'right'<div class="sub-desc"></div></li>
152      * <li>'bottom'<div class="sub-desc"></div></li>
153      * <li>'left'<div class="sub-desc"></div></li>
154      * </ul>
155      * <p>Defaults to <b><tt>'left'</tt></b>.</p>
156      */
157     iconAlign : 'left',
158
159     /**
160      * @cfg {String} arrowAlign
161      * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
162      * Two values are allowed:</p>
163      * <ul class="mdetail-params">
164      * <li>'right'<div class="sub-desc"></div></li>
165      * <li>'bottom'<div class="sub-desc"></div></li>
166      * </ul>
167      * <p>Defaults to <b><tt>'right'</tt></b>.</p>
168      */
169     arrowAlign : 'right',
170
171     /**
172      * @cfg {Ext.Template} template (Optional)
173      * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
174      * Instances, or subclasses which need a different DOM structure may provide a different
175      * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
176      * @type Ext.Template
177      * @property template
178      */
179     /**
180      * @cfg {String} cls
181      * A CSS class string to apply to the button's main element.
182      */
183     /**
184      * @property menu
185      * @type Menu
186      * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
187      */
188     /**
189      * @cfg {Boolean} autoWidth
190      * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
191      * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
192      * the button from doing this automatic sizing.
193      * Defaults to <tt>undefined</tt>.
194      */
195
196     initComponent : function(){
197         if(this.menu){
198             this.menu = Ext.menu.MenuMgr.get(this.menu);
199             this.menu.ownerCt = this;
200         }
201         
202         Ext.Button.superclass.initComponent.call(this);
203
204         this.addEvents(
205             /**
206              * @event click
207              * Fires when this button is clicked
208              * @param {Button} this
209              * @param {EventObject} e The click event
210              */
211             'click',
212             /**
213              * @event toggle
214              * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
215              * @param {Button} this
216              * @param {Boolean} pressed
217              */
218             'toggle',
219             /**
220              * @event mouseover
221              * Fires when the mouse hovers over the button
222              * @param {Button} this
223              * @param {Event} e The event object
224              */
225             'mouseover',
226             /**
227              * @event mouseout
228              * Fires when the mouse exits the button
229              * @param {Button} this
230              * @param {Event} e The event object
231              */
232             'mouseout',
233             /**
234              * @event menushow
235              * If this button has a menu, this event fires when it is shown
236              * @param {Button} this
237              * @param {Menu} menu
238              */
239             'menushow',
240             /**
241              * @event menuhide
242              * If this button has a menu, this event fires when it is hidden
243              * @param {Button} this
244              * @param {Menu} menu
245              */
246             'menuhide',
247             /**
248              * @event menutriggerover
249              * If this button has a menu, this event fires when the mouse enters the menu triggering element
250              * @param {Button} this
251              * @param {Menu} menu
252              * @param {EventObject} e
253              */
254             'menutriggerover',
255             /**
256              * @event menutriggerout
257              * If this button has a menu, this event fires when the mouse leaves the menu triggering element
258              * @param {Button} this
259              * @param {Menu} menu
260              * @param {EventObject} e
261              */
262             'menutriggerout'
263         );
264         
265         if (this.menu){
266             this.menu.ownerCt = undefined;
267         }
268         if(Ext.isString(this.toggleGroup)){
269             this.enableToggle = true;
270         }
271     },
272
273 /**
274   * <p>This method returns an Array which provides substitution parameters for the {@link #template Template} used
275   * to create this Button's DOM structure.</p>
276   * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
277   * own implementation of this method.</p>
278   * <p>The default implementation which provides data for the default {@link #template} returns an Array containing the
279   * following items:</p><div class="mdetail-params"><ul>
280   * <li>The &lt;button&gt;'s {@link #type}</li>
281   * <li>A CSS class name applied to the Button's main &lt;tbody&gt; element which determines the button's scale and icon alignment.</li>
282   * <li>A CSS class to determine the presence and position of an arrow icon. (<code>'x-btn-arrow'</code> or <code>'x-btn-arrow-bottom'</code> or <code>''</code>)</li>
283   * <li>The {@link #cls} CSS class name applied to the button's wrapping &lt;table&gt; element.</li>
284   * <li>The Component id which is applied to the button's wrapping &lt;table&gt; element.</li>
285   * </ul></div>
286   * @return {Array} Substitution data for a Template.
287  */
288     getTemplateArgs : function(){
289         return [this.type, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];
290     },
291
292     // private
293     setButtonClass : function(){
294         if(this.useSetClass){
295             if(!Ext.isEmpty(this.oldCls)){
296                 this.el.removeClass([this.oldCls, 'x-btn-pressed']);
297             }
298             this.oldCls = (this.iconCls || this.icon) ? (this.text ? 'x-btn-text-icon' : 'x-btn-icon') : 'x-btn-noicon';
299             this.el.addClass([this.oldCls, this.pressed ? 'x-btn-pressed' : null]);
300         }
301     },
302
303     // protected
304     getMenuClass : function(){
305         return this.menu ? (this.arrowAlign != 'bottom' ? 'x-btn-arrow' : 'x-btn-arrow-bottom') : '';
306     },
307
308     // private
309     onRender : function(ct, position){
310         if(!this.template){
311             if(!Ext.Button.buttonTemplate){
312                 // hideous table template
313                 Ext.Button.buttonTemplate = new Ext.Template(
314                     '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
315                     '<tr><td class="x-btn-tl"><i>&#160;</i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i>&#160;</i></td></tr>',
316                     '<tr><td class="x-btn-ml"><i>&#160;</i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i>&#160;</i></td></tr>',
317                     '<tr><td class="x-btn-bl"><i>&#160;</i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i>&#160;</i></td></tr>',
318                     '</tbody></table>');
319                 Ext.Button.buttonTemplate.compile();
320             }
321             this.template = Ext.Button.buttonTemplate;
322         }
323
324         var btn, targs = this.getTemplateArgs();
325
326         if(position){
327             btn = this.template.insertBefore(position, targs, true);
328         }else{
329             btn = this.template.append(ct, targs, true);
330         }
331         /**
332          * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,
333          * this references a <tt>&lt;button&gt;</tt> element. Read only.
334          * @type Ext.Element
335          * @property btnEl
336          */
337         this.btnEl = btn.child(this.buttonSelector);
338         this.mon(this.btnEl, {
339             scope: this,
340             focus: this.onFocus,
341             blur: this.onBlur
342         });
343
344         this.initButtonEl(btn, this.btnEl);
345
346         Ext.ButtonToggleMgr.register(this);
347     },
348
349     // private
350     initButtonEl : function(btn, btnEl){
351         this.el = btn;
352         this.setIcon(this.icon);
353         this.setText(this.text);
354         this.setIconClass(this.iconCls);
355         if(Ext.isDefined(this.tabIndex)){
356             btnEl.dom.tabIndex = this.tabIndex;
357         }
358         if(this.tooltip){
359             this.setTooltip(this.tooltip, true);
360         }
361
362         if(this.handleMouseEvents){
363             this.mon(btn, {
364                 scope: this,
365                 mouseover: this.onMouseOver,
366                 mousedown: this.onMouseDown
367             });
368
369             // new functionality for monitoring on the document level
370             //this.mon(btn, 'mouseout', this.onMouseOut, this);
371         }
372
373         if(this.menu){
374             this.mon(this.menu, {
375                 scope: this,
376                 show: this.onMenuShow,
377                 hide: this.onMenuHide
378             });
379         }
380
381         if(this.repeat){
382             var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});
383             this.mon(repeater, 'click', this.onRepeatClick, this);
384         }else{
385             this.mon(btn, this.clickEvent, this.onClick, this);
386         }
387     },
388
389     // private
390     afterRender : function(){
391         Ext.Button.superclass.afterRender.call(this);
392         this.useSetClass = true;
393         this.setButtonClass();
394         this.doc = Ext.getDoc();
395         this.doAutoWidth();
396     },
397
398     /**
399      * Sets the CSS class that provides a background image to use as the button's icon.  This method also changes
400      * the value of the {@link iconCls} config internally.
401      * @param {String} cls The CSS class providing the icon image
402      * @return {Ext.Button} this
403      */
404     setIconClass : function(cls){
405         this.iconCls = cls;
406         if(this.el){
407             this.btnEl.dom.className = '';
408             this.btnEl.addClass(['x-btn-text', cls || '']);
409             this.setButtonClass();
410         }
411         return this;
412     },
413
414     /**
415      * Sets the tooltip for this Button.
416      * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
417      * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
418      * <li><b>Object</b> : A configuration object for {@link Ext.QuickTips#register}.</li>
419      * </ul></div>
420      * @return {Ext.Button} this
421      */
422     setTooltip : function(tooltip, /* private */ initial){
423         if(this.rendered){
424             if(!initial){
425                 this.clearTip();
426             }
427             if(Ext.isObject(tooltip)){
428                 Ext.QuickTips.register(Ext.apply({
429                       target: this.btnEl.id
430                 }, tooltip));
431                 this.tooltip = tooltip;
432             }else{
433                 this.btnEl.dom[this.tooltipType] = tooltip;
434             }
435         }else{
436             this.tooltip = tooltip;
437         }
438         return this;
439     },
440
441     // private
442     clearTip : function(){
443         if(Ext.isObject(this.tooltip)){
444             Ext.QuickTips.unregister(this.btnEl);
445         }
446     },
447
448     // private
449     beforeDestroy : function(){
450         if(this.rendered){
451             this.clearTip();
452         }
453         if(this.menu && this.destroyMenu !== false) {
454             Ext.destroy(this.btnEl, this.menu);
455         }
456         Ext.destroy(this.repeater);
457     },
458
459     // private
460     onDestroy : function(){
461         if(this.rendered){
462             this.doc.un('mouseover', this.monitorMouseOver, this);
463             this.doc.un('mouseup', this.onMouseUp, this);
464             delete this.doc;
465             delete this.btnEl;
466             Ext.ButtonToggleMgr.unregister(this);
467         }
468         Ext.Button.superclass.onDestroy.call(this);
469     },
470
471     // private
472     doAutoWidth : function(){
473         if(this.autoWidth !== false && this.el && this.text && this.width === undefined){
474             this.el.setWidth('auto');
475             if(Ext.isIE7 && Ext.isStrict){
476                 var ib = this.btnEl;
477                 if(ib && ib.getWidth() > 20){
478                     ib.clip();
479                     ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
480                 }
481             }
482             if(this.minWidth){
483                 if(this.el.getWidth() < this.minWidth){
484                     this.el.setWidth(this.minWidth);
485                 }
486             }
487         }
488     },
489
490     /**
491      * Assigns this Button's click handler
492      * @param {Function} handler The function to call when the button is clicked
493      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
494      * Defaults to this Button.
495      * @return {Ext.Button} this
496      */
497     setHandler : function(handler, scope){
498         this.handler = handler;
499         this.scope = scope;
500         return this;
501     },
502
503     /**
504      * Sets this Button's text
505      * @param {String} text The button text
506      * @return {Ext.Button} this
507      */
508     setText : function(text){
509         this.text = text;
510         if(this.el){
511             this.btnEl.update(text || '&#160;');
512             this.setButtonClass();
513         }
514         this.doAutoWidth();
515         return this;
516     },
517
518     /**
519      * Sets the background image (inline style) of the button.  This method also changes
520      * the value of the {@link icon} config internally.
521      * @param {String} icon The path to an image to display in the button
522      * @return {Ext.Button} this
523      */
524     setIcon : function(icon){
525         this.icon = icon;
526         if(this.el){
527             this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');
528             this.setButtonClass();
529         }
530         return this;
531     },
532
533     /**
534      * Gets the text for this Button
535      * @return {String} The button text
536      */
537     getText : function(){
538         return this.text;
539     },
540
541     /**
542      * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
543      * @param {Boolean} state (optional) Force a particular state
544      * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
545      * @return {Ext.Button} this
546      */
547     toggle : function(state, suppressEvent){
548         state = state === undefined ? !this.pressed : !!state;
549         if(state != this.pressed){
550             if(this.rendered){
551                 this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
552             }
553             this.pressed = state;
554             if(!suppressEvent){
555                 this.fireEvent('toggle', this, state);
556                 if(this.toggleHandler){
557                     this.toggleHandler.call(this.scope || this, this, state);
558                 }
559             }
560         }
561         return this;
562     },
563
564     // private
565     onDisable : function(){
566         this.onDisableChange(true);
567     },
568
569     // private
570     onEnable : function(){
571         this.onDisableChange(false);
572     },
573
574     onDisableChange : function(disabled){
575         if(this.el){
576             if(!Ext.isIE6 || !this.text){
577                 this.el[disabled ? 'addClass' : 'removeClass'](this.disabledClass);
578             }
579             this.el.dom.disabled = disabled;
580         }
581         this.disabled = disabled;
582     },
583
584     /**
585      * Show this button's menu (if it has one)
586      */
587     showMenu : function(){
588         if(this.rendered && this.menu){
589             if(this.tooltip){
590                 Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);
591             }
592             if(this.menu.isVisible()){
593                 this.menu.hide();
594             }
595             this.menu.ownerCt = this;
596             this.menu.show(this.el, this.menuAlign);
597         }
598         return this;
599     },
600
601     /**
602      * Hide this button's menu (if it has one)
603      */
604     hideMenu : function(){
605         if(this.hasVisibleMenu()){
606             this.menu.hide();
607         }
608         return this;
609     },
610
611     /**
612      * Returns true if the button has a menu and it is visible
613      * @return {Boolean}
614      */
615     hasVisibleMenu : function(){
616         return this.menu && this.menu.ownerCt == this && this.menu.isVisible();
617     },
618     
619     // private
620     onRepeatClick : function(repeat, e){
621         this.onClick(e);
622     },
623
624     // private
625     onClick : function(e){
626         if(e){
627             e.preventDefault();
628         }
629         if(e.button !== 0){
630             return;
631         }
632         if(!this.disabled){
633             this.doToggle();
634             if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){
635                 this.showMenu();
636             }
637             this.fireEvent('click', this, e);
638             if(this.handler){
639                 //this.el.removeClass('x-btn-over');
640                 this.handler.call(this.scope || this, this, e);
641             }
642         }
643     },
644     
645     // private
646     doToggle: function(){
647         if (this.enableToggle && (this.allowDepress !== false || !this.pressed)) {
648             this.toggle();
649         }
650     },
651
652     // private
653     isMenuTriggerOver : function(e, internal){
654         return this.menu && !internal;
655     },
656
657     // private
658     isMenuTriggerOut : function(e, internal){
659         return this.menu && !internal;
660     },
661
662     // private
663     onMouseOver : function(e){
664         if(!this.disabled){
665             var internal = e.within(this.el,  true);
666             if(!internal){
667                 this.el.addClass('x-btn-over');
668                 if(!this.monitoringMouseOver){
669                     this.doc.on('mouseover', this.monitorMouseOver, this);
670                     this.monitoringMouseOver = true;
671                 }
672                 this.fireEvent('mouseover', this, e);
673             }
674             if(this.isMenuTriggerOver(e, internal)){
675                 this.fireEvent('menutriggerover', this, this.menu, e);
676             }
677         }
678     },
679
680     // private
681     monitorMouseOver : function(e){
682         if(e.target != this.el.dom && !e.within(this.el)){
683             if(this.monitoringMouseOver){
684                 this.doc.un('mouseover', this.monitorMouseOver, this);
685                 this.monitoringMouseOver = false;
686             }
687             this.onMouseOut(e);
688         }
689     },
690
691     // private
692     onMouseOut : function(e){
693         var internal = e.within(this.el) && e.target != this.el.dom;
694         this.el.removeClass('x-btn-over');
695         this.fireEvent('mouseout', this, e);
696         if(this.isMenuTriggerOut(e, internal)){
697             this.fireEvent('menutriggerout', this, this.menu, e);
698         }
699     },
700
701     focus : function() {
702         this.btnEl.focus();
703     },
704
705     blur : function() {
706         this.btnEl.blur();
707     },
708
709     // private
710     onFocus : function(e){
711         if(!this.disabled){
712             this.el.addClass('x-btn-focus');
713         }
714     },
715     // private
716     onBlur : function(e){
717         this.el.removeClass('x-btn-focus');
718     },
719
720     // private
721     getClickEl : function(e, isUp){
722        return this.el;
723     },
724
725     // private
726     onMouseDown : function(e){
727         if(!this.disabled && e.button === 0){
728             this.getClickEl(e).addClass('x-btn-click');
729             this.doc.on('mouseup', this.onMouseUp, this);
730         }
731     },
732     // private
733     onMouseUp : function(e){
734         if(e.button === 0){
735             this.getClickEl(e, true).removeClass('x-btn-click');
736             this.doc.un('mouseup', this.onMouseUp, this);
737         }
738     },
739     // private
740     onMenuShow : function(e){
741         if(this.menu.ownerCt == this){
742             this.menu.ownerCt = this;
743             this.ignoreNextClick = 0;
744             this.el.addClass('x-btn-menu-active');
745             this.fireEvent('menushow', this, this.menu);
746         }
747     },
748     // private
749     onMenuHide : function(e){
750         if(this.menu.ownerCt == this){
751             this.el.removeClass('x-btn-menu-active');
752             this.ignoreNextClick = this.restoreClick.defer(250, this);
753             this.fireEvent('menuhide', this, this.menu);
754             delete this.menu.ownerCt;
755         }
756     },
757
758     // private
759     restoreClick : function(){
760         this.ignoreNextClick = 0;
761     }
762
763     /**
764      * @cfg {String} autoEl @hide
765      */
766     /**
767      * @cfg {String/Object} html @hide
768      */
769     /**
770      * @cfg {String} contentEl  @hide
771      */
772     /**
773      * @cfg {Mixed} data  @hide
774      */
775     /**
776      * @cfg {Mixed} tpl  @hide
777      */
778     /**
779      * @cfg {String} tplWriteMode  @hide
780      */
781 });
782 Ext.reg('button', Ext.Button);
783
784 // Private utility class used by Button
785 Ext.ButtonToggleMgr = function(){
786    var groups = {};
787
788    function toggleGroup(btn, state){
789        if(state){
790            var g = groups[btn.toggleGroup];
791            for(var i = 0, l = g.length; i < l; i++){
792                if(g[i] != btn){
793                    g[i].toggle(false);
794                }
795            }
796        }
797    }
798
799    return {
800        register : function(btn){
801            if(!btn.toggleGroup){
802                return;
803            }
804            var g = groups[btn.toggleGroup];
805            if(!g){
806                g = groups[btn.toggleGroup] = [];
807            }
808            g.push(btn);
809            btn.on('toggle', toggleGroup);
810        },
811
812        unregister : function(btn){
813            if(!btn.toggleGroup){
814                return;
815            }
816            var g = groups[btn.toggleGroup];
817            if(g){
818                g.remove(btn);
819                btn.un('toggle', toggleGroup);
820            }
821        },
822
823        /**
824         * Gets the pressed button in the passed group or null
825         * @param {String} group
826         * @return Button
827         */
828        getPressed : function(group){
829            var g = groups[group];
830            if(g){
831                for(var i = 0, len = g.length; i < len; i++){
832                    if(g[i].pressed === true){
833                        return g[i];
834                    }
835                }
836            }
837            return null;
838        }
839    };
840 }();