1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-button.Button-method-constructor'><span id='Ext-button.Button'>/**
2 </span></span> * @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',
155 <span id='Ext-button.Button-property-hidden'> /**
156 </span> * Read-only. True if this button is hidden
161 <span id='Ext-button.Button-property-disabled'> /**
162 </span> * Read-only. True if this button is disabled
167 <span id='Ext-button.Button-property-pressed'> /**
168 </span> * Read-only. True if this button is pressed (only if enableToggle = true)
173 <span id='Ext-button.Button-cfg-text'> /**
174 </span> * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
177 <span id='Ext-button.Button-cfg-icon'> /**
178 </span> * @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')
182 <span id='Ext-button.Button-cfg-handler'> /**
183 </span> * @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>
187 * </ul></div>
190 <span id='Ext-button.Button-cfg-minWidth'> /**
191 </span> * @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>.
195 <span id='Ext-button.Button-cfg-tooltip'> /**
196 </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
199 <span id='Ext-button.Button-cfg-hidden'> /**
200 </span> * @cfg {Boolean} hidden True to start hidden (defaults to false)
203 <span id='Ext-button.Button-cfg-disabled'> /**
204 </span> * @cfg {Boolean} disabled True to start disabled (defaults to false)
207 <span id='Ext-button.Button-cfg-pressed'> /**
208 </span> * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
211 <span id='Ext-button.Button-cfg-toggleGroup'> /**
212 </span> * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
215 <span id='Ext-button.Button-cfg-repeat'> /**
216 </span> * @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).
220 <span id='Ext-button.Button-cfg-tabIndex'> /**
221 </span> * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
224 <span id='Ext-button.Button-cfg-allowDepress'> /**
225 </span> * @cfg {Boolean} allowDepress
226 * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
229 <span id='Ext-button.Button-cfg-enableToggle'> /**
230 </span> * @cfg {Boolean} enableToggle
231 * True to enable pressed/not pressed toggling (defaults to false)
235 <span id='Ext-button.Button-cfg-toggleHandler'> /**
236 </span> * @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>
243 <span id='Ext-button.Button-cfg-menu'> /**
244 </span> * @cfg {Mixed} menu
245 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
248 <span id='Ext-button.Button-cfg-menuAlign'> /**
249 </span> * @cfg {String} menuAlign
250 * The position to align the menu to (see {@link Ext.core.Element#alignTo} for more details, defaults to 'tl-bl?').
254 <span id='Ext-button.Button-cfg-overflowText'> /**
255 </span> * @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>.
260 <span id='Ext-button.Button-cfg-iconCls'> /**
261 </span> * @cfg {String} iconCls
262 * A css class which sets a background image to be used as the icon for this button
265 <span id='Ext-button.Button-cfg-type'> /**
266 </span> * @cfg {String} type
267 * submit, reset or button - defaults to 'button'
271 <span id='Ext-button.Button-cfg-clickEvent'> /**
272 </span> * @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>.
278 <span id='Ext-button.Button-cfg-preventDefault'> /**
279 </span> * @cfg {Boolean} preventDefault
280 * True to prevent the default action when the {@link #clickEvent} is processed. Defaults to true.
282 preventDefault: true,
284 <span id='Ext-button.Button-cfg-handleMouseEvents'> /**
285 </span> * @cfg {Boolean} handleMouseEvents
286 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
288 handleMouseEvents: true,
290 <span id='Ext-button.Button-cfg-tooltipType'> /**
291 </span> * @cfg {String} tooltipType
292 * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
296 <span id='Ext-button.Button-cfg-baseCls'> /**
297 </span> * @cfg {String} baseCls
298 * The base CSS class to add to all buttons. (Defaults to 'x-btn')
300 baseCls: Ext.baseCSSPrefix + 'btn',
302 <span id='Ext-button.Button-cfg-pressedCls'> /**
303 </span> * @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',
308 <span id='Ext-button.Button-cfg-overCls'> /**
309 </span> * @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')
314 <span id='Ext-button.Button-cfg-focusCls'> /**
315 </span> * @cfg {String} focusCls
316 * The CSS class to add to a button when it is in the focussed state. (Defaults to 'x-btn-focus')
320 <span id='Ext-button.Button-cfg-menuActiveCls'> /**
321 </span> * @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',
330 '<em class="{splitCls}">' +
331 '<tpl if="href">' +
332 '<a href="{href}" target="{target}"<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="link">' +
333 '<span class="{baseCls}-inner">{text}</span>' +
336 '<tpl if="!href">' +
337 '<button type="{type}" hidefocus="true"' +
338 // the autocomplete="off" is required to prevent Firefox from remembering
339 // the button's disabled state between page reloads.
340 '<tpl if="tabIndex"> tabIndex="{tabIndex}"</tpl> role="button" autocomplete="off">' +
341 '<span class="{baseCls}-inner" style="{innerSpanStyle}">{text}</span>' +
346 <span id='Ext-button.Button-cfg-scale'> /**
347 </span> * @cfg {String} scale
348 * <p>(Optional) The size of the Button. Three values are allowed:</p>
349 * <ul class="mdetail-params">
350 * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
351 * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
352 * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
354 * <p>Defaults to <b><tt>'small'</tt></b>.</p>
358 <span id='Ext-button.Button-property-allowedScales'> /**
359 </span> * @private An array of allowed scales.
361 allowedScales: ['small', 'medium', 'large'],
363 <span id='Ext-button.Button-cfg-scope'> /**
364 </span> * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
365 * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
366 * executed. Defaults to this Button.
369 <span id='Ext-button.Button-cfg-iconAlign'> /**
370 </span> * @cfg {String} iconAlign
371 * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
372 * <ul class="mdetail-params">
373 * <li>'top'<div class="sub-desc"></div></li>
374 * <li>'right'<div class="sub-desc"></div></li>
375 * <li>'bottom'<div class="sub-desc"></div></li>
376 * <li>'left'<div class="sub-desc"></div></li>
378 * <p>Defaults to <b><tt>'left'</tt></b>.</p>
382 <span id='Ext-button.Button-cfg-arrowAlign'> /**
383 </span> * @cfg {String} arrowAlign
384 * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
385 * Two values are allowed:</p>
386 * <ul class="mdetail-params">
387 * <li>'right'<div class="sub-desc"></div></li>
388 * <li>'bottom'<div class="sub-desc"></div></li>
390 * <p>Defaults to <b><tt>'right'</tt></b>.</p>
394 <span id='Ext-button.Button-cfg-arrowCls'> /**
395 </span> * @cfg {String} arrowCls
396 * <p>(Optional) The className used for the inner arrow element if the button has a menu.</p>
400 <span id='Ext-button.Button-property-template'> /**
401 </span> * @cfg {Ext.Template} template (Optional)
402 * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
403 * Instances, or subclasses which need a different DOM structure may provide a different
404 * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
409 <span id='Ext-button.Button-cfg-cls'> /**
410 </span> * @cfg {String} cls
411 * A CSS class string to apply to the button's main element.
414 <span id='Ext-button.Button-property-menu'> /**
415 </span> * @property menu
417 * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
420 <span id='Ext-button.Button-cfg-autoWidth'> /**
421 </span> * @cfg {Boolean} autoWidth
422 * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
423 * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
424 * the button from doing this automatic sizing.
425 * Defaults to <tt>undefined</tt>.
428 maskOnDisable: false,
431 initComponent: function() {
433 me.callParent(arguments);
436 <span id='Ext-button.Button-event-click'> /**
437 </span> * @event click
438 * Fires when this button is clicked
439 * @param {Button} this
440 * @param {EventObject} e The click event
444 <span id='Ext-button.Button-event-toggle'> /**
445 </span> * @event toggle
446 * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
447 * @param {Button} this
448 * @param {Boolean} pressed
452 <span id='Ext-button.Button-event-mouseover'> /**
453 </span> * @event mouseover
454 * Fires when the mouse hovers over the button
455 * @param {Button} this
456 * @param {Event} e The event object
460 <span id='Ext-button.Button-event-mouseout'> /**
461 </span> * @event mouseout
462 * Fires when the mouse exits the button
463 * @param {Button} this
464 * @param {Event} e The event object
468 <span id='Ext-button.Button-event-menushow'> /**
469 </span> * @event menushow
470 * If this button has a menu, this event fires when it is shown
471 * @param {Button} this
476 <span id='Ext-button.Button-event-menuhide'> /**
477 </span> * @event menuhide
478 * If this button has a menu, this event fires when it is hidden
479 * @param {Button} this
484 <span id='Ext-button.Button-event-menutriggerover'> /**
485 </span> * @event menutriggerover
486 * If this button has a menu, this event fires when the mouse enters the menu triggering element
487 * @param {Button} this
489 * @param {EventObject} e
493 <span id='Ext-button.Button-event-menutriggerout'> /**
494 </span> * @event menutriggerout
495 * If this button has a menu, this event fires when the mouse leaves the menu triggering element
496 * @param {Button} this
498 * @param {EventObject} e
504 // Flag that we'll have a splitCls
507 // retrieve menu by id or instantiate instance if needed
508 me.menu = Ext.menu.Manager.get(me.menu);
509 me.menu.ownerCt = me;
512 // Accept url as a synonym for href
517 // preventDefault defaults to false for links
518 if (me.href && !me.hasOwnProperty('preventDefault')) {
519 me.preventDefault = false;
522 if (Ext.isString(me.toggleGroup)) {
523 me.enableToggle = true;
529 initAria: function() {
531 var actionEl = this.getActionEl();
533 actionEl.dom.setAttribute('aria-haspopup', true);
538 getActionEl: function() {
543 getFocusEl: function() {
548 setButtonCls: function() {
553 if (me.useSetClass) {
554 if (!Ext.isEmpty(me.oldCls)) {
555 me.removeClsWithUI(me.oldCls);
556 me.removeClsWithUI(me.pressedCls);
559 // Check whether the button has an icon or not, and if it has an icon, what is th alignment
560 if (me.iconCls || me.icon) {
562 cls.push('icon-text-' + me.iconAlign);
566 } else if (me.text) {
571 me.addClsWithUI(cls);
572 me.addClsWithUI(me.pressed ? me.pressedCls : null);
577 onRender: function(ct, position) {
578 // classNames for the button
582 // Apply the renderData to the template args
583 Ext.applyIf(me.renderData, me.getTemplateArgs());
585 // Extract the button and the button wrapping element
586 Ext.applyIf(me.renderSelectors, {
587 btnEl : me.href ? 'a' : 'button',
589 btnInnerEl: '.' + me.baseCls + '-inner'
593 me.ui = me.ui + '-' + me.scale;
596 // Render internal structure
597 me.callParent(arguments);
599 // If it is a split button + has a toolip for the arrow
600 if (me.split && me.arrowTooltip) {
601 me.arrowEl.dom[me.tooltipType] = me.arrowTooltip;
604 // Add listeners to the focus and blur events on the element
611 // Set btn as a local variable for easy access
619 me.setIconCls(me.iconCls);
623 me.setTooltip(me.tooltip, true);
626 // Add the mouse events to the button
627 if (me.handleMouseEvents) {
630 mouseover: me.onMouseOver,
631 mouseout: me.onMouseOut,
632 mousedown: me.onMouseDown
637 mousemove: me.onMouseMove,
643 // Check if the button has a menu
651 me.keyMap = Ext.create('Ext.util.KeyMap', me.el, {
652 key: Ext.EventObject.DOWN,
653 handler: me.onDownKey,
658 // Check if it is a repeat button
660 repeater = Ext.create('Ext.util.ClickRepeater', btn, Ext.isObject(me.repeat) ? me.repeat: {});
661 me.mon(repeater, 'click', me.onRepeatClick, me);
663 me.mon(btn, me.clickEvent, me.onClick, me);
666 // Register the button in the toggle manager
667 Ext.ButtonToggleManager.register(me);
670 <span id='Ext-button.Button-method-getTemplateArgs'> /**
671 </span> * <p>This method returns an object which provides substitution parameters for the {@link #renderTpl XTemplate} used
672 * to create this Button's DOM structure.</p>
673 * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
674 * own implementation of this method.</p>
675 * <p>The default implementation which provides data for the default {@link #template} returns an Object containing the
676 * following properties:</p><div class="mdetail-params"><ul>
677 * <li><code>type</code> : The &lt;button&gt;'s {@link #type}</li>
678 * <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>
679 * <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>
680 * <li><code>text</code> : The {@link #text} to display ion the Button.</li>
681 * <li><code>tabIndex</code> : The tab index within the input flow.</li>
682 * </ul></div>
683 * @return {Array} Substitution data for a Template.
685 getTemplateArgs: function() {
687 persistentPadding = me.getPersistentBtnPadding(),
690 // Create negative margin offsets to counteract persistent button padding if needed
691 if (Math.max.apply(Math, persistentPadding) > 0) {
692 innerSpanStyle = 'margin:' + Ext.Array.map(persistentPadding, function(pad) {
699 target : me.target || '_blank',
701 splitCls : me.getSplitCls(),
703 text : me.text || '&#160;',
704 tabIndex : me.tabIndex,
705 innerSpanStyle: innerSpanStyle
709 <span id='Ext-button.Button-method-getHref'> /**
711 * If there is a configured href for this Button, returns the href with parameters appended.
712 * @returns The href string with parameters appended.
714 getHref: function() {
716 return me.href ? Ext.urlAppend(me.href, me.params + Ext.Object.toQueryString(Ext.apply(Ext.apply({}, me.baseParams)))) : false;
719 <span id='Ext-button.Button-method-setParams'> /**
720 </span> * <p><b>Only valid if the Button was originally configured with a {@link #url}</b></p>
721 * <p>Sets the href of the link dynamically according to the params passed, and any {@link #baseParams} configured.</p>
722 * @param {Object} Parameters to use in the href URL.
724 setParams: function(p) {
726 this.btnEl.dom.href = this.getHref();
729 getSplitCls: function() {
731 return me.split ? (me.baseCls + '-' + me.arrowCls) + ' ' + (me.baseCls + '-' + me.arrowCls + '-' + me.arrowAlign) : '';
735 afterRender: function() {
737 me.useSetClass = true;
739 me.doc = Ext.getDoc();
740 this.callParent(arguments);
743 <span id='Ext-button.Button-method-setIconCls'> /**
744 </span> * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
745 * the value of the {@link #iconCls} config internally.
746 * @param {String} cls The CSS class providing the icon image
747 * @return {Ext.button.Button} this
749 setIconCls: function(cls) {
751 btnInnerEl = me.btnInnerEl;
753 // Remove the previous iconCls from the button
754 btnInnerEl.removeCls(me.iconCls);
755 btnInnerEl.addCls(cls || '');
762 <span id='Ext-button.Button-method-setTooltip'> /**
763 </span> * Sets the tooltip for this Button.
764 * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
765 * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
766 * <li><b>Object</b> : A configuration object for {@link Ext.tip.QuickTipManager#register}.</li>
767 * </ul></div>
768 * @return {Ext.button.Button} this
770 setTooltip: function(tooltip, initial) {
777 if (Ext.isObject(tooltip)) {
778 Ext.tip.QuickTipManager.register(Ext.apply({
782 me.tooltip = tooltip;
784 me.btnEl.dom.setAttribute('data-' + this.tooltipType, tooltip);
787 me.tooltip = tooltip;
793 getRefItems: function(deep){
794 var menu = this.menu,
798 items = menu.getRefItems(deep);
805 clearTip: function() {
806 if (Ext.isObject(this.tooltip)) {
807 Ext.tip.QuickTipManager.unregister(this.btnEl);
812 beforeDestroy: function() {
817 if (me.menu && me.destroyMenu !== false) {
818 Ext.destroy(me.btnEl, me.btnInnerEl, me.menu);
820 Ext.destroy(me.repeater);
824 onDestroy: function() {
827 me.doc.un('mouseover', me.monitorMouseOver, me);
828 me.doc.un('mouseup', me.onMouseUp, me);
831 delete me.btnInnerEl;
832 Ext.ButtonToggleManager.unregister(me);
834 Ext.destroy(me.keyMap);
840 <span id='Ext-button.Button-method-setHandler'> /**
841 </span> * Assigns this Button's click handler
842 * @param {Function} handler The function to call when the button is clicked
843 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
844 * Defaults to this Button.
845 * @return {Ext.button.Button} this
847 setHandler: function(handler, scope) {
848 this.handler = handler;
853 <span id='Ext-button.Button-method-setText'> /**
854 </span> * Sets this Button's text
855 * @param {String} text The button text
856 * @return {Ext.button.Button} this
858 setText: function(text) {
862 me.btnInnerEl.update(text || '&#160;');
865 me.doComponentLayout();
869 <span id='Ext-button.Button-method-setIcon'> /**
870 </span> * Sets the background image (inline style) of the button. This method also changes
871 * the value of the {@link #icon} config internally.
872 * @param {String} icon The path to an image to display in the button
873 * @return {Ext.button.Button} this
875 setIcon: function(icon) {
877 btnInnerEl = me.btnInnerEl;
880 btnInnerEl.setStyle('background-image', icon ? 'url(' + icon + ')': '');
886 <span id='Ext-button.Button-method-getText'> /**
887 </span> * Gets the text for this Button
888 * @return {String} The button text
890 getText: function() {
894 <span id='Ext-button.Button-method-toggle'> /**
895 </span> * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
896 * @param {Boolean} state (optional) Force a particular state
897 * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
898 * @return {Ext.button.Button} this
900 toggle: function(state, suppressEvent) {
902 state = state === undefined ? !me.pressed: !!state;
903 if (state !== me.pressed) {
905 me[state ? 'addClsWithUI': 'removeClsWithUI'](me.pressedCls);
907 me.btnEl.dom.setAttribute('aria-pressed', state);
909 if (!suppressEvent) {
910 me.fireEvent('toggle', me, state);
911 Ext.callback(me.toggleHandler, me.scope || me, [me, state]);
917 <span id='Ext-button.Button-method-showMenu'> /**
918 </span> * Show this button's menu (if it has one)
920 showMenu: function() {
922 if (me.rendered && me.menu) {
924 Ext.tip.QuickTipManager.getQuickTip().cancelShow(me.btnEl);
926 if (me.menu.isVisible()) {
930 me.menu.showBy(me.el, me.menuAlign);
935 <span id='Ext-button.Button-method-hideMenu'> /**
936 </span> * Hide this button's menu (if it has one)
938 hideMenu: function() {
939 if (this.hasVisibleMenu()) {
945 <span id='Ext-button.Button-method-hasVisibleMenu'> /**
946 </span> * Returns true if the button has a menu and it is visible
949 hasVisibleMenu: function() {
950 var menu = this.menu;
951 return menu && menu.rendered && menu.isVisible();
955 onRepeatClick: function(repeat, e) {
960 onClick: function(e) {
962 if (me.preventDefault || (me.disabled && me.getHref()) && e) {
965 if (e.button !== 0) {
969 if (me.enableToggle && (me.allowDepress !== false || !me.pressed)) {
972 if (me.menu && !me.hasVisibleMenu() && !me.ignoreNextClick) {
975 me.fireEvent('click', me, e);
977 me.handler.call(me.scope || me, me, e);
983 <span id='Ext-button.Button-method-onMouseOver'> /**
984 </span> * @private mouseover handler called when a mouseover event occurs anywhere within the encapsulating element.
985 * The targets are interrogated to see what is being entered from where.
988 onMouseOver: function(e) {
990 if (!me.disabled && !e.within(me.el, true, true)) {
995 <span id='Ext-button.Button-method-onMouseOut'> /**
996 </span> * @private mouseout handler called when a mouseout event occurs anywhere within the encapsulating element -
997 * or the mouse leaves the encapsulating element.
998 * The targets are interrogated to see what is being exited to where.
1001 onMouseOut: function(e) {
1003 if (!e.within(me.el, true, true)) {
1004 if (me.overMenuTrigger) {
1005 me.onMenuTriggerOut(e);
1011 <span id='Ext-button.Button-method-onMouseMove'> /**
1012 </span> * @private mousemove handler called when the mouse moves anywhere within the encapsulating element.
1013 * The position is checked to determine if the mouse is entering or leaving the trigger area. Using
1014 * mousemove to check this is more resource intensive than we'd like, but it is necessary because
1015 * the trigger area does not line up exactly with sub-elements so we don't always get mouseover/out
1016 * events when needed. In the future we should consider making the trigger a separate element that
1017 * is absolutely positioned and sized over the trigger area.
1019 onMouseMove: function(e) {
1022 over = me.overMenuTrigger,
1026 if (me.arrowAlign === 'right') {
1027 overlap = e.getX() - el.getX();
1028 btnSize = el.getWidth();
1030 overlap = e.getY() - el.getY();
1031 btnSize = el.getHeight();
1034 if (overlap > (btnSize - me.getTriggerSize())) {
1036 me.onMenuTriggerOver(e);
1040 me.onMenuTriggerOut(e);
1046 <span id='Ext-button.Button-method-getTriggerSize'> /**
1047 </span> * @private Measures the size of the trigger area for menu and split buttons. Will be a width for
1048 * a right-aligned trigger and a height for a bottom-aligned trigger. Cached after first measurement.
1050 getTriggerSize: function() {
1052 size = me.triggerSize,
1053 side, sideFirstLetter, undef;
1055 if (size === undef) {
1056 side = me.arrowAlign;
1057 sideFirstLetter = side.charAt(0);
1058 size = me.triggerSize = me.el.getFrameWidth(sideFirstLetter) + me.btnWrap.getFrameWidth(sideFirstLetter) + (me.frameSize && me.frameSize[side] || 0);
1063 <span id='Ext-button.Button-method-onMouseEnter'> /**
1064 </span> * @private virtual mouseenter handler called when it is detected that the mouseout event
1065 * signified the mouse entering the encapsulating element.
1068 onMouseEnter: function(e) {
1070 me.addClsWithUI(me.overCls);
1071 me.fireEvent('mouseover', me, e);
1074 <span id='Ext-button.Button-method-onMouseLeave'> /**
1075 </span> * @private virtual mouseleave handler called when it is detected that the mouseover event
1076 * signified the mouse entering the encapsulating element.
1079 onMouseLeave: function(e) {
1081 me.removeClsWithUI(me.overCls);
1082 me.fireEvent('mouseout', me, e);
1085 <span id='Ext-button.Button-method-onMenuTriggerOver'> /**
1086 </span> * @private virtual mouseenter handler called when it is detected that the mouseover event
1087 * signified the mouse entering the arrow area of the button - the <em>.
1090 onMenuTriggerOver: function(e) {
1092 me.overMenuTrigger = true;
1093 me.fireEvent('menutriggerover', me, me.menu, e);
1096 <span id='Ext-button.Button-method-onMenuTriggerOut'> /**
1097 </span> * @private virtual mouseleave handler called when it is detected that the mouseout event
1098 * signified the mouse leaving the arrow area of the button - the <em>.
1101 onMenuTriggerOut: function(e) {
1103 delete me.overMenuTrigger;
1104 me.fireEvent('menutriggerout', me, me.menu, e);
1108 enable : function(silent) {
1111 me.callParent(arguments);
1113 me.removeClsWithUI('disabled');
1119 disable : function(silent) {
1122 me.callParent(arguments);
1124 me.addClsWithUI('disabled');
1129 <span id='Ext-button.Button-method-setScale'> /**
1130 </span> * Method to change the scale of the button. See {@link #scale} for allowed configurations.
1131 * @param {String} scale The scale to change to.
1133 setScale: function(scale) {
1135 ui = me.ui.replace('-' + me.scale, '');
1137 //check if it is an allowed scale
1138 if (!Ext.Array.contains(me.allowedScales, scale)) {
1139 throw('#setScale: scale must be an allowed scale (' + me.allowedScales.join(', ') + ')');
1147 setUI: function(ui) {
1150 //we need to append the scale to the UI, if not already done
1151 if (me.scale && !ui.match(me.scale)) {
1152 ui = ui + '-' + me.scale;
1155 me.callParent([ui]);
1157 // Set all the state classNames, as they need to include the UI
1158 // me.disabledCls += ' ' + me.baseCls + '-' + me.ui + '-disabled';
1162 onFocus: function(e) {
1165 me.addClsWithUI(me.focusCls);
1170 onBlur: function(e) {
1172 me.removeClsWithUI(me.focusCls);
1176 onMouseDown: function(e) {
1178 if (!me.disabled && e.button === 0) {
1179 me.addClsWithUI(me.pressedCls);
1180 me.doc.on('mouseup', me.onMouseUp, me);
1184 onMouseUp: function(e) {
1186 if (e.button === 0) {
1188 me.removeClsWithUI(me.pressedCls);
1190 me.doc.un('mouseup', me.onMouseUp, me);
1194 onMenuShow: function(e) {
1196 me.ignoreNextClick = 0;
1197 me.addClsWithUI(me.menuActiveCls);
1198 me.fireEvent('menushow', me, me.menu);
1202 onMenuHide: function(e) {
1204 me.removeClsWithUI(me.menuActiveCls);
1205 me.ignoreNextClick = Ext.defer(me.restoreClick, 250, me);
1206 me.fireEvent('menuhide', me, me.menu);
1210 restoreClick: function() {
1211 this.ignoreNextClick = 0;
1215 onDownKey: function() {
1225 <span id='Ext-button.Button-method-getPersistentBtnPadding'> /**
1226 </span> * @private Some browsers (notably Safari and older Chromes on Windows) add extra "padding" inside the button
1227 * element that cannot be removed. This method returns the size of that padding with a one-time detection.
1228 * @return Array [top, right, bottom, left]
1230 getPersistentBtnPadding: function() {
1231 var cls = Ext.button.Button,
1232 padding = cls.persistentPadding,
1233 btn, leftTop, btnEl, btnInnerEl;
1236 padding = cls.persistentPadding = [0, 0, 0, 0]; //set early to prevent recursion
1238 if (!Ext.isIE) { //short-circuit IE as it sometimes gives false positive for padding
1239 // Create auto-size button offscreen and measure its insides
1240 btn = Ext.create('Ext.button.Button', {
1241 renderTo: Ext.getBody(),
1243 style: 'position:absolute;top:-999px;'
1246 btnInnerEl = btn.btnInnerEl;
1247 btnEl.setSize(null, null); //clear any hard dimensions on the button el to see what it does naturally
1249 leftTop = btnInnerEl.getOffsetsTo(btnEl);
1250 padding[0] = leftTop[1];
1251 padding[1] = btnEl.getWidth() - btnInnerEl.getWidth() - leftTop[0];
1252 padding[2] = btnEl.getHeight() - btnInnerEl.getHeight() - leftTop[1];
1253 padding[3] = leftTop[0];
1266 function toggleGroup(btn, state) {
1268 g = groups[btn.toggleGroup];
1269 for (i = 0, l = g.length; i < l; i++) {
1276 // Private utility class used by Button
1277 Ext.ButtonToggleManager = {
1278 register: function(btn) {
1279 if (!btn.toggleGroup) {
1282 var group = groups[btn.toggleGroup];
1284 group = groups[btn.toggleGroup] = [];
1287 btn.on('toggle', toggleGroup);
1290 unregister: function(btn) {
1291 if (!btn.toggleGroup) {
1294 var group = groups[btn.toggleGroup];
1296 Ext.Array.remove(group, btn);
1297 btn.un('toggle', toggleGroup);
1301 <span id='Ext-button.Button-method-getPressed'> /**
1302 </span> * Gets the pressed button in the passed group or null
1303 * @param {String} group
1306 getPressed: function(group) {
1307 var g = groups[group],
1311 for (len = g.length; i < len; i++) {
1312 if (g[i].pressed === true) {
1321 </pre></pre></body></html>