4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-button-Button'>/**
19 </span> * @class Ext.button.Button
20 * @extends Ext.Component
22 Create simple buttons with this component. Customisations include {@link #iconAlign aligned}
23 {@link #iconCls icons}, {@link #menu dropdown menus}, {@link #tooltip tooltips}
24 and {@link #scale sizing options}. Specify a {@link #handler handler} to run code when
25 a user clicks the button, or use {@link #listeners listeners} for other events such as
26 {@link #mouseover mouseover}.
28 {@img Ext.button.Button/Ext.button.Button1.png Ext.button.Button component}
31 Ext.create('Ext.Button', {
33 renderTo: Ext.getBody(),
35 alert('You clicked the button!')
39 The {@link #handler} configuration can also be updated dynamically using the {@link #setHandler} method.
42 Ext.create('Ext.Button', {
43 text : 'Dyanmic Handler Button',
44 renderTo: Ext.getBody(),
45 handler : function() {
46 //this button will spit out a different number every time you click it.
47 //so firstly we must check if that number is already set:
48 if (this.clickCount) {
49 //looks like the property is already set, so lets just add 1 to that number and alert the user
51 alert('You have clicked the button "' + this.clickCount + '" times.\n\nTry clicking it again..');
53 //if the clickCount property is not set, we will set it and alert the user
55 alert('You just clicked the button for the first time!\n\nTry pressing it again..');
60 A button within a container:
62 Ext.create('Ext.Container', {
63 renderTo: Ext.getBody(),
72 A useful option of Button is the {@link #scale} configuration. This configuration has three different options:
77 {@img Ext.button.Button/Ext.button.Button2.png Ext.button.Button component}
80 Ext.create('Ext.Button', {
81 renderTo: document.body,
86 Buttons can also be toggled. To enable this, you simple set the {@link #enableToggle} property to `true`.
87 {@img Ext.button.Button/Ext.button.Button3.png Ext.button.Button component}
90 Ext.create('Ext.Button', {
91 renderTo: Ext.getBody(),
96 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}
97 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.
98 You can change the alignment of the arrow using the {@link #arrowAlign} configuration on button.
99 {@img Ext.button.Button/Ext.button.Button4.png Ext.button.Button component}
102 Ext.create('Ext.Button', {
103 text : 'Menu button',
104 renderTo : Ext.getBody(),
105 arrowAlign: 'bottom',
114 Using listeners, you can easily listen to events fired by any component, using the {@link #listeners} configuration or using the {@link #addListener} method.
115 Button has a variety of different listeners:
127 Ext.create('Ext.Button', {
129 renderTo : Ext.getBody(),
132 //this == the button, as we are in the local scope
133 this.setText('I was clicked!');
135 mouseover: function() {
136 //set a new config which says we moused over, if not already set
137 if (!this.mousedOver) {
138 this.mousedOver = true;
139 alert('You moused over a button!\n\nI wont do this again.');
146 * @docauthor Robert Dougan <rob@sencha.com>
148 Ext.define('Ext.button.Button', {
150 /* Begin Definitions */
151 alias: 'widget.button',
152 extend: 'Ext.Component',
156 'Ext.util.ClickRepeater',
157 'Ext.layout.component.Button',
158 'Ext.util.TextMetrics',
162 alternateClassName: 'Ext.Button',
163 /* End Definitions */
166 componentLayout: 'button',
168 <span id='Ext-button-Button-property-hidden'> /**
169 </span> * Read-only. True if this button is hidden
174 <span id='Ext-button-Button-property-disabled'> /**
175 </span> * Read-only. True if this button is disabled
180 <span id='Ext-button-Button-property-pressed'> /**
181 </span> * Read-only. True if this button is pressed (only if enableToggle = true)
186 <span id='Ext-button-Button-cfg-text'> /**
187 </span> * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
190 <span id='Ext-button-Button-cfg-icon'> /**
191 </span> * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
192 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
195 <span id='Ext-button-Button-cfg-handler'> /**
196 </span> * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
197 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
198 * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
199 * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
200 * </ul></div>
203 <span id='Ext-button-Button-cfg-minWidth'> /**
204 </span> * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
205 * See also {@link Ext.panel.Panel}.<tt>{@link Ext.panel.Panel#minButtonWidth minButtonWidth}</tt>.
208 <span id='Ext-button-Button-cfg-tooltip'> /**
209 </span> * @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
212 <span id='Ext-button-Button-cfg-hidden'> /**
213 </span> * @cfg {Boolean} hidden True to start hidden (defaults to false)
216 <span id='Ext-button-Button-cfg-disabled'> /**
217 </span> * @cfg {Boolean} disabled True to start disabled (defaults to false)
220 <span id='Ext-button-Button-cfg-pressed'> /**
221 </span> * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
224 <span id='Ext-button-Button-cfg-toggleGroup'> /**
225 </span> * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
228 <span id='Ext-button-Button-cfg-repeat'> /**
229 </span> * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
230 * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
233 <span id='Ext-button-Button-cfg-tabIndex'> /**
234 </span> * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
237 <span id='Ext-button-Button-cfg-allowDepress'> /**
238 </span> * @cfg {Boolean} allowDepress
239 * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
242 <span id='Ext-button-Button-cfg-enableToggle'> /**
243 </span> * @cfg {Boolean} enableToggle
244 * True to enable pressed/not pressed toggling (defaults to false)
248 <span id='Ext-button-Button-cfg-toggleHandler'> /**
249 </span> * @cfg {Function} toggleHandler
250 * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
251 * <li><b>button</b> : Ext.button.Button<div class="sub-desc">this Button object</div></li>
252 * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
256 <span id='Ext-button-Button-cfg-menu'> /**
257 </span> * @cfg {Mixed} menu
258 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
261 <span id='Ext-button-Button-cfg-menuAlign'> /**
262 </span> * @cfg {String} menuAlign
263 * The position to align the menu to (see {@link Ext.core.Element#alignTo} for more details, defaults to 'tl-bl?').
267 <span id='Ext-button-Button-cfg-overflowText'> /**
268 </span> * @cfg {String} overflowText If used in a {@link Ext.toolbar.Toolbar Toolbar}, the
269 * text to be used if this item is shown in the overflow menu. See also
270 * {@link Ext.toolbar.Item}.<code>{@link Ext.toolbar.Item#overflowText overflowText}</code>.
273 <span id='Ext-button-Button-cfg-iconCls'> /**
274 </span> * @cfg {String} iconCls
275 * A css class which sets a background image to be used as the icon for this button
278 <span id='Ext-button-Button-cfg-type'> /**
279 </span> * @cfg {String} type
280 * submit, reset or button - defaults to 'button'
284 <span id='Ext-button-Button-cfg-clickEvent'> /**
285 </span> * @cfg {String} clickEvent
286 * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
287 * Defaults to <tt>'click'</tt>.
291 <span id='Ext-button-Button-cfg-preventDefault'> /**
292 </span> * @cfg {Boolean} preventDefault
293 * True to prevent the default action when the {@link #clickEvent} is processed. Defaults to true.
295 preventDefault: true,
297 <span id='Ext-button-Button-cfg-handleMouseEvents'> /**
298 </span> * @cfg {Boolean} handleMouseEvents
299 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
301 handleMouseEvents: true,
303 <span id='Ext-button-Button-cfg-tooltipType'> /**
304 </span> * @cfg {String} tooltipType
305 * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
309 <span id='Ext-button-Button-cfg-baseCls'> /**
310 </span> * @cfg {String} baseCls
311 * The base CSS class to add to all buttons. (Defaults to 'x-btn')
313 baseCls: Ext.baseCSSPrefix + 'btn',
315 <span id='Ext-button-Button-cfg-pressedCls'> /**
316 </span> * @cfg {String} pressedCls
317 * The CSS class to add to a button when it is in the pressed state. (Defaults to 'x-btn-pressed')
319 pressedCls: 'pressed',
321 <span id='Ext-button-Button-cfg-overCls'> /**
322 </span> * @cfg {String} overCls
323 * The CSS class to add to a button when it is in the over (hovered) state. (Defaults to 'x-btn-over')
327 <span id='Ext-button-Button-cfg-focusCls'> /**
328 </span> * @cfg {String} focusCls
329 * The CSS class to add to a button when it is in the focussed state. (Defaults to 'x-btn-focus')
333 <span id='Ext-button-Button-cfg-menuActiveCls'> /**
334 </span> * @cfg {String} menuActiveCls
335 * The CSS class to add to a button when it's menu is active. (Defaults to 'x-btn-menu-active')
337 menuActiveCls: 'menu-active',
339 <span id='Ext-button-Button-cfg-baseParams'> /**
340 </span> * @cfg {Object} baseParams
341 * An object literal of parameters to pass to the url when the {@link #href} property is specified.
344 <span id='Ext-button-Button-cfg-params'> /**
345 </span> * @cfg {Object} params
346 * An object literal of parameters to pass to the url when the {@link #href} property is specified.
347 * Any params override {@link #baseParams}. New params can be set using the {@link #setParams} method.
354 '<em class="{splitCls}">' +
355 '<tpl if="href">' +
356 '<a href="{href}" target="{target}"<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="link">' +
357 '<span class="{baseCls}-inner">' +
360 '<span class="{baseCls}-icon"></span>' +
363 '<tpl if="!href">' +
364 '<button type="{type}" hidefocus="true"' +
365 // the autocomplete="off" is required to prevent Firefox from remembering
366 // the button's disabled state between page reloads.
367 '<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="button" autocomplete="off">' +
368 '<span class="{baseCls}-inner" style="{innerSpanStyle}">' +
371 '<span class="{baseCls}-icon"></span>' +
376 <span id='Ext-button-Button-cfg-scale'> /**
377 </span> * @cfg {String} scale
378 * <p>(Optional) The size of the Button. Three values are allowed:</p>
379 * <ul class="mdetail-params">
380 * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
381 * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
382 * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
384 * <p>Defaults to <b><tt>'small'</tt></b>.</p>
388 <span id='Ext-button-Button-property-allowedScales'> /**
389 </span> * @private An array of allowed scales.
391 allowedScales: ['small', 'medium', 'large'],
393 <span id='Ext-button-Button-cfg-scope'> /**
394 </span> * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
395 * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
396 * executed. Defaults to this Button.
399 <span id='Ext-button-Button-cfg-iconAlign'> /**
400 </span> * @cfg {String} iconAlign
401 * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
402 * <ul class="mdetail-params">
403 * <li>'top'<div class="sub-desc"></div></li>
404 * <li>'right'<div class="sub-desc"></div></li>
405 * <li>'bottom'<div class="sub-desc"></div></li>
406 * <li>'left'<div class="sub-desc"></div></li>
408 * <p>Defaults to <b><tt>'left'</tt></b>.</p>
412 <span id='Ext-button-Button-cfg-arrowAlign'> /**
413 </span> * @cfg {String} arrowAlign
414 * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
415 * Two values are allowed:</p>
416 * <ul class="mdetail-params">
417 * <li>'right'<div class="sub-desc"></div></li>
418 * <li>'bottom'<div class="sub-desc"></div></li>
420 * <p>Defaults to <b><tt>'right'</tt></b>.</p>
424 <span id='Ext-button-Button-cfg-arrowCls'> /**
425 </span> * @cfg {String} arrowCls
426 * <p>(Optional) The className used for the inner arrow element if the button has a menu.</p>
430 <span id='Ext-button-Button-property-template'> /**
431 </span> * @cfg {Ext.Template} template (Optional)
432 * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
433 * Instances, or subclasses which need a different DOM structure may provide a different
434 * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
439 <span id='Ext-button-Button-cfg-cls'> /**
440 </span> * @cfg {String} cls
441 * A CSS class string to apply to the button's main element.
444 <span id='Ext-button-Button-property-menu'> /**
445 </span> * @property menu
447 * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
450 <span id='Ext-button-Button-cfg-autoWidth'> /**
451 </span> * @cfg {Boolean} autoWidth
452 * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
453 * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
454 * the button from doing this automatic sizing.
455 * Defaults to <tt>undefined</tt>.
458 maskOnDisable: false,
461 initComponent: function() {
463 me.callParent(arguments);
466 <span id='Ext-button-Button-event-click'> /**
467 </span> * @event click
468 * Fires when this button is clicked
469 * @param {Button} this
470 * @param {EventObject} e The click event
474 <span id='Ext-button-Button-event-toggle'> /**
475 </span> * @event toggle
476 * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
477 * @param {Button} this
478 * @param {Boolean} pressed
482 <span id='Ext-button-Button-event-mouseover'> /**
483 </span> * @event mouseover
484 * Fires when the mouse hovers over the button
485 * @param {Button} this
486 * @param {Event} e The event object
490 <span id='Ext-button-Button-event-mouseout'> /**
491 </span> * @event mouseout
492 * Fires when the mouse exits the button
493 * @param {Button} this
494 * @param {Event} e The event object
498 <span id='Ext-button-Button-event-menushow'> /**
499 </span> * @event menushow
500 * If this button has a menu, this event fires when it is shown
501 * @param {Button} this
506 <span id='Ext-button-Button-event-menuhide'> /**
507 </span> * @event menuhide
508 * If this button has a menu, this event fires when it is hidden
509 * @param {Button} this
514 <span id='Ext-button-Button-event-menutriggerover'> /**
515 </span> * @event menutriggerover
516 * If this button has a menu, this event fires when the mouse enters the menu triggering element
517 * @param {Button} this
519 * @param {EventObject} e
523 <span id='Ext-button-Button-event-menutriggerout'> /**
524 </span> * @event menutriggerout
525 * If this button has a menu, this event fires when the mouse leaves the menu triggering element
526 * @param {Button} this
528 * @param {EventObject} e
534 // Flag that we'll have a splitCls
537 // retrieve menu by id or instantiate instance if needed
538 me.menu = Ext.menu.Manager.get(me.menu);
539 me.menu.ownerCt = me;
542 // Accept url as a synonym for href
547 // preventDefault defaults to false for links
548 if (me.href && !me.hasOwnProperty('preventDefault')) {
549 me.preventDefault = false;
552 if (Ext.isString(me.toggleGroup)) {
553 me.enableToggle = true;
559 initAria: function() {
561 var actionEl = this.getActionEl();
563 actionEl.dom.setAttribute('aria-haspopup', true);
568 getActionEl: function() {
573 getFocusEl: function() {
578 setButtonCls: function() {
583 if (me.useSetClass) {
584 if (!Ext.isEmpty(me.oldCls)) {
585 me.removeClsWithUI(me.oldCls);
586 me.removeClsWithUI(me.pressedCls);
589 // Check whether the button has an icon or not, and if it has an icon, what is th alignment
590 if (me.iconCls || me.icon) {
592 cls.push('icon-text-' + me.iconAlign);
596 } else if (me.text) {
601 me.addClsWithUI(cls);
602 me.addClsWithUI(me.pressed ? me.pressedCls : null);
607 onRender: function(ct, position) {
608 // classNames for the button
612 // Apply the renderData to the template args
613 Ext.applyIf(me.renderData, me.getTemplateArgs());
615 // Extract the button and the button wrapping element
616 Ext.applyIf(me.renderSelectors, {
617 btnEl : me.href ? 'a' : 'button',
619 btnInnerEl: '.' + me.baseCls + '-inner',
620 btnIconEl: '.'+ me.baseCls + '-icon'
624 me.ui = me.ui + '-' + me.scale;
627 // Render internal structure
628 me.callParent(arguments);
630 // If it is a split button + has a toolip for the arrow
631 if (me.split && me.arrowTooltip) {
632 me.arrowEl.dom[me.tooltipType] = me.arrowTooltip;
635 // Add listeners to the focus and blur events on the element
642 // Set btn as a local variable for easy access
650 me.setIconCls(me.iconCls);
654 me.setTooltip(me.tooltip, true);
657 // Add the mouse events to the button
658 if (me.handleMouseEvents) {
661 mouseover: me.onMouseOver,
662 mouseout: me.onMouseOut,
663 mousedown: me.onMouseDown
668 mousemove: me.onMouseMove,
674 // Check if the button has a menu
682 me.keyMap = Ext.create('Ext.util.KeyMap', me.el, {
683 key: Ext.EventObject.DOWN,
684 handler: me.onDownKey,
689 // Check if it is a repeat button
691 repeater = Ext.create('Ext.util.ClickRepeater', btn, Ext.isObject(me.repeat) ? me.repeat: {});
692 me.mon(repeater, 'click', me.onRepeatClick, me);
694 me.mon(btn, me.clickEvent, me.onClick, me);
697 // Register the button in the toggle manager
698 Ext.ButtonToggleManager.register(me);
701 <span id='Ext-button-Button-method-getTemplateArgs'> /**
702 </span> * <p>This method returns an object which provides substitution parameters for the {@link #renderTpl XTemplate} used
703 * to create this Button's DOM structure.</p>
704 * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
705 * own implementation of this method.</p>
706 * <p>The default implementation which provides data for the default {@link #template} returns an Object containing the
707 * following properties:</p><div class="mdetail-params"><ul>
708 * <li><code>type</code> : The &lt;button&gt;'s {@link #type}</li>
709 * <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>
710 * <li><code>cls</code> : A CSS class name applied to the Button's main &lt;tbody&gt; element which determines the button's scale and icon alignment.</li>
711 * <li><code>text</code> : The {@link #text} to display ion the Button.</li>
712 * <li><code>tabIndex</code> : The tab index within the input flow.</li>
713 * </ul></div>
714 * @return {Array} Substitution data for a Template.
716 getTemplateArgs: function() {
718 persistentPadding = me.getPersistentBtnPadding(),
721 // Create negative margin offsets to counteract persistent button padding if needed
722 if (Math.max.apply(Math, persistentPadding) > 0) {
723 innerSpanStyle = 'margin:' + Ext.Array.map(persistentPadding, function(pad) {
730 target : me.target || '_blank',
732 splitCls : me.getSplitCls(),
734 text : me.text || '&#160;',
735 tabIndex : me.tabIndex,
736 innerSpanStyle: innerSpanStyle
740 <span id='Ext-button-Button-method-getHref'> /**
742 * If there is a configured href for this Button, returns the href with parameters appended.
743 * @returns The href string with parameters appended.
745 getHref: function() {
747 params = Ext.apply({}, me.baseParams);
749 // write baseParams first, then write any params
750 params = Ext.apply(params, me.params);
751 return me.href ? Ext.urlAppend(me.href, Ext.Object.toQueryString(params)) : false;
754 <span id='Ext-button-Button-method-setParams'> /**
755 </span> * <p><b>Only valid if the Button was originally configured with a {@link #url}</b></p>
756 * <p>Sets the href of the link dynamically according to the params passed, and any {@link #baseParams} configured.</p>
757 * @param {Object} params Parameters to use in the href URL.
759 setParams: function(params) {
760 this.params = params;
761 this.btnEl.dom.href = this.getHref();
764 getSplitCls: function() {
766 return me.split ? (me.baseCls + '-' + me.arrowCls) + ' ' + (me.baseCls + '-' + me.arrowCls + '-' + me.arrowAlign) : '';
770 afterRender: function() {
772 me.useSetClass = true;
774 me.doc = Ext.getDoc();
775 this.callParent(arguments);
778 <span id='Ext-button-Button-method-setIconCls'> /**
779 </span> * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
780 * the value of the {@link #iconCls} config internally.
781 * @param {String} cls The CSS class providing the icon image
782 * @return {Ext.button.Button} this
784 setIconCls: function(cls) {
786 btnIconEl = me.btnIconEl;
788 // Remove the previous iconCls from the button
789 btnIconEl.removeCls(me.iconCls);
790 btnIconEl.addCls(cls || '');
797 <span id='Ext-button-Button-method-setTooltip'> /**
798 </span> * Sets the tooltip for this Button.
799 * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
800 * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
801 * <li><b>Object</b> : A configuration object for {@link Ext.tip.QuickTipManager#register}.</li>
802 * </ul></div>
803 * @return {Ext.button.Button} this
805 setTooltip: function(tooltip, initial) {
812 if (Ext.isObject(tooltip)) {
813 Ext.tip.QuickTipManager.register(Ext.apply({
817 me.tooltip = tooltip;
819 me.btnEl.dom.setAttribute('data-' + this.tooltipType, tooltip);
822 me.tooltip = tooltip;
828 getRefItems: function(deep){
829 var menu = this.menu,
833 items = menu.getRefItems(deep);
840 clearTip: function() {
841 if (Ext.isObject(this.tooltip)) {
842 Ext.tip.QuickTipManager.unregister(this.btnEl);
847 beforeDestroy: function() {
852 if (me.menu && me.destroyMenu !== false) {
853 Ext.destroy(me.btnEl, me.btnInnerEl, me.menu);
855 Ext.destroy(me.repeater);
859 onDestroy: function() {
862 me.doc.un('mouseover', me.monitorMouseOver, me);
863 me.doc.un('mouseup', me.onMouseUp, me);
866 delete me.btnInnerEl;
867 Ext.ButtonToggleManager.unregister(me);
869 Ext.destroy(me.keyMap);
875 <span id='Ext-button-Button-method-setHandler'> /**
876 </span> * Assigns this Button's click handler
877 * @param {Function} handler The function to call when the button is clicked
878 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
879 * Defaults to this Button.
880 * @return {Ext.button.Button} this
882 setHandler: function(handler, scope) {
883 this.handler = handler;
888 <span id='Ext-button-Button-method-setText'> /**
889 </span> * Sets this Button's text
890 * @param {String} text The button text
891 * @return {Ext.button.Button} this
893 setText: function(text) {
897 me.btnInnerEl.update(text || '&#160;');
900 me.doComponentLayout();
904 <span id='Ext-button-Button-method-setIcon'> /**
905 </span> * Sets the background image (inline style) of the button. This method also changes
906 * the value of the {@link #icon} config internally.
907 * @param {String} icon The path to an image to display in the button
908 * @return {Ext.button.Button} this
910 setIcon: function(icon) {
912 btnInnerEl = me.btnInnerEl;
915 btnInnerEl.setStyle('background-image', icon ? 'url(' + icon + ')': '');
921 <span id='Ext-button-Button-method-getText'> /**
922 </span> * Gets the text for this Button
923 * @return {String} The button text
925 getText: function() {
929 <span id='Ext-button-Button-method-toggle'> /**
930 </span> * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
931 * @param {Boolean} state (optional) Force a particular state
932 * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
933 * @return {Ext.button.Button} this
935 toggle: function(state, suppressEvent) {
937 state = state === undefined ? !me.pressed: !!state;
938 if (state !== me.pressed) {
940 me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls);
942 me.btnEl.dom.setAttribute('aria-pressed', state);
944 if (!suppressEvent) {
945 me.fireEvent('toggle', me, state);
946 Ext.callback(me.toggleHandler, me.scope || me, [me, state]);
952 <span id='Ext-button-Button-method-showMenu'> /**
953 </span> * Show this button's menu (if it has one)
955 showMenu: function() {
957 if (me.rendered && me.menu) {
959 Ext.tip.QuickTipManager.getQuickTip().cancelShow(me.btnEl);
961 if (me.menu.isVisible()) {
965 me.menu.showBy(me.el, me.menuAlign);
970 <span id='Ext-button-Button-method-hideMenu'> /**
971 </span> * Hide this button's menu (if it has one)
973 hideMenu: function() {
974 if (this.hasVisibleMenu()) {
980 <span id='Ext-button-Button-method-hasVisibleMenu'> /**
981 </span> * Returns true if the button has a menu and it is visible
984 hasVisibleMenu: function() {
985 var menu = this.menu;
986 return menu && menu.rendered && menu.isVisible();
990 onRepeatClick: function(repeat, e) {
995 onClick: function(e) {
997 if (me.preventDefault || (me.disabled && me.getHref()) && e) {
1000 if (e.button !== 0) {
1004 if (me.enableToggle && (me.allowDepress !== false || !me.pressed)) {
1007 if (me.menu && !me.hasVisibleMenu() && !me.ignoreNextClick) {
1010 me.fireEvent('click', me, e);
1012 me.handler.call(me.scope || me, me, e);
1018 <span id='Ext-button-Button-method-onMouseOver'> /**
1019 </span> * @private mouseover handler called when a mouseover event occurs anywhere within the encapsulating element.
1020 * The targets are interrogated to see what is being entered from where.
1023 onMouseOver: function(e) {
1025 if (!me.disabled && !e.within(me.el, true, true)) {
1030 <span id='Ext-button-Button-method-onMouseOut'> /**
1031 </span> * @private mouseout handler called when a mouseout event occurs anywhere within the encapsulating element -
1032 * or the mouse leaves the encapsulating element.
1033 * The targets are interrogated to see what is being exited to where.
1036 onMouseOut: function(e) {
1038 if (!e.within(me.el, true, true)) {
1039 if (me.overMenuTrigger) {
1040 me.onMenuTriggerOut(e);
1046 <span id='Ext-button-Button-method-onMouseMove'> /**
1047 </span> * @private mousemove handler called when the mouse moves anywhere within the encapsulating element.
1048 * The position is checked to determine if the mouse is entering or leaving the trigger area. Using
1049 * mousemove to check this is more resource intensive than we'd like, but it is necessary because
1050 * the trigger area does not line up exactly with sub-elements so we don't always get mouseover/out
1051 * events when needed. In the future we should consider making the trigger a separate element that
1052 * is absolutely positioned and sized over the trigger area.
1054 onMouseMove: function(e) {
1057 over = me.overMenuTrigger,
1061 if (me.arrowAlign === 'right') {
1062 overlap = e.getX() - el.getX();
1063 btnSize = el.getWidth();
1065 overlap = e.getY() - el.getY();
1066 btnSize = el.getHeight();
1069 if (overlap > (btnSize - me.getTriggerSize())) {
1071 me.onMenuTriggerOver(e);
1075 me.onMenuTriggerOut(e);
1081 <span id='Ext-button-Button-method-getTriggerSize'> /**
1082 </span> * @private Measures the size of the trigger area for menu and split buttons. Will be a width for
1083 * a right-aligned trigger and a height for a bottom-aligned trigger. Cached after first measurement.
1085 getTriggerSize: function() {
1087 size = me.triggerSize,
1088 side, sideFirstLetter, undef;
1090 if (size === undef) {
1091 side = me.arrowAlign;
1092 sideFirstLetter = side.charAt(0);
1093 size = me.triggerSize = me.el.getFrameWidth(sideFirstLetter) + me.btnWrap.getFrameWidth(sideFirstLetter) + (me.frameSize && me.frameSize[side] || 0);
1098 <span id='Ext-button-Button-method-onMouseEnter'> /**
1099 </span> * @private virtual mouseenter handler called when it is detected that the mouseout event
1100 * signified the mouse entering the encapsulating element.
1103 onMouseEnter: function(e) {
1105 me.addClsWithUI(me.overCls);
1106 me.fireEvent('mouseover', me, e);
1109 <span id='Ext-button-Button-method-onMouseLeave'> /**
1110 </span> * @private virtual mouseleave handler called when it is detected that the mouseover event
1111 * signified the mouse entering the encapsulating element.
1114 onMouseLeave: function(e) {
1116 me.removeClsWithUI(me.overCls);
1117 me.fireEvent('mouseout', me, e);
1120 <span id='Ext-button-Button-method-onMenuTriggerOver'> /**
1121 </span> * @private virtual mouseenter handler called when it is detected that the mouseover event
1122 * signified the mouse entering the arrow area of the button - the <em>.
1125 onMenuTriggerOver: function(e) {
1127 me.overMenuTrigger = true;
1128 me.fireEvent('menutriggerover', me, me.menu, e);
1131 <span id='Ext-button-Button-method-onMenuTriggerOut'> /**
1132 </span> * @private virtual mouseleave handler called when it is detected that the mouseout event
1133 * signified the mouse leaving the arrow area of the button - the <em>.
1136 onMenuTriggerOut: function(e) {
1138 delete me.overMenuTrigger;
1139 me.fireEvent('menutriggerout', me, me.menu, e);
1143 enable : function(silent) {
1146 me.callParent(arguments);
1148 me.removeClsWithUI('disabled');
1154 disable : function(silent) {
1157 me.callParent(arguments);
1159 me.addClsWithUI('disabled');
1164 <span id='Ext-button-Button-method-setScale'> /**
1165 </span> * Method to change the scale of the button. See {@link #scale} for allowed configurations.
1166 * @param {String} scale The scale to change to.
1168 setScale: function(scale) {
1170 ui = me.ui.replace('-' + me.scale, '');
1172 //check if it is an allowed scale
1173 if (!Ext.Array.contains(me.allowedScales, scale)) {
1174 throw('#setScale: scale must be an allowed scale (' + me.allowedScales.join(', ') + ')');
1182 setUI: function(ui) {
1185 //we need to append the scale to the UI, if not already done
1186 if (me.scale && !ui.match(me.scale)) {
1187 ui = ui + '-' + me.scale;
1190 me.callParent([ui]);
1192 // Set all the state classNames, as they need to include the UI
1193 // me.disabledCls += ' ' + me.baseCls + '-' + me.ui + '-disabled';
1197 onFocus: function(e) {
1200 me.addClsWithUI(me.focusCls);
1205 onBlur: function(e) {
1207 me.removeClsWithUI(me.focusCls);
1211 onMouseDown: function(e) {
1213 if (!me.disabled && e.button === 0) {
1214 me.addClsWithUI(me.pressedCls);
1215 me.doc.on('mouseup', me.onMouseUp, me);
1219 onMouseUp: function(e) {
1221 if (e.button === 0) {
1223 me.removeClsWithUI(me.pressedCls);
1225 me.doc.un('mouseup', me.onMouseUp, me);
1229 onMenuShow: function(e) {
1231 me.ignoreNextClick = 0;
1232 me.addClsWithUI(me.menuActiveCls);
1233 me.fireEvent('menushow', me, me.menu);
1237 onMenuHide: function(e) {
1239 me.removeClsWithUI(me.menuActiveCls);
1240 me.ignoreNextClick = Ext.defer(me.restoreClick, 250, me);
1241 me.fireEvent('menuhide', me, me.menu);
1245 restoreClick: function() {
1246 this.ignoreNextClick = 0;
1250 onDownKey: function() {
1260 <span id='Ext-button-Button-method-getPersistentBtnPadding'> /**
1261 </span> * @private Some browsers (notably Safari and older Chromes on Windows) add extra "padding" inside the button
1262 * element that cannot be removed. This method returns the size of that padding with a one-time detection.
1263 * @return Array [top, right, bottom, left]
1265 getPersistentBtnPadding: function() {
1266 var cls = Ext.button.Button,
1267 padding = cls.persistentPadding,
1268 btn, leftTop, btnEl, btnInnerEl;
1271 padding = cls.persistentPadding = [0, 0, 0, 0]; //set early to prevent recursion
1273 if (!Ext.isIE) { //short-circuit IE as it sometimes gives false positive for padding
1274 // Create auto-size button offscreen and measure its insides
1275 btn = Ext.create('Ext.button.Button', {
1276 renderTo: Ext.getBody(),
1278 style: 'position:absolute;top:-999px;'
1281 btnInnerEl = btn.btnInnerEl;
1282 btnEl.setSize(null, null); //clear any hard dimensions on the button el to see what it does naturally
1284 leftTop = btnInnerEl.getOffsetsTo(btnEl);
1285 padding[0] = leftTop[1];
1286 padding[1] = btnEl.getWidth() - btnInnerEl.getWidth() - leftTop[0];
1287 padding[2] = btnEl.getHeight() - btnInnerEl.getHeight() - leftTop[1];
1288 padding[3] = leftTop[0];
1301 function toggleGroup(btn, state) {
1303 g = groups[btn.toggleGroup];
1304 for (i = 0, l = g.length; i < l; i++) {
1311 // Private utility class used by Button
1312 Ext.ButtonToggleManager = {
1313 register: function(btn) {
1314 if (!btn.toggleGroup) {
1317 var group = groups[btn.toggleGroup];
1319 group = groups[btn.toggleGroup] = [];
1322 btn.on('toggle', toggleGroup);
1325 unregister: function(btn) {
1326 if (!btn.toggleGroup) {
1329 var group = groups[btn.toggleGroup];
1331 Ext.Array.remove(group, btn);
1332 btn.un('toggle', toggleGroup);
1336 <span id='Ext-button-Button-method-getPressed'> /**
1337 </span> * Gets the pressed button in the passed group or null
1338 * @param {String} group
1341 getPressed: function(group) {
1342 var g = groups[group],
1346 for (len = g.length; i < len; i++) {
1347 if (g[i].pressed === true) {