2 * @class Ext.button.Button
3 * @extends Ext.Component
5 Create simple buttons with this component. Customisations include {@link #config-iconAlign aligned}
6 {@link #config-iconCls icons}, {@link #config-menu dropdown menus}, {@link #config-tooltip tooltips}
7 and {@link #config-scale sizing options}. Specify a {@link #config-handler handler} to run code when
8 a user clicks the button, or use {@link #config-listeners listeners} for other events such as
9 {@link #events-mouseover mouseover}.
11 {@img Ext.button.Button/Ext.button.Button1.png Ext.button.Button component}
14 Ext.create('Ext.Button', {
16 renderTo: Ext.getBody(),
18 alert('You clicked the button!')
22 The {@link #handler} configuration can also be updated dynamically using the {@link #setHandler} method.
25 Ext.create('Ext.Button', {
26 text : 'Dyanmic Handler Button',
27 renderTo: Ext.getBody(),
28 handler : function() {
29 //this button will spit out a different number every time you click it.
30 //so firstly we must check if that number is already set:
31 if (this.clickCount) {
32 //looks like the property is already set, so lets just add 1 to that number and alert the user
34 alert('You have clicked the button "' + this.clickCount + '" times.\n\nTry clicking it again..');
36 //if the clickCount property is not set, we will set it and alert the user
38 alert('You just clicked the button for the first time!\n\nTry pressing it again..');
43 A button within a container:
45 Ext.create('Ext.Container', {
46 renderTo: Ext.getBody(),
55 A useful option of Button is the {@link #scale} configuration. This configuration has three different options:
60 {@img Ext.button.Button/Ext.button.Button2.png Ext.button.Button component}
63 Ext.create('Ext.Button', {
64 renderTo: document.body,
69 Buttons can also be toggled. To enable this, you simple set the {@link #enableToggle} property to `true`.
70 {@img Ext.button.Button/Ext.button.Button3.png Ext.button.Button component}
73 Ext.create('Ext.Button', {
74 renderTo: Ext.getBody(),
79 You can assign a menu to a button by using the {@link #menu} configuration. This standard configuration can either be a reference to a {@link Ext.menu.Menu menu}
80 object, a {@link Ext.menu.Menu menu} id or a {@link Ext.menu.Menu menu} config blob. When assigning a menu to a button, an arrow is automatically added to the button.
81 You can change the alignment of the arrow using the {@link #arrowAlign} configuration on button.
82 {@img Ext.button.Button/Ext.button.Button4.png Ext.button.Button component}
85 Ext.create('Ext.Button', {
87 renderTo : Ext.getBody(),
97 Using listeners, you can easily listen to events fired by any component, using the {@link #listeners} configuration or using the {@link #addListener} method.
98 Button has a variety of different listeners:
110 Ext.create('Ext.Button', {
112 renderTo : Ext.getBody(),
115 //this == the button, as we are in the local scope
116 this.setText('I was clicked!');
118 mouseover: function() {
119 //set a new config which says we moused over, if not already set
120 if (!this.mousedOver) {
121 this.mousedOver = true;
122 alert('You moused over a button!\n\nI wont do this again.');
129 * Create a new button
130 * @param {Object} config The config object
133 * @docauthor Robert Dougan <rob@sencha.com>
135 Ext.define('Ext.button.Button', {
137 /* Begin Definitions */
138 alias: 'widget.button',
139 extend: 'Ext.Component',
143 'Ext.util.ClickRepeater',
144 'Ext.layout.component.Button',
145 'Ext.util.TextMetrics',
149 alternateClassName: 'Ext.Button',
150 /* End Definitions */
153 componentLayout: 'button',
156 * Read-only. True if this button is hidden
162 * Read-only. True if this button is disabled
168 * Read-only. True if this button is pressed (only if enableToggle = true)
174 * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
178 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
179 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
183 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
184 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
185 * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
186 * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
191 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
192 * See also {@link Ext.panel.Panel}.<tt>{@link Ext.panel.Panel#minButtonWidth minButtonWidth}</tt>.
196 * @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
200 * @cfg {Boolean} hidden True to start hidden (defaults to false)
204 * @cfg {Boolean} disabled True to start disabled (defaults to false)
208 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
212 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
216 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
217 * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
221 * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
225 * @cfg {Boolean} allowDepress
226 * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
230 * @cfg {Boolean} enableToggle
231 * True to enable pressed/not pressed toggling (defaults to false)
236 * @cfg {Function} toggleHandler
237 * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
238 * <li><b>button</b> : Ext.button.Button<div class="sub-desc">this Button object</div></li>
239 * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
245 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
249 * @cfg {String} menuAlign
250 * The position to align the menu to (see {@link Ext.core.Element#alignTo} for more details, defaults to 'tl-bl?').
255 * @cfg {String} overflowText If used in a {@link Ext.toolbar.Toolbar Toolbar}, the
256 * text to be used if this item is shown in the overflow menu. See also
257 * {@link Ext.toolbar.Item}.<code>{@link Ext.toolbar.Item#overflowText overflowText}</code>.
261 * @cfg {String} iconCls
262 * A css class which sets a background image to be used as the icon for this button
267 * submit, reset or button - defaults to 'button'
272 * @cfg {String} clickEvent
273 * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
274 * Defaults to <tt>'click'</tt>.
279 * @cfg {Boolean} preventDefault
280 * True to prevent the default action when the {@link #clickEvent} is processed. Defaults to true.
282 preventDefault: true,
285 * @cfg {Boolean} handleMouseEvents
286 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
288 handleMouseEvents: true,
291 * @cfg {String} tooltipType
292 * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
297 * @cfg {String} baseCls
298 * The base CSS class to add to all buttons. (Defaults to 'x-btn')
300 baseCls: Ext.baseCSSPrefix + 'btn',
303 * @cfg {String} pressedCls
304 * The CSS class to add to a button when it is in the pressed state. (Defaults to 'x-btn-pressed')
306 pressedCls: 'pressed',
309 * @cfg {String} overCls
310 * The CSS class to add to a button when it is in the over (hovered) state. (Defaults to 'x-btn-over')
315 * @cfg {String} focusCls
316 * The CSS class to add to a button when it is in the focussed state. (Defaults to 'x-btn-focus')
321 * @cfg {String} menuActiveCls
322 * The CSS class to add to a button when it's menu is active. (Defaults to 'x-btn-menu-active')
324 menuActiveCls: 'menu-active',
327 * @cfg {Object} baseParams
328 * An object literal of parameters to pass to the url when the {@link #href} property is specified.
332 * @cfg {Object} params
333 * An object literal of parameters to pass to the url when the {@link #href} property is specified.
334 * Any params override {@link #baseParams}. New params can be set using the {@link #setParams} method.
341 '<em class="{splitCls}">' +
343 '<a href="{href}" target="{target}"<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="link">' +
344 '<span class="{baseCls}-inner">{text}</span>' +
348 '<button type="{type}" hidefocus="true"' +
349 // the autocomplete="off" is required to prevent Firefox from remembering
350 // the button's disabled state between page reloads.
351 '<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="button" autocomplete="off">' +
352 '<span class="{baseCls}-inner" style="{innerSpanStyle}">{text}</span>' +
358 * @cfg {String} scale
359 * <p>(Optional) The size of the Button. Three values are allowed:</p>
360 * <ul class="mdetail-params">
361 * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
362 * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
363 * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
365 * <p>Defaults to <b><tt>'small'</tt></b>.</p>
370 * @private An array of allowed scales.
372 allowedScales: ['small', 'medium', 'large'],
375 * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
376 * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
377 * executed. Defaults to this Button.
381 * @cfg {String} iconAlign
382 * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
383 * <ul class="mdetail-params">
384 * <li>'top'<div class="sub-desc"></div></li>
385 * <li>'right'<div class="sub-desc"></div></li>
386 * <li>'bottom'<div class="sub-desc"></div></li>
387 * <li>'left'<div class="sub-desc"></div></li>
389 * <p>Defaults to <b><tt>'left'</tt></b>.</p>
394 * @cfg {String} arrowAlign
395 * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
396 * Two values are allowed:</p>
397 * <ul class="mdetail-params">
398 * <li>'right'<div class="sub-desc"></div></li>
399 * <li>'bottom'<div class="sub-desc"></div></li>
401 * <p>Defaults to <b><tt>'right'</tt></b>.</p>
406 * @cfg {String} arrowCls
407 * <p>(Optional) The className used for the inner arrow element if the button has a menu.</p>
412 * @cfg {Ext.Template} template (Optional)
413 * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
414 * Instances, or subclasses which need a different DOM structure may provide a different
415 * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
422 * A CSS class string to apply to the button's main element.
428 * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
432 * @cfg {Boolean} autoWidth
433 * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
434 * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
435 * the button from doing this automatic sizing.
436 * Defaults to <tt>undefined</tt>.
439 maskOnDisable: false,
442 initComponent: function() {
444 me.callParent(arguments);
449 * Fires when this button is clicked
450 * @param {Button} this
451 * @param {EventObject} e The click event
457 * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
458 * @param {Button} this
459 * @param {Boolean} pressed
465 * Fires when the mouse hovers over the button
466 * @param {Button} this
467 * @param {Event} e The event object
473 * Fires when the mouse exits the button
474 * @param {Button} this
475 * @param {Event} e The event object
481 * If this button has a menu, this event fires when it is shown
482 * @param {Button} this
489 * If this button has a menu, this event fires when it is hidden
490 * @param {Button} this
496 * @event menutriggerover
497 * If this button has a menu, this event fires when the mouse enters the menu triggering element
498 * @param {Button} this
500 * @param {EventObject} e
505 * @event menutriggerout
506 * If this button has a menu, this event fires when the mouse leaves the menu triggering element
507 * @param {Button} this
509 * @param {EventObject} e
515 // Flag that we'll have a splitCls
518 // retrieve menu by id or instantiate instance if needed
519 me.menu = Ext.menu.Manager.get(me.menu);
520 me.menu.ownerCt = me;
523 // Accept url as a synonym for href
528 // preventDefault defaults to false for links
529 if (me.href && !me.hasOwnProperty('preventDefault')) {
530 me.preventDefault = false;
533 if (Ext.isString(me.toggleGroup)) {
534 me.enableToggle = true;
540 initAria: function() {
542 var actionEl = this.getActionEl();
544 actionEl.dom.setAttribute('aria-haspopup', true);
549 getActionEl: function() {
554 getFocusEl: function() {
559 setButtonCls: function() {
564 if (me.useSetClass) {
565 if (!Ext.isEmpty(me.oldCls)) {
566 me.removeClsWithUI(me.oldCls);
567 me.removeClsWithUI(me.pressedCls);
570 // Check whether the button has an icon or not, and if it has an icon, what is th alignment
571 if (me.iconCls || me.icon) {
573 cls.push('icon-text-' + me.iconAlign);
577 } else if (me.text) {
582 me.addClsWithUI(cls);
583 me.addClsWithUI(me.pressed ? me.pressedCls : null);
588 onRender: function(ct, position) {
589 // classNames for the button
593 // Apply the renderData to the template args
594 Ext.applyIf(me.renderData, me.getTemplateArgs());
596 // Extract the button and the button wrapping element
597 Ext.applyIf(me.renderSelectors, {
598 btnEl : me.href ? 'a' : 'button',
600 btnInnerEl: '.' + me.baseCls + '-inner'
604 me.ui = me.ui + '-' + me.scale;
607 // Render internal structure
608 me.callParent(arguments);
610 // If it is a split button + has a toolip for the arrow
611 if (me.split && me.arrowTooltip) {
612 me.arrowEl.dom[me.tooltipType] = me.arrowTooltip;
615 // Add listeners to the focus and blur events on the element
622 // Set btn as a local variable for easy access
630 me.setIconCls(me.iconCls);
634 me.setTooltip(me.tooltip, true);
637 // Add the mouse events to the button
638 if (me.handleMouseEvents) {
641 mouseover: me.onMouseOver,
642 mouseout: me.onMouseOut,
643 mousedown: me.onMouseDown
648 mousemove: me.onMouseMove,
654 // Check if the button has a menu
662 me.keyMap = Ext.create('Ext.util.KeyMap', me.el, {
663 key: Ext.EventObject.DOWN,
664 handler: me.onDownKey,
669 // Check if it is a repeat button
671 repeater = Ext.create('Ext.util.ClickRepeater', btn, Ext.isObject(me.repeat) ? me.repeat: {});
672 me.mon(repeater, 'click', me.onRepeatClick, me);
674 me.mon(btn, me.clickEvent, me.onClick, me);
677 // Register the button in the toggle manager
678 Ext.ButtonToggleManager.register(me);
682 * <p>This method returns an object which provides substitution parameters for the {@link #renderTpl XTemplate} used
683 * to create this Button's DOM structure.</p>
684 * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
685 * own implementation of this method.</p>
686 * <p>The default implementation which provides data for the default {@link #template} returns an Object containing the
687 * following properties:</p><div class="mdetail-params"><ul>
688 * <li><code>type</code> : The <button>'s {@link #type}</li>
689 * <li><code>splitCls</code> : 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>
690 * <li><code>cls</code> : A CSS class name applied to the Button's main <tbody> element which determines the button's scale and icon alignment.</li>
691 * <li><code>text</code> : The {@link #text} to display ion the Button.</li>
692 * <li><code>tabIndex</code> : The tab index within the input flow.</li>
694 * @return {Array} Substitution data for a Template.
696 getTemplateArgs: function() {
698 persistentPadding = me.getPersistentBtnPadding(),
701 // Create negative margin offsets to counteract persistent button padding if needed
702 if (Math.max.apply(Math, persistentPadding) > 0) {
703 innerSpanStyle = 'margin:' + Ext.Array.map(persistentPadding, function(pad) {
710 target : me.target || '_blank',
712 splitCls : me.getSplitCls(),
714 text : me.text || ' ',
715 tabIndex : me.tabIndex,
716 innerSpanStyle: innerSpanStyle
722 * If there is a configured href for this Button, returns the href with parameters appended.
723 * @returns The href string with parameters appended.
725 getHref: function() {
727 params = Ext.apply({}, me.baseParams);
729 // write baseParams first, then write any params
730 params = Ext.apply(params, me.params);
731 return me.href ? Ext.urlAppend(me.href, Ext.Object.toQueryString(params)) : false;
735 * <p><b>Only valid if the Button was originally configured with a {@link #url}</b></p>
736 * <p>Sets the href of the link dynamically according to the params passed, and any {@link #baseParams} configured.</p>
737 * @param {Object} params Parameters to use in the href URL.
739 setParams: function(params) {
740 this.params = params;
741 this.btnEl.dom.href = this.getHref();
744 getSplitCls: function() {
746 return me.split ? (me.baseCls + '-' + me.arrowCls) + ' ' + (me.baseCls + '-' + me.arrowCls + '-' + me.arrowAlign) : '';
750 afterRender: function() {
752 me.useSetClass = true;
754 me.doc = Ext.getDoc();
755 this.callParent(arguments);
759 * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
760 * the value of the {@link #iconCls} config internally.
761 * @param {String} cls The CSS class providing the icon image
762 * @return {Ext.button.Button} this
764 setIconCls: function(cls) {
766 btnInnerEl = me.btnInnerEl;
768 // Remove the previous iconCls from the button
769 btnInnerEl.removeCls(me.iconCls);
770 btnInnerEl.addCls(cls || '');
778 * Sets the tooltip for this Button.
779 * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
780 * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
781 * <li><b>Object</b> : A configuration object for {@link Ext.tip.QuickTipManager#register}.</li>
783 * @return {Ext.button.Button} this
785 setTooltip: function(tooltip, initial) {
792 if (Ext.isObject(tooltip)) {
793 Ext.tip.QuickTipManager.register(Ext.apply({
797 me.tooltip = tooltip;
799 me.btnEl.dom.setAttribute('data-' + this.tooltipType, tooltip);
802 me.tooltip = tooltip;
808 getRefItems: function(deep){
809 var menu = this.menu,
813 items = menu.getRefItems(deep);
820 clearTip: function() {
821 if (Ext.isObject(this.tooltip)) {
822 Ext.tip.QuickTipManager.unregister(this.btnEl);
827 beforeDestroy: function() {
832 if (me.menu && me.destroyMenu !== false) {
833 Ext.destroy(me.btnEl, me.btnInnerEl, me.menu);
835 Ext.destroy(me.repeater);
839 onDestroy: function() {
842 me.doc.un('mouseover', me.monitorMouseOver, me);
843 me.doc.un('mouseup', me.onMouseUp, me);
846 delete me.btnInnerEl;
847 Ext.ButtonToggleManager.unregister(me);
849 Ext.destroy(me.keyMap);
856 * Assigns this Button's click handler
857 * @param {Function} handler The function to call when the button is clicked
858 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
859 * Defaults to this Button.
860 * @return {Ext.button.Button} this
862 setHandler: function(handler, scope) {
863 this.handler = handler;
869 * Sets this Button's text
870 * @param {String} text The button text
871 * @return {Ext.button.Button} this
873 setText: function(text) {
877 me.btnInnerEl.update(text || ' ');
880 me.doComponentLayout();
885 * Sets the background image (inline style) of the button. This method also changes
886 * the value of the {@link #icon} config internally.
887 * @param {String} icon The path to an image to display in the button
888 * @return {Ext.button.Button} this
890 setIcon: function(icon) {
892 btnInnerEl = me.btnInnerEl;
895 btnInnerEl.setStyle('background-image', icon ? 'url(' + icon + ')': '');
902 * Gets the text for this Button
903 * @return {String} The button text
905 getText: function() {
910 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
911 * @param {Boolean} state (optional) Force a particular state
912 * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
913 * @return {Ext.button.Button} this
915 toggle: function(state, suppressEvent) {
917 state = state === undefined ? !me.pressed: !!state;
918 if (state !== me.pressed) {
920 me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls);
922 me.btnEl.dom.setAttribute('aria-pressed', state);
924 if (!suppressEvent) {
925 me.fireEvent('toggle', me, state);
926 Ext.callback(me.toggleHandler, me.scope || me, [me, state]);
933 * Show this button's menu (if it has one)
935 showMenu: function() {
937 if (me.rendered && me.menu) {
939 Ext.tip.QuickTipManager.getQuickTip().cancelShow(me.btnEl);
941 if (me.menu.isVisible()) {
945 me.menu.showBy(me.el, me.menuAlign);
951 * Hide this button's menu (if it has one)
953 hideMenu: function() {
954 if (this.hasVisibleMenu()) {
961 * Returns true if the button has a menu and it is visible
964 hasVisibleMenu: function() {
965 var menu = this.menu;
966 return menu && menu.rendered && menu.isVisible();
970 onRepeatClick: function(repeat, e) {
975 onClick: function(e) {
977 if (me.preventDefault || (me.disabled && me.getHref()) && e) {
980 if (e.button !== 0) {
984 if (me.enableToggle && (me.allowDepress !== false || !me.pressed)) {
987 if (me.menu && !me.hasVisibleMenu() && !me.ignoreNextClick) {
990 me.fireEvent('click', me, e);
992 me.handler.call(me.scope || me, me, e);
999 * @private mouseover handler called when a mouseover event occurs anywhere within the encapsulating element.
1000 * The targets are interrogated to see what is being entered from where.
1003 onMouseOver: function(e) {
1005 if (!me.disabled && !e.within(me.el, true, true)) {
1011 * @private mouseout handler called when a mouseout event occurs anywhere within the encapsulating element -
1012 * or the mouse leaves the encapsulating element.
1013 * The targets are interrogated to see what is being exited to where.
1016 onMouseOut: function(e) {
1018 if (!e.within(me.el, true, true)) {
1019 if (me.overMenuTrigger) {
1020 me.onMenuTriggerOut(e);
1027 * @private mousemove handler called when the mouse moves anywhere within the encapsulating element.
1028 * The position is checked to determine if the mouse is entering or leaving the trigger area. Using
1029 * mousemove to check this is more resource intensive than we'd like, but it is necessary because
1030 * the trigger area does not line up exactly with sub-elements so we don't always get mouseover/out
1031 * events when needed. In the future we should consider making the trigger a separate element that
1032 * is absolutely positioned and sized over the trigger area.
1034 onMouseMove: function(e) {
1037 over = me.overMenuTrigger,
1041 if (me.arrowAlign === 'right') {
1042 overlap = e.getX() - el.getX();
1043 btnSize = el.getWidth();
1045 overlap = e.getY() - el.getY();
1046 btnSize = el.getHeight();
1049 if (overlap > (btnSize - me.getTriggerSize())) {
1051 me.onMenuTriggerOver(e);
1055 me.onMenuTriggerOut(e);
1062 * @private Measures the size of the trigger area for menu and split buttons. Will be a width for
1063 * a right-aligned trigger and a height for a bottom-aligned trigger. Cached after first measurement.
1065 getTriggerSize: function() {
1067 size = me.triggerSize,
1068 side, sideFirstLetter, undef;
1070 if (size === undef) {
1071 side = me.arrowAlign;
1072 sideFirstLetter = side.charAt(0);
1073 size = me.triggerSize = me.el.getFrameWidth(sideFirstLetter) + me.btnWrap.getFrameWidth(sideFirstLetter) + (me.frameSize && me.frameSize[side] || 0);
1079 * @private virtual mouseenter handler called when it is detected that the mouseout event
1080 * signified the mouse entering the encapsulating element.
1083 onMouseEnter: function(e) {
1085 me.addClsWithUI(me.overCls);
1086 me.fireEvent('mouseover', me, e);
1090 * @private virtual mouseleave handler called when it is detected that the mouseover event
1091 * signified the mouse entering the encapsulating element.
1094 onMouseLeave: function(e) {
1096 me.removeClsWithUI(me.overCls);
1097 me.fireEvent('mouseout', me, e);
1101 * @private virtual mouseenter handler called when it is detected that the mouseover event
1102 * signified the mouse entering the arrow area of the button - the <em>.
1105 onMenuTriggerOver: function(e) {
1107 me.overMenuTrigger = true;
1108 me.fireEvent('menutriggerover', me, me.menu, e);
1112 * @private virtual mouseleave handler called when it is detected that the mouseout event
1113 * signified the mouse leaving the arrow area of the button - the <em>.
1116 onMenuTriggerOut: function(e) {
1118 delete me.overMenuTrigger;
1119 me.fireEvent('menutriggerout', me, me.menu, e);
1123 enable : function(silent) {
1126 me.callParent(arguments);
1128 me.removeClsWithUI('disabled');
1134 disable : function(silent) {
1137 me.callParent(arguments);
1139 me.addClsWithUI('disabled');
1145 * Method to change the scale of the button. See {@link #scale} for allowed configurations.
1146 * @param {String} scale The scale to change to.
1148 setScale: function(scale) {
1150 ui = me.ui.replace('-' + me.scale, '');
1152 //check if it is an allowed scale
1153 if (!Ext.Array.contains(me.allowedScales, scale)) {
1154 throw('#setScale: scale must be an allowed scale (' + me.allowedScales.join(', ') + ')');
1162 setUI: function(ui) {
1165 //we need to append the scale to the UI, if not already done
1166 if (me.scale && !ui.match(me.scale)) {
1167 ui = ui + '-' + me.scale;
1170 me.callParent([ui]);
1172 // Set all the state classNames, as they need to include the UI
1173 // me.disabledCls += ' ' + me.baseCls + '-' + me.ui + '-disabled';
1177 onFocus: function(e) {
1180 me.addClsWithUI(me.focusCls);
1185 onBlur: function(e) {
1187 me.removeClsWithUI(me.focusCls);
1191 onMouseDown: function(e) {
1193 if (!me.disabled && e.button === 0) {
1194 me.addClsWithUI(me.pressedCls);
1195 me.doc.on('mouseup', me.onMouseUp, me);
1199 onMouseUp: function(e) {
1201 if (e.button === 0) {
1203 me.removeClsWithUI(me.pressedCls);
1205 me.doc.un('mouseup', me.onMouseUp, me);
1209 onMenuShow: function(e) {
1211 me.ignoreNextClick = 0;
1212 me.addClsWithUI(me.menuActiveCls);
1213 me.fireEvent('menushow', me, me.menu);
1217 onMenuHide: function(e) {
1219 me.removeClsWithUI(me.menuActiveCls);
1220 me.ignoreNextClick = Ext.defer(me.restoreClick, 250, me);
1221 me.fireEvent('menuhide', me, me.menu);
1225 restoreClick: function() {
1226 this.ignoreNextClick = 0;
1230 onDownKey: function() {
1241 * @private Some browsers (notably Safari and older Chromes on Windows) add extra "padding" inside the button
1242 * element that cannot be removed. This method returns the size of that padding with a one-time detection.
1243 * @return Array [top, right, bottom, left]
1245 getPersistentBtnPadding: function() {
1246 var cls = Ext.button.Button,
1247 padding = cls.persistentPadding,
1248 btn, leftTop, btnEl, btnInnerEl;
1251 padding = cls.persistentPadding = [0, 0, 0, 0]; //set early to prevent recursion
1253 if (!Ext.isIE) { //short-circuit IE as it sometimes gives false positive for padding
1254 // Create auto-size button offscreen and measure its insides
1255 btn = Ext.create('Ext.button.Button', {
1256 renderTo: Ext.getBody(),
1258 style: 'position:absolute;top:-999px;'
1261 btnInnerEl = btn.btnInnerEl;
1262 btnEl.setSize(null, null); //clear any hard dimensions on the button el to see what it does naturally
1264 leftTop = btnInnerEl.getOffsetsTo(btnEl);
1265 padding[0] = leftTop[1];
1266 padding[1] = btnEl.getWidth() - btnInnerEl.getWidth() - leftTop[0];
1267 padding[2] = btnEl.getHeight() - btnInnerEl.getHeight() - leftTop[1];
1268 padding[3] = leftTop[0];
1281 function toggleGroup(btn, state) {
1283 g = groups[btn.toggleGroup];
1284 for (i = 0, l = g.length; i < l; i++) {
1291 // Private utility class used by Button
1292 Ext.ButtonToggleManager = {
1293 register: function(btn) {
1294 if (!btn.toggleGroup) {
1297 var group = groups[btn.toggleGroup];
1299 group = groups[btn.toggleGroup] = [];
1302 btn.on('toggle', toggleGroup);
1305 unregister: function(btn) {
1306 if (!btn.toggleGroup) {
1309 var group = groups[btn.toggleGroup];
1311 Ext.Array.remove(group, btn);
1312 btn.un('toggle', toggleGroup);
1317 * Gets the pressed button in the passed group or null
1318 * @param {String} group
1321 getPressed: function(group) {
1322 var g = groups[group],
1326 for (len = g.length; i < len; i++) {
1327 if (g[i].pressed === true) {