-<html>\r
-<head>\r
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js"><div id="cls-Ext.Button"></div>/**\r
- * @class Ext.Button\r
- * @extends Ext.BoxComponent\r
- * Simple Button class\r
- * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)\r
- * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image\r
- * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')\r
- * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).\r
- * The handler is passed the following parameters:<div class="mdetail-params"><ul>\r
- * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>\r
- * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>\r
- * </ul></div>\r
- * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).\r
- * See also {@link Ext.Panel}.<tt>{@link Ext.Panel#minButtonWidth minButtonWidth}</tt>.\r
- * @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\r
- * @cfg {Boolean} hidden True to start hidden (defaults to false)\r
- * @cfg {Boolean} disabled True to start disabled (defaults to false)\r
- * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)\r
- * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)\r
- * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be\r
- * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).\r
- * @constructor\r
- * Create a new button\r
- * @param {Object} config The config object\r
- * @xtype button\r
- */\r
-Ext.Button = Ext.extend(Ext.BoxComponent, {\r
- /**\r
- * Read-only. True if this button is hidden\r
- * @type Boolean\r
- */\r
- hidden : false,\r
- /**\r
- * Read-only. True if this button is disabled\r
- * @type Boolean\r
- */\r
- disabled : false,\r
- /**\r
- * Read-only. True if this button is pressed (only if enableToggle = true)\r
- * @type Boolean\r
- */\r
- pressed : false,\r
-\r
- /**\r
- * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)\r
- */\r
-\r
- /**\r
- * @cfg {Boolean} allowDepress\r
- * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.\r
- */\r
-\r
- /**\r
- * @cfg {Boolean} enableToggle\r
- * True to enable pressed/not pressed toggling (defaults to false)\r
- */\r
- enableToggle : false,\r
- /**\r
- * @cfg {Function} toggleHandler\r
- * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">\r
- * <li><b>button</b> : Ext.Button<div class="sub-desc">this Button object</div></li>\r
- * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>\r
- * </ul>\r
- */\r
- /**\r
- * @cfg {Mixed} menu\r
- * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).\r
- */\r
- /**\r
- * @cfg {String} menuAlign\r
- * The position to align the menu to (see {@link Ext.Element#alignTo} for more details, defaults to 'tl-bl?').\r
- */\r
- menuAlign : 'tl-bl?',\r
-\r
- /**\r
- * @cfg {String} overflowText If used in a {@link Ext.Toolbar Toolbar}, the\r
- * text to be used if this item is shown in the overflow menu. See also\r
- * {@link Ext.Toolbar.Item}.<code>{@link Ext.Toolbar.Item#overflowText overflowText}</code>.\r
- */\r
- /**\r
- * @cfg {String} iconCls\r
- * A css class which sets a background image to be used as the icon for this button\r
- */\r
- /**\r
- * @cfg {String} type\r
- * submit, reset or button - defaults to 'button'\r
- */\r
- type : 'button',\r
-\r
- // private\r
- menuClassTarget : 'tr:nth(2)',\r
-\r
- /**\r
- * @cfg {String} clickEvent\r
- * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).\r
- * Defaults to <tt>'click'</tt>.\r
- */\r
- clickEvent : 'click',\r
-\r
- /**\r
- * @cfg {Boolean} handleMouseEvents\r
- * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)\r
- */\r
- handleMouseEvents : true,\r
-\r
- /**\r
- * @cfg {String} tooltipType\r
- * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.\r
- */\r
- tooltipType : 'qtip',\r
-\r
- /**\r
- * @cfg {String} buttonSelector\r
- * <p>(Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the\r
- * DOM structure created.</p>\r
- * <p>When a custom {@link #template} is used, you must ensure that this selector results in the selection of\r
- * a focussable element.</p>\r
- * <p>Defaults to <b><tt>'button:first-child'</tt></b>.</p>\r
- */\r
- buttonSelector : 'button:first-child',\r
-\r
- /**\r
- * @cfg {String} scale\r
- * <p>(Optional) The size of the Button. Three values are allowed:</p>\r
- * <ul class="mdetail-params">\r
- * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>\r
- * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>\r
- * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>\r
- * </ul>\r
- * <p>Defaults to <b><tt>'small'</tt></b>.</p>\r
- */\r
- scale : 'small',\r
-\r
- /**\r
- * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the\r
- * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is\r
- * executed. Defaults to this Button.\r
- */\r
-\r
- /**\r
- * @cfg {String} iconAlign\r
- * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>\r
- * <ul class="mdetail-params">\r
- * <li>'top'<div class="sub-desc"></div></li>\r
- * <li>'right'<div class="sub-desc"></div></li>\r
- * <li>'bottom'<div class="sub-desc"></div></li>\r
- * <li>'left'<div class="sub-desc"></div></li>\r
- * </ul>\r
- * <p>Defaults to <b><tt>'left'</tt></b>.</p>\r
- */\r
- iconAlign : 'left',\r
-\r
- /**\r
- * @cfg {String} arrowAlign\r
- * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.\r
- * Two values are allowed:</p>\r
- * <ul class="mdetail-params">\r
- * <li>'right'<div class="sub-desc"></div></li>\r
- * <li>'bottom'<div class="sub-desc"></div></li>\r
- * </ul>\r
- * <p>Defaults to <b><tt>'right'</tt></b>.</p>\r
- */\r
- arrowAlign : 'right',\r
-\r
- /**\r
- * @cfg {Ext.Template} template (Optional)\r
- * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>\r
- * Instances, or subclasses which need a different DOM structure may provide a different\r
- * template layout in conjunction with an implementation of {@link #getTemplateArgs}.\r
- * @type Ext.Template\r
- * @property template\r
- */\r
- /**\r
- * @cfg {String} cls\r
- * A CSS class string to apply to the button's main element.\r
- */\r
- /**\r
- * @property menu\r
- * @type Menu\r
- * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.\r
- */\r
-\r
- initComponent : function(){\r
- Ext.Button.superclass.initComponent.call(this);\r
-\r
- this.addEvents(\r
- /**\r
- * @event click\r
- * Fires when this button is clicked\r
- * @param {Button} this\r
- * @param {EventObject} e The click event\r
- */\r
- 'click',\r
- /**\r
- * @event toggle\r
- * Fires when the 'pressed' state of this button changes (only if enableToggle = true)\r
- * @param {Button} this\r
- * @param {Boolean} pressed\r
- */\r
- 'toggle',\r
- /**\r
- * @event mouseover\r
- * Fires when the mouse hovers over the button\r
- * @param {Button} this\r
- * @param {Event} e The event object\r
- */\r
- 'mouseover',\r
- /**\r
- * @event mouseout\r
- * Fires when the mouse exits the button\r
- * @param {Button} this\r
- * @param {Event} e The event object\r
- */\r
- 'mouseout',\r
- /**\r
- * @event menushow\r
- * If this button has a menu, this event fires when it is shown\r
- * @param {Button} this\r
- * @param {Menu} menu\r
- */\r
- 'menushow',\r
- /**\r
- * @event menuhide\r
- * If this button has a menu, this event fires when it is hidden\r
- * @param {Button} this\r
- * @param {Menu} menu\r
- */\r
- 'menuhide',\r
- /**\r
- * @event menutriggerover\r
- * If this button has a menu, this event fires when the mouse enters the menu triggering element\r
- * @param {Button} this\r
- * @param {Menu} menu\r
- * @param {EventObject} e\r
- */\r
- 'menutriggerover',\r
- /**\r
- * @event menutriggerout\r
- * If this button has a menu, this event fires when the mouse leaves the menu triggering element\r
- * @param {Button} this\r
- * @param {Menu} menu\r
- * @param {EventObject} e\r
- */\r
- 'menutriggerout'\r
- );\r
- if(this.menu){\r
- this.menu = Ext.menu.MenuMgr.get(this.menu);\r
- }\r
- if(Ext.isString(this.toggleGroup)){\r
- this.enableToggle = true;\r
- }\r
- },\r
-\r
-/**\r
- * <p>This method returns an Array which provides substitution parameters for the {@link #template Template} used\r
- * to create this Button's DOM structure.</p>\r
- * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their\r
- * own implementation of this method.</p>\r
- * <p>The default implementation which provides data for the default {@link #template} returns an Array containing the\r
- * following items:</p><div class="mdetail-params"><ul>\r
- * <li>The <button>'s {@link #type}</li>\r
- * <li>A CSS class name applied to the Button's main <tbody> element which determines the button's scale and icon alignment.</li>\r
- * <li>A CSS class to determine the presence and position of an arrow icon. (<code>'x-btn-arrow'</code> or <code>'x-btn-arrow-bottom'</code> or <code>''</code>)</li>\r
- * <li>The {@link #cls} CSS class name applied to the button's wrapping <table> element.</li>\r
- * <li>The Component id which is applied to the button's wrapping <table> element.</li>\r
- * </ul></div>\r
- * @return {Array} Substitution data for a Template.\r
- */\r
- getTemplateArgs : function(){\r
- return [this.type, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];\r
- },\r
-\r
- // private\r
- setButtonClass : function(){\r
- if(this.useSetClass){\r
- if(!Ext.isEmpty(this.oldCls)){\r
- this.el.removeClass([this.oldCls, 'x-btn-pressed']);\r
- }\r
- this.oldCls = (this.iconCls || this.icon) ? (this.text ? ' x-btn-text-icon' : ' x-btn-icon') : ' x-btn-noicon';\r
- this.el.addClass([this.oldCls, this.pressed ? 'x-btn-pressed' : null]);\r
- }\r
- },\r
-\r
- // protected\r
- getMenuClass : function(){\r
- return this.menu ? (this.arrowAlign != 'bottom' ? 'x-btn-arrow' : 'x-btn-arrow-bottom') : '';\r
- },\r
-\r
- // private\r
- onRender : function(ct, position){\r
- if(!this.template){\r
- if(!Ext.Button.buttonTemplate){\r
- // hideous table template\r
- Ext.Button.buttonTemplate = new Ext.Template(\r
- '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',\r
- '<tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr>',\r
- '<tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i> </i></td></tr>',\r
- '<tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr>',\r
- '</tbody></table>');\r
- Ext.Button.buttonTemplate.compile();\r
- }\r
- this.template = Ext.Button.buttonTemplate;\r
- }\r
-\r
- var btn, targs = this.getTemplateArgs();\r
-\r
- if(position){\r
- btn = this.template.insertBefore(position, targs, true);\r
- }else{\r
- btn = this.template.append(ct, targs, true);\r
- }\r
- /**\r
- * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,\r
- * this references a <tt><button></tt> element. Read only.\r
- * @type Ext.Element\r
- * @property btnEl\r
- */\r
- this.btnEl = btn.child(this.buttonSelector);\r
- this.mon(this.btnEl, {\r
- scope: this,\r
- focus: this.onFocus,\r
- blur: this.onBlur\r
- });\r
-\r
- this.initButtonEl(btn, this.btnEl);\r
-\r
- Ext.ButtonToggleMgr.register(this);\r
- },\r
-\r
- // private\r
- initButtonEl : function(btn, btnEl){\r
- this.el = btn;\r
- this.setIcon(this.icon);\r
- this.setText(this.text);\r
- this.setIconClass(this.iconCls);\r
- if(Ext.isDefined(this.tabIndex)){\r
- btnEl.dom.tabIndex = this.tabIndex;\r
- }\r
- if(this.tooltip){\r
- this.setTooltip(this.tooltip, true);\r
- }\r
-\r
- if(this.handleMouseEvents){\r
- this.mon(btn, {\r
- scope: this,\r
- mouseover: this.onMouseOver,\r
- mousedown: this.onMouseDown\r
- });\r
-\r
- // new functionality for monitoring on the document level\r
- //this.mon(btn, 'mouseout', this.onMouseOut, this);\r
- }\r
-\r
- if(this.menu){\r
- this.mon(this.menu, {\r
- scope: this,\r
- show: this.onMenuShow,\r
- hide: this.onMenuHide\r
- });\r
- }\r
-\r
- if(this.repeat){\r
- var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});\r
- this.mon(repeater, 'click', this.onClick, this);\r
- }\r
- this.mon(btn, this.clickEvent, this.onClick, this);\r
- },\r
-\r
- // private\r
- afterRender : function(){\r
- Ext.Button.superclass.afterRender.call(this);\r
- this.useSetClass = true;\r
- this.setButtonClass();\r
- this.doc = Ext.getDoc();\r
- this.doAutoWidth();\r
- },\r
-\r
- /**\r
- * Sets the CSS class that provides a background image to use as the button's icon. This method also changes\r
- * the value of the {@link iconCls} config internally.\r
- * @param {String} cls The CSS class providing the icon image\r
- * @return {Ext.Button} this\r
- */\r
- setIconClass : function(cls){\r
- this.iconCls = cls;\r
- if(this.el){\r
- this.btnEl.dom.className = '';\r
- this.btnEl.addClass(['x-btn-text', cls || '']);\r
- this.setButtonClass();\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Sets the tooltip for this Button.\r
- * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>\r
- * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>\r
- * <li><b>Object</b> : A configuration object for {@link Ext.QuickTips#register}.</li>\r
- * </ul></div>\r
- * @return {Ext.Button} this\r
- */\r
- setTooltip : function(tooltip, /* private */ initial){\r
- if(this.rendered){\r
- if(!initial){\r
- this.clearTip();\r
- }\r
- if(Ext.isObject(tooltip)){\r
- Ext.QuickTips.register(Ext.apply({\r
- target: this.btnEl.id\r
- }, tooltip));\r
- this.tooltip = tooltip;\r
- }else{\r
- this.btnEl.dom[this.tooltipType] = tooltip;\r
- }\r
- }else{\r
- this.tooltip = tooltip;\r
- }\r
- return this;\r
- },\r
-\r
- // private\r
- clearTip : function(){\r
- if(Ext.isObject(this.tooltip)){\r
- Ext.QuickTips.unregister(this.btnEl);\r
- }\r
- },\r
-\r
- // private\r
- beforeDestroy : function(){\r
- if(this.rendered){\r
- this.clearTip();\r
- }\r
- if(this.menu && this.destroyMenu !== false) {\r
- Ext.destroy(this.menu);\r
- }\r
- Ext.destroy(this.repeater);\r
- },\r
-\r
- // private\r
- onDestroy : function(){\r
- if(this.rendered){\r
- this.doc.un('mouseover', this.monitorMouseOver, this);\r
- this.doc.un('mouseup', this.onMouseUp, this);\r
- delete this.doc;\r
- delete this.btnEl;\r
- Ext.ButtonToggleMgr.unregister(this);\r
- }\r
- Ext.Button.superclass.onDestroy.call(this);\r
- },\r
-\r
- // private\r
- doAutoWidth : function(){\r
- if(this.el && this.text && this.width === undefined){\r
- this.el.setWidth('auto');\r
- if(Ext.isIE7 && Ext.isStrict){\r
- var ib = this.btnEl;\r
- if(ib && ib.getWidth() > 20){\r
- ib.clip();\r
- ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));\r
- }\r
- }\r
- if(this.minWidth){\r
- if(this.el.getWidth() < this.minWidth){\r
- this.el.setWidth(this.minWidth);\r
- }\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Assigns this Button's click handler\r
- * @param {Function} handler The function to call when the button is clicked\r
- * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.\r
- * Defaults to this Button.\r
- * @return {Ext.Button} this\r
- */\r
- setHandler : function(handler, scope){\r
- this.handler = handler;\r
- this.scope = scope;\r
- return this;\r
- },\r
-\r
- /**\r
- * Sets this Button's text\r
- * @param {String} text The button text\r
- * @return {Ext.Button} this\r
- */\r
- setText : function(text){\r
- this.text = text;\r
- if(this.el){\r
- this.btnEl.update(text || ' ');\r
- this.setButtonClass();\r
- }\r
- this.doAutoWidth();\r
- return this;\r
- },\r
-\r
- /**\r
- * Sets the background image (inline style) of the button. This method also changes\r
- * the value of the {@link icon} config internally.\r
- * @param {String} icon The path to an image to display in the button\r
- * @return {Ext.Button} this\r
- */\r
- setIcon : function(icon){\r
- this.icon = icon;\r
- if(this.el){\r
- this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');\r
- this.setButtonClass();\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Gets the text for this Button\r
- * @return {String} The button text\r
- */\r
- getText : function(){\r
- return this.text;\r
- },\r
-\r
- /**\r
- * If a state it passed, it becomes the pressed state otherwise the current state is toggled.\r
- * @param {Boolean} state (optional) Force a particular state\r
- * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.\r
- * @return {Ext.Button} this\r
- */\r
- toggle : function(state, suppressEvent){\r
- state = state === undefined ? !this.pressed : !!state;\r
- if(state != this.pressed){\r
- if(this.rendered){\r
- this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');\r
- }\r
- this.pressed = state;\r
- if(!suppressEvent){\r
- this.fireEvent('toggle', this, state);\r
- if(this.toggleHandler){\r
- this.toggleHandler.call(this.scope || this, this, state);\r
- }\r
- }\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Focus the button\r
- */\r
- focus : function(){\r
- this.btnEl.focus();\r
- },\r
-\r
- // private\r
- onDisable : function(){\r
- this.onDisableChange(true);\r
- },\r
-\r
- // private\r
- onEnable : function(){\r
- this.onDisableChange(false);\r
- },\r
-\r
- onDisableChange : function(disabled){\r
- if(this.el){\r
- if(!Ext.isIE6 || !this.text){\r
- this.el[disabled ? 'addClass' : 'removeClass'](this.disabledClass);\r
- }\r
- this.el.dom.disabled = disabled;\r
- }\r
- this.disabled = disabled;\r
- },\r
-\r
- /**\r
- * Show this button's menu (if it has one)\r
- */\r
- showMenu : function(){\r
- if(this.rendered && this.menu){\r
- if(this.tooltip){\r
- Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);\r
- }\r
- if(this.menu.isVisible()){\r
- this.menu.hide();\r
- }\r
- this.menu.ownerCt = this;\r
- this.menu.show(this.el, this.menuAlign);\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Hide this button's menu (if it has one)\r
- */\r
- hideMenu : function(){\r
- if(this.hasVisibleMenu()){\r
- this.menu.hide();\r
- }\r
- return this;\r
- },\r
-\r
- /**\r
- * Returns true if the button has a menu and it is visible\r
- * @return {Boolean}\r
- */\r
- hasVisibleMenu : function(){\r
- return this.menu && this.menu.ownerCt == this && this.menu.isVisible();\r
- },\r
-\r
- // private\r
- onClick : function(e){\r
- if(e){\r
- e.preventDefault();\r
- }\r
- if(e.button !== 0){\r
- return;\r
- }\r
- if(!this.disabled){\r
- if(this.enableToggle && (this.allowDepress !== false || !this.pressed)){\r
- this.toggle();\r
- }\r
- if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){\r
- this.showMenu();\r
- }\r
- this.fireEvent('click', this, e);\r
- if(this.handler){\r
- //this.el.removeClass('x-btn-over');\r
- this.handler.call(this.scope || this, this, e);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- isMenuTriggerOver : function(e, internal){\r
- return this.menu && !internal;\r
- },\r
-\r
- // private\r
- isMenuTriggerOut : function(e, internal){\r
- return this.menu && !internal;\r
- },\r
-\r
- // private\r
- onMouseOver : function(e){\r
- if(!this.disabled){\r
- var internal = e.within(this.el, true);\r
- if(!internal){\r
- this.el.addClass('x-btn-over');\r
- if(!this.monitoringMouseOver){\r
- this.doc.on('mouseover', this.monitorMouseOver, this);\r
- this.monitoringMouseOver = true;\r
- }\r
- this.fireEvent('mouseover', this, e);\r
- }\r
- if(this.isMenuTriggerOver(e, internal)){\r
- this.fireEvent('menutriggerover', this, this.menu, e);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- monitorMouseOver : function(e){\r
- if(e.target != this.el.dom && !e.within(this.el)){\r
- if(this.monitoringMouseOver){\r
- this.doc.un('mouseover', this.monitorMouseOver, this);\r
- this.monitoringMouseOver = false;\r
- }\r
- this.onMouseOut(e);\r
- }\r
- },\r
-\r
- // private\r
- onMouseOut : function(e){\r
- var internal = e.within(this.el) && e.target != this.el.dom;\r
- this.el.removeClass('x-btn-over');\r
- this.fireEvent('mouseout', this, e);\r
- if(this.isMenuTriggerOut(e, internal)){\r
- this.fireEvent('menutriggerout', this, this.menu, e);\r
- }\r
- },\r
-\r
- focus : function() {\r
- this.btnEl.focus();\r
- },\r
-\r
- blur : function() {\r
- this.btnEl.blur();\r
- },\r
-\r
- // private\r
- onFocus : function(e){\r
- if(!this.disabled){\r
- this.el.addClass('x-btn-focus');\r
- }\r
- },\r
- // private\r
- onBlur : function(e){\r
- this.el.removeClass('x-btn-focus');\r
- },\r
-\r
- // private\r
- getClickEl : function(e, isUp){\r
- return this.el;\r
- },\r
-\r
- // private\r
- onMouseDown : function(e){\r
- if(!this.disabled && e.button === 0){\r
- this.getClickEl(e).addClass('x-btn-click');\r
- this.doc.on('mouseup', this.onMouseUp, this);\r
- }\r
- },\r
- // private\r
- onMouseUp : function(e){\r
- if(e.button === 0){\r
- this.getClickEl(e, true).removeClass('x-btn-click');\r
- this.doc.un('mouseup', this.onMouseUp, this);\r
- }\r
- },\r
- // private\r
- onMenuShow : function(e){\r
- if(this.menu.ownerCt == this){\r
- this.menu.ownerCt = this;\r
- this.ignoreNextClick = 0;\r
- this.el.addClass('x-btn-menu-active');\r
- this.fireEvent('menushow', this, this.menu);\r
- }\r
- },\r
- // private\r
- onMenuHide : function(e){\r
- if(this.menu.ownerCt == this){\r
- this.el.removeClass('x-btn-menu-active');\r
- this.ignoreNextClick = this.restoreClick.defer(250, this);\r
- this.fireEvent('menuhide', this, this.menu);\r
- delete this.menu.ownerCt;\r
- }\r
- },\r
-\r
- // private\r
- restoreClick : function(){\r
- this.ignoreNextClick = 0;\r
- }\r
-\r
- /**\r
- * @cfg {String} autoEl @hide\r
- */\r
- /**\r
- * @cfg {String/Object} html @hide\r
- */\r
- /**\r
- * @cfg {String} contentEl @hide\r
- */\r
- /**\r
- * @cfg {Mixed} data @hide\r
- */\r
- /**\r
- * @cfg {Mixed} tpl @hide\r
- */\r
- /**\r
- * @cfg {String} tplWriteMode @hide\r
- */\r
-});\r
-Ext.reg('button', Ext.Button);\r
-\r
-// Private utility class used by Button\r
-Ext.ButtonToggleMgr = function(){\r
- var groups = {};\r
-\r
- function toggleGroup(btn, state){\r
- if(state){\r
- var g = groups[btn.toggleGroup];\r
- for(var i = 0, l = g.length; i < l; i++){\r
- if(g[i] != btn){\r
- g[i].toggle(false);\r
- }\r
- }\r
- }\r
- }\r
-\r
- return {\r
- register : function(btn){\r
- if(!btn.toggleGroup){\r
- return;\r
- }\r
- var g = groups[btn.toggleGroup];\r
- if(!g){\r
- g = groups[btn.toggleGroup] = [];\r
- }\r
- g.push(btn);\r
- btn.on('toggle', toggleGroup);\r
- },\r
-\r
- unregister : function(btn){\r
- if(!btn.toggleGroup){\r
- return;\r
- }\r
- var g = groups[btn.toggleGroup];\r
- if(g){\r
- g.remove(btn);\r
- btn.un('toggle', toggleGroup);\r
- }\r
- },\r
-\r
- /**\r
- * Gets the pressed button in the passed group or null\r
- * @param {String} group\r
- * @return Button\r
- */\r
- getPressed : function(group){\r
- var g = groups[group];\r
- if(g){\r
- for(var i = 0, len = g.length; i < len; i++){\r
- if(g[i].pressed === true){\r
- return g[i];\r
- }\r
- }\r
- }\r
- return null;\r
- }\r
- };\r
-}();\r
-</pre> \r
-</body>\r
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>The source code</title>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+</head>
+<body onload="prettyPrint();">
+ <pre class="prettyprint lang-js">/*!
+ * Ext JS Library 3.3.1
+ * Copyright(c) 2006-2010 Sencha Inc.
+ * licensing@sencha.com
+ * http://www.sencha.com/license
+ */
+<div id="cls-Ext.Button"></div>/**
+ * @class Ext.Button
+ * @extends Ext.BoxComponent
+ * Simple Button class
+ * @cfg {String} text The button text to be used as innerHTML (html tags are accepted)
+ * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
+ * CSS property of the button by default, so if you want a mixed icon/text button, set cls:'x-btn-text-icon')
+ * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event).
+ * The handler is passed the following parameters:<div class="mdetail-params"><ul>
+ * <li><code>b</code> : Button<div class="sub-desc">This Button.</div></li>
+ * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
+ * </ul></div>
+ * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width).
+ * See also {@link Ext.Panel}.<tt>{@link Ext.Panel#minButtonWidth minButtonWidth}</tt>.
+ * @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
+ * @cfg {Boolean} hidden True to start hidden (defaults to false)
+ * @cfg {Boolean} disabled True to start disabled (defaults to false)
+ * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
+ * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed)
+ * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
+ * a {@link Ext.util.ClickRepeater ClickRepeater} config object (defaults to false).
+ * @constructor
+ * Create a new button
+ * @param {Object} config The config object
+ * @xtype button
+ */
+Ext.Button = Ext.extend(Ext.BoxComponent, {
+ /**
+ * Read-only. True if this button is hidden
+ * @type Boolean
+ */
+ hidden : false,
+ /**
+ * Read-only. True if this button is disabled
+ * @type Boolean
+ */
+ disabled : false,
+ /**
+ * Read-only. True if this button is pressed (only if enableToggle = true)
+ * @type Boolean
+ */
+ pressed : false,
+
+ /**
+ * @cfg {Number} tabIndex Set a DOM tabIndex for this button (defaults to undefined)
+ */
+
+ /**
+ * @cfg {Boolean} allowDepress
+ * False to not allow a pressed Button to be depressed (defaults to undefined). Only valid when {@link #enableToggle} is true.
+ */
+
+ /**
+ * @cfg {Boolean} enableToggle
+ * True to enable pressed/not pressed toggling (defaults to false)
+ */
+ enableToggle : false,
+ /**
+ * @cfg {Function} toggleHandler
+ * Function called when a Button with {@link #enableToggle} set to true is clicked. Two arguments are passed:<ul class="mdetail-params">
+ * <li><b>button</b> : Ext.Button<div class="sub-desc">this Button object</div></li>
+ * <li><b>state</b> : Boolean<div class="sub-desc">The next state of the Button, true means pressed.</div></li>
+ * </ul>
+ */
+ /**
+ * @cfg {Mixed} menu
+ * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
+ */
+ /**
+ * @cfg {String} menuAlign
+ * The position to align the menu to (see {@link Ext.Element#alignTo} for more details, defaults to 'tl-bl?').
+ */
+ menuAlign : 'tl-bl?',
+
+ /**
+ * @cfg {String} overflowText If used in a {@link Ext.Toolbar Toolbar}, the
+ * text to be used if this item is shown in the overflow menu. See also
+ * {@link Ext.Toolbar.Item}.<code>{@link Ext.Toolbar.Item#overflowText overflowText}</code>.
+ */
+ /**
+ * @cfg {String} iconCls
+ * A css class which sets a background image to be used as the icon for this button
+ */
+ /**
+ * @cfg {String} type
+ * submit, reset or button - defaults to 'button'
+ */
+ type : 'button',
+
+ // private
+ menuClassTarget : 'tr:nth(2)',
+
+ /**
+ * @cfg {String} clickEvent
+ * The DOM event that will fire the handler of the button. This can be any valid event name (dblclick, contextmenu).
+ * Defaults to <tt>'click'</tt>.
+ */
+ clickEvent : 'click',
+
+ /**
+ * @cfg {Boolean} handleMouseEvents
+ * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
+ */
+ handleMouseEvents : true,
+
+ /**
+ * @cfg {String} tooltipType
+ * The type of tooltip to use. Either 'qtip' (default) for QuickTips or 'title' for title attribute.
+ */
+ tooltipType : 'qtip',
+
+ /**
+ * @cfg {String} buttonSelector
+ * <p>(Optional) A {@link Ext.DomQuery DomQuery} selector which is used to extract the active, clickable element from the
+ * DOM structure created.</p>
+ * <p>When a custom {@link #template} is used, you must ensure that this selector results in the selection of
+ * a focussable element.</p>
+ * <p>Defaults to <b><tt>'button:first-child'</tt></b>.</p>
+ */
+ buttonSelector : 'button:first-child',
+
+ /**
+ * @cfg {String} scale
+ * <p>(Optional) The size of the Button. Three values are allowed:</p>
+ * <ul class="mdetail-params">
+ * <li>'small'<div class="sub-desc">Results in the button element being 16px high.</div></li>
+ * <li>'medium'<div class="sub-desc">Results in the button element being 24px high.</div></li>
+ * <li>'large'<div class="sub-desc">Results in the button element being 32px high.</div></li>
+ * </ul>
+ * <p>Defaults to <b><tt>'small'</tt></b>.</p>
+ */
+ scale : 'small',
+
+ /**
+ * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the
+ * <code>{@link #handler}</code> and <code>{@link #toggleHandler}</code> is
+ * executed. Defaults to this Button.
+ */
+
+ /**
+ * @cfg {String} iconAlign
+ * <p>(Optional) The side of the Button box to render the icon. Four values are allowed:</p>
+ * <ul class="mdetail-params">
+ * <li>'top'<div class="sub-desc"></div></li>
+ * <li>'right'<div class="sub-desc"></div></li>
+ * <li>'bottom'<div class="sub-desc"></div></li>
+ * <li>'left'<div class="sub-desc"></div></li>
+ * </ul>
+ * <p>Defaults to <b><tt>'left'</tt></b>.</p>
+ */
+ iconAlign : 'left',
+
+ /**
+ * @cfg {String} arrowAlign
+ * <p>(Optional) The side of the Button box to render the arrow if the button has an associated {@link #menu}.
+ * Two values are allowed:</p>
+ * <ul class="mdetail-params">
+ * <li>'right'<div class="sub-desc"></div></li>
+ * <li>'bottom'<div class="sub-desc"></div></li>
+ * </ul>
+ * <p>Defaults to <b><tt>'right'</tt></b>.</p>
+ */
+ arrowAlign : 'right',
+
+ /**
+ * @cfg {Ext.Template} template (Optional)
+ * <p>A {@link Ext.Template Template} used to create the Button's DOM structure.</p>
+ * Instances, or subclasses which need a different DOM structure may provide a different
+ * template layout in conjunction with an implementation of {@link #getTemplateArgs}.
+ * @type Ext.Template
+ * @property template
+ */
+ /**
+ * @cfg {String} cls
+ * A CSS class string to apply to the button's main element.
+ */
+ /**
+ * @property menu
+ * @type Menu
+ * The {@link Ext.menu.Menu Menu} object associated with this Button when configured with the {@link #menu} config option.
+ */
+ /**
+ * @cfg {Boolean} autoWidth
+ * By default, if a width is not specified the button will attempt to stretch horizontally to fit its content.
+ * If the button is being managed by a width sizing layout (hbox, fit, anchor), set this to false to prevent
+ * the button from doing this automatic sizing.
+ * Defaults to <tt>undefined</tt>.
+ */
+
+ initComponent : function(){
+ if(this.menu){
+ this.menu = Ext.menu.MenuMgr.get(this.menu);
+ this.menu.ownerCt = this;
+ }
+
+ Ext.Button.superclass.initComponent.call(this);
+
+ this.addEvents(
+ /**
+ * @event click
+ * Fires when this button is clicked
+ * @param {Button} this
+ * @param {EventObject} e The click event
+ */
+ 'click',
+ /**
+ * @event toggle
+ * Fires when the 'pressed' state of this button changes (only if enableToggle = true)
+ * @param {Button} this
+ * @param {Boolean} pressed
+ */
+ 'toggle',
+ /**
+ * @event mouseover
+ * Fires when the mouse hovers over the button
+ * @param {Button} this
+ * @param {Event} e The event object
+ */
+ 'mouseover',
+ /**
+ * @event mouseout
+ * Fires when the mouse exits the button
+ * @param {Button} this
+ * @param {Event} e The event object
+ */
+ 'mouseout',
+ /**
+ * @event menushow
+ * If this button has a menu, this event fires when it is shown
+ * @param {Button} this
+ * @param {Menu} menu
+ */
+ 'menushow',
+ /**
+ * @event menuhide
+ * If this button has a menu, this event fires when it is hidden
+ * @param {Button} this
+ * @param {Menu} menu
+ */
+ 'menuhide',
+ /**
+ * @event menutriggerover
+ * If this button has a menu, this event fires when the mouse enters the menu triggering element
+ * @param {Button} this
+ * @param {Menu} menu
+ * @param {EventObject} e
+ */
+ 'menutriggerover',
+ /**
+ * @event menutriggerout
+ * If this button has a menu, this event fires when the mouse leaves the menu triggering element
+ * @param {Button} this
+ * @param {Menu} menu
+ * @param {EventObject} e
+ */
+ 'menutriggerout'
+ );
+
+ if (this.menu){
+ this.menu.ownerCt = undefined;
+ }
+ if(Ext.isString(this.toggleGroup)){
+ this.enableToggle = true;
+ }
+ },
+
+/**
+ * <p>This method returns an Array which provides substitution parameters for the {@link #template Template} used
+ * to create this Button's DOM structure.</p>
+ * <p>Instances or subclasses which use a different Template to create a different DOM structure may need to provide their
+ * own implementation of this method.</p>
+ * <p>The default implementation which provides data for the default {@link #template} returns an Array containing the
+ * following items:</p><div class="mdetail-params"><ul>
+ * <li>The <button>'s {@link #type}</li>
+ * <li>A CSS class name applied to the Button's main <tbody> element which determines the button's scale and icon alignment.</li>
+ * <li>A CSS class to determine the presence and position of an arrow icon. (<code>'x-btn-arrow'</code> or <code>'x-btn-arrow-bottom'</code> or <code>''</code>)</li>
+ * <li>The {@link #cls} CSS class name applied to the button's wrapping <table> element.</li>
+ * <li>The Component id which is applied to the button's wrapping <table> element.</li>
+ * </ul></div>
+ * @return {Array} Substitution data for a Template.
+ */
+ getTemplateArgs : function(){
+ return [this.type, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];
+ },
+
+ // private
+ setButtonClass : function(){
+ if(this.useSetClass){
+ if(!Ext.isEmpty(this.oldCls)){
+ this.el.removeClass([this.oldCls, 'x-btn-pressed']);
+ }
+ this.oldCls = (this.iconCls || this.icon) ? (this.text ? 'x-btn-text-icon' : 'x-btn-icon') : 'x-btn-noicon';
+ this.el.addClass([this.oldCls, this.pressed ? 'x-btn-pressed' : null]);
+ }
+ },
+
+ // protected
+ getMenuClass : function(){
+ return this.menu ? (this.arrowAlign != 'bottom' ? 'x-btn-arrow' : 'x-btn-arrow-bottom') : '';
+ },
+
+ // private
+ onRender : function(ct, position){
+ if(!this.template){
+ if(!Ext.Button.buttonTemplate){
+ // hideous table template
+ Ext.Button.buttonTemplate = new Ext.Template(
+ '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
+ '<tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr>',
+ '<tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr"><i> </i></td></tr>',
+ '<tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr>',
+ '</tbody></table>');
+ Ext.Button.buttonTemplate.compile();
+ }
+ this.template = Ext.Button.buttonTemplate;
+ }
+
+ var btn, targs = this.getTemplateArgs();
+
+ if(position){
+ btn = this.template.insertBefore(position, targs, true);
+ }else{
+ btn = this.template.append(ct, targs, true);
+ }
+ /**
+ * An {@link Ext.Element Element} encapsulating the Button's clickable element. By default,
+ * this references a <tt><button></tt> element. Read only.
+ * @type Ext.Element
+ * @property btnEl
+ */
+ this.btnEl = btn.child(this.buttonSelector);
+ this.mon(this.btnEl, {
+ scope: this,
+ focus: this.onFocus,
+ blur: this.onBlur
+ });
+
+ this.initButtonEl(btn, this.btnEl);
+
+ Ext.ButtonToggleMgr.register(this);
+ },
+
+ // private
+ initButtonEl : function(btn, btnEl){
+ this.el = btn;
+ this.setIcon(this.icon);
+ this.setText(this.text);
+ this.setIconClass(this.iconCls);
+ if(Ext.isDefined(this.tabIndex)){
+ btnEl.dom.tabIndex = this.tabIndex;
+ }
+ if(this.tooltip){
+ this.setTooltip(this.tooltip, true);
+ }
+
+ if(this.handleMouseEvents){
+ this.mon(btn, {
+ scope: this,
+ mouseover: this.onMouseOver,
+ mousedown: this.onMouseDown
+ });
+
+ // new functionality for monitoring on the document level
+ //this.mon(btn, 'mouseout', this.onMouseOut, this);
+ }
+
+ if(this.menu){
+ this.mon(this.menu, {
+ scope: this,
+ show: this.onMenuShow,
+ hide: this.onMenuHide
+ });
+ }
+
+ if(this.repeat){
+ var repeater = new Ext.util.ClickRepeater(btn, Ext.isObject(this.repeat) ? this.repeat : {});
+ this.mon(repeater, 'click', this.onRepeatClick, this);
+ }else{
+ this.mon(btn, this.clickEvent, this.onClick, this);
+ }
+ },
+
+ // private
+ afterRender : function(){
+ Ext.Button.superclass.afterRender.call(this);
+ this.useSetClass = true;
+ this.setButtonClass();
+ this.doc = Ext.getDoc();
+ this.doAutoWidth();
+ },
+
+ /**
+ * Sets the CSS class that provides a background image to use as the button's icon. This method also changes
+ * the value of the {@link iconCls} config internally.
+ * @param {String} cls The CSS class providing the icon image
+ * @return {Ext.Button} this
+ */
+ setIconClass : function(cls){
+ this.iconCls = cls;
+ if(this.el){
+ this.btnEl.dom.className = '';
+ this.btnEl.addClass(['x-btn-text', cls || '']);
+ this.setButtonClass();
+ }
+ return this;
+ },
+
+ /**
+ * Sets the tooltip for this Button.
+ * @param {String/Object} tooltip. This may be:<div class="mdesc-details"><ul>
+ * <li><b>String</b> : A string to be used as innerHTML (html tags are accepted) to show in a tooltip</li>
+ * <li><b>Object</b> : A configuration object for {@link Ext.QuickTips#register}.</li>
+ * </ul></div>
+ * @return {Ext.Button} this
+ */
+ setTooltip : function(tooltip, /* private */ initial){
+ if(this.rendered){
+ if(!initial){
+ this.clearTip();
+ }
+ if(Ext.isObject(tooltip)){
+ Ext.QuickTips.register(Ext.apply({
+ target: this.btnEl.id
+ }, tooltip));
+ this.tooltip = tooltip;
+ }else{
+ this.btnEl.dom[this.tooltipType] = tooltip;
+ }
+ }else{
+ this.tooltip = tooltip;
+ }
+ return this;
+ },
+
+ // private
+ clearTip : function(){
+ if(Ext.isObject(this.tooltip)){
+ Ext.QuickTips.unregister(this.btnEl);
+ }
+ },
+
+ // private
+ beforeDestroy : function(){
+ if(this.rendered){
+ this.clearTip();
+ }
+ if(this.menu && this.destroyMenu !== false) {
+ Ext.destroy(this.btnEl, this.menu);
+ }
+ Ext.destroy(this.repeater);
+ },
+
+ // private
+ onDestroy : function(){
+ if(this.rendered){
+ this.doc.un('mouseover', this.monitorMouseOver, this);
+ this.doc.un('mouseup', this.onMouseUp, this);
+ delete this.doc;
+ delete this.btnEl;
+ Ext.ButtonToggleMgr.unregister(this);
+ }
+ Ext.Button.superclass.onDestroy.call(this);
+ },
+
+ // private
+ doAutoWidth : function(){
+ if(this.autoWidth !== false && this.el && this.text && this.width === undefined){
+ this.el.setWidth('auto');
+ if(Ext.isIE7 && Ext.isStrict){
+ var ib = this.btnEl;
+ if(ib && ib.getWidth() > 20){
+ ib.clip();
+ ib.setWidth(Ext.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
+ }
+ }
+ if(this.minWidth){
+ if(this.el.getWidth() < this.minWidth){
+ this.el.setWidth(this.minWidth);
+ }
+ }
+ }
+ },
+
+ /**
+ * Assigns this Button's click handler
+ * @param {Function} handler The function to call when the button is clicked
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
+ * Defaults to this Button.
+ * @return {Ext.Button} this
+ */
+ setHandler : function(handler, scope){
+ this.handler = handler;
+ this.scope = scope;
+ return this;
+ },
+
+ /**
+ * Sets this Button's text
+ * @param {String} text The button text
+ * @return {Ext.Button} this
+ */
+ setText : function(text){
+ this.text = text;
+ if(this.el){
+ this.btnEl.update(text || ' ');
+ this.setButtonClass();
+ }
+ this.doAutoWidth();
+ return this;
+ },
+
+ /**
+ * Sets the background image (inline style) of the button. This method also changes
+ * the value of the {@link icon} config internally.
+ * @param {String} icon The path to an image to display in the button
+ * @return {Ext.Button} this
+ */
+ setIcon : function(icon){
+ this.icon = icon;
+ if(this.el){
+ this.btnEl.setStyle('background-image', icon ? 'url(' + icon + ')' : '');
+ this.setButtonClass();
+ }
+ return this;
+ },
+
+ /**
+ * Gets the text for this Button
+ * @return {String} The button text
+ */
+ getText : function(){
+ return this.text;
+ },
+
+ /**
+ * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
+ * @param {Boolean} state (optional) Force a particular state
+ * @param {Boolean} supressEvent (optional) True to stop events being fired when calling this method.
+ * @return {Ext.Button} this
+ */
+ toggle : function(state, suppressEvent){
+ state = state === undefined ? !this.pressed : !!state;
+ if(state != this.pressed){
+ if(this.rendered){
+ this.el[state ? 'addClass' : 'removeClass']('x-btn-pressed');
+ }
+ this.pressed = state;
+ if(!suppressEvent){
+ this.fireEvent('toggle', this, state);
+ if(this.toggleHandler){
+ this.toggleHandler.call(this.scope || this, this, state);
+ }
+ }
+ }
+ return this;
+ },
+
+ // private
+ onDisable : function(){
+ this.onDisableChange(true);
+ },
+
+ // private
+ onEnable : function(){
+ this.onDisableChange(false);
+ },
+
+ onDisableChange : function(disabled){
+ if(this.el){
+ if(!Ext.isIE6 || !this.text){
+ this.el[disabled ? 'addClass' : 'removeClass'](this.disabledClass);
+ }
+ this.el.dom.disabled = disabled;
+ }
+ this.disabled = disabled;
+ },
+
+ /**
+ * Show this button's menu (if it has one)
+ */
+ showMenu : function(){
+ if(this.rendered && this.menu){
+ if(this.tooltip){
+ Ext.QuickTips.getQuickTip().cancelShow(this.btnEl);
+ }
+ if(this.menu.isVisible()){
+ this.menu.hide();
+ }
+ this.menu.ownerCt = this;
+ this.menu.show(this.el, this.menuAlign);
+ }
+ return this;
+ },
+
+ /**
+ * Hide this button's menu (if it has one)
+ */
+ hideMenu : function(){
+ if(this.hasVisibleMenu()){
+ this.menu.hide();
+ }
+ return this;
+ },
+
+ /**
+ * Returns true if the button has a menu and it is visible
+ * @return {Boolean}
+ */
+ hasVisibleMenu : function(){
+ return this.menu && this.menu.ownerCt == this && this.menu.isVisible();
+ },
+
+ // private
+ onRepeatClick : function(repeat, e){
+ this.onClick(e);
+ },
+
+ // private
+ onClick : function(e){
+ if(e){
+ e.preventDefault();
+ }
+ if(e.button !== 0){
+ return;
+ }
+ if(!this.disabled){
+ this.doToggle();
+ if(this.menu && !this.hasVisibleMenu() && !this.ignoreNextClick){
+ this.showMenu();
+ }
+ this.fireEvent('click', this, e);
+ if(this.handler){
+ //this.el.removeClass('x-btn-over');
+ this.handler.call(this.scope || this, this, e);
+ }
+ }
+ },
+
+ // private
+ doToggle: function(){
+ if (this.enableToggle && (this.allowDepress !== false || !this.pressed)) {
+ this.toggle();
+ }
+ },
+
+ // private
+ isMenuTriggerOver : function(e, internal){
+ return this.menu && !internal;
+ },
+
+ // private
+ isMenuTriggerOut : function(e, internal){
+ return this.menu && !internal;
+ },
+
+ // private
+ onMouseOver : function(e){
+ if(!this.disabled){
+ var internal = e.within(this.el, true);
+ if(!internal){
+ this.el.addClass('x-btn-over');
+ if(!this.monitoringMouseOver){
+ this.doc.on('mouseover', this.monitorMouseOver, this);
+ this.monitoringMouseOver = true;
+ }
+ this.fireEvent('mouseover', this, e);
+ }
+ if(this.isMenuTriggerOver(e, internal)){
+ this.fireEvent('menutriggerover', this, this.menu, e);
+ }
+ }
+ },
+
+ // private
+ monitorMouseOver : function(e){
+ if(e.target != this.el.dom && !e.within(this.el)){
+ if(this.monitoringMouseOver){
+ this.doc.un('mouseover', this.monitorMouseOver, this);
+ this.monitoringMouseOver = false;
+ }
+ this.onMouseOut(e);
+ }
+ },
+
+ // private
+ onMouseOut : function(e){
+ var internal = e.within(this.el) && e.target != this.el.dom;
+ this.el.removeClass('x-btn-over');
+ this.fireEvent('mouseout', this, e);
+ if(this.isMenuTriggerOut(e, internal)){
+ this.fireEvent('menutriggerout', this, this.menu, e);
+ }
+ },
+
+ focus : function() {
+ this.btnEl.focus();
+ },
+
+ blur : function() {
+ this.btnEl.blur();
+ },
+
+ // private
+ onFocus : function(e){
+ if(!this.disabled){
+ this.el.addClass('x-btn-focus');
+ }
+ },
+ // private
+ onBlur : function(e){
+ this.el.removeClass('x-btn-focus');
+ },
+
+ // private
+ getClickEl : function(e, isUp){
+ return this.el;
+ },
+
+ // private
+ onMouseDown : function(e){
+ if(!this.disabled && e.button === 0){
+ this.getClickEl(e).addClass('x-btn-click');
+ this.doc.on('mouseup', this.onMouseUp, this);
+ }
+ },
+ // private
+ onMouseUp : function(e){
+ if(e.button === 0){
+ this.getClickEl(e, true).removeClass('x-btn-click');
+ this.doc.un('mouseup', this.onMouseUp, this);
+ }
+ },
+ // private
+ onMenuShow : function(e){
+ if(this.menu.ownerCt == this){
+ this.menu.ownerCt = this;
+ this.ignoreNextClick = 0;
+ this.el.addClass('x-btn-menu-active');
+ this.fireEvent('menushow', this, this.menu);
+ }
+ },
+ // private
+ onMenuHide : function(e){
+ if(this.menu.ownerCt == this){
+ this.el.removeClass('x-btn-menu-active');
+ this.ignoreNextClick = this.restoreClick.defer(250, this);
+ this.fireEvent('menuhide', this, this.menu);
+ delete this.menu.ownerCt;
+ }
+ },
+
+ // private
+ restoreClick : function(){
+ this.ignoreNextClick = 0;
+ }
+
+ /**
+ * @cfg {String} autoEl @hide
+ */
+ /**
+ * @cfg {String/Object} html @hide
+ */
+ /**
+ * @cfg {String} contentEl @hide
+ */
+ /**
+ * @cfg {Mixed} data @hide
+ */
+ /**
+ * @cfg {Mixed} tpl @hide
+ */
+ /**
+ * @cfg {String} tplWriteMode @hide
+ */
+});
+Ext.reg('button', Ext.Button);
+
+// Private utility class used by Button
+Ext.ButtonToggleMgr = function(){
+ var groups = {};
+
+ function toggleGroup(btn, state){
+ if(state){
+ var g = groups[btn.toggleGroup];
+ for(var i = 0, l = g.length; i < l; i++){
+ if(g[i] != btn){
+ g[i].toggle(false);
+ }
+ }
+ }
+ }
+
+ return {
+ register : function(btn){
+ if(!btn.toggleGroup){
+ return;
+ }
+ var g = groups[btn.toggleGroup];
+ if(!g){
+ g = groups[btn.toggleGroup] = [];
+ }
+ g.push(btn);
+ btn.on('toggle', toggleGroup);
+ },
+
+ unregister : function(btn){
+ if(!btn.toggleGroup){
+ return;
+ }
+ var g = groups[btn.toggleGroup];
+ if(g){
+ g.remove(btn);
+ btn.un('toggle', toggleGroup);
+ }
+ },
+
+ /**
+ * Gets the pressed button in the passed group or null
+ * @param {String} group
+ * @return Button
+ */
+ getPressed : function(group){
+ var g = groups[group];
+ if(g){
+ for(var i = 0, len = g.length; i < len; i++){
+ if(g[i].pressed === true){
+ return g[i];
+ }
+ }
+ }
+ return null;
+ }
+ };
+}();
+</pre>
+</body>