Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / widgets / Button.js
diff --git a/source/widgets/Button.js b/source/widgets/Button.js
deleted file mode 100644 (file)
index 9d89324..0000000
+++ /dev/null
@@ -1,635 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-\r
-/**\r
- * @class Ext.Button\r
- * @extends Ext.Component\r
- * Simple Button class\r
- * @cfg {String} text The button text\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
- * @cfg {Object} scope The scope of the handler\r
- * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)\r
- * @cfg {String/Object} tooltip The tooltip for the button - can be a string 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
-  an {@link Ext.util.ClickRepeater} config object (defaults to false).\r
- * @constructor\r
- * Create a new button\r
- * @param {Object} config The config object\r
- */\r
-Ext.Button = Ext.extend(Ext.Component, {\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
-     * The Button's owner {@link Ext.Panel} (defaults to undefined, and is set automatically when\r
-     * the Button is added to a container).  Read-only.\r
-     * @type Ext.Panel\r
-     * @property ownerCt\r
-     */\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 if 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} 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',\r
-\r
-    /**\r
-     * @cfg {String} clickEvent\r
-     * The type of event to map to the button's event handler (defaults to 'click')\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 {Ext.Template} template\r
-     * (Optional) An {@link Ext.Template} with which to create the Button's main element. This Template must\r
-     * contain numeric substitution parameter 0 if it is to display the text property. Changing the template could\r
-     * require code modifications if required elements (e.g. a button) aren't present.\r
-     */\r
-    /**\r
-     * @cfg {String} cls\r
-     * A CSS class string to apply to the button's main element.\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(typeof this.toggleGroup === 'string'){\r
-            this.enableToggle = true;\r
-        }\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 border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',\r
-                    '<td class="x-btn-left"><i>&#160;</i></td><td class="x-btn-center"><em unselectable="on"><button class="x-btn-text" type="{1}">{0}</button></em></td><td class="x-btn-right"><i>&#160;</i></td>',\r
-                    "</tr></tbody></table>");\r
-            }\r
-            this.template = Ext.Button.buttonTemplate;\r
-        }\r
-        var btn, targs = [this.text || '&#160;', this.type];\r
-\r
-        if(position){\r
-            btn = this.template.insertBefore(position, targs, true);\r
-        }else{\r
-            btn = this.template.append(ct, targs, true);\r
-        }\r
-        var btnEl = btn.child(this.buttonSelector);\r
-        btnEl.on('focus', this.onFocus, this);\r
-        btnEl.on('blur', this.onBlur, this);\r
-\r
-        this.initButtonEl(btn, btnEl);\r
-\r
-        if(this.menu){\r
-            this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");\r
-        }\r
-        Ext.ButtonToggleMgr.register(this);\r
-    },\r
-\r
-    // private\r
-    initButtonEl : function(btn, btnEl){\r
-\r
-        this.el = btn;\r
-        btn.addClass("x-btn");\r
-\r
-        if(this.id){\r
-            this.el.dom.id = this.el.id = this.id;\r
-        }\r
-        if(this.icon){\r
-            btnEl.setStyle('background-image', 'url(' +this.icon +')');\r
-        }\r
-        if(this.iconCls){\r
-            btnEl.addClass(this.iconCls);\r
-            if(!this.cls){\r
-                btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');\r
-            }\r
-        }\r
-        if(this.tabIndex !== undefined){\r
-            btnEl.dom.tabIndex = this.tabIndex;\r
-        }\r
-        if(this.tooltip){\r
-            if(typeof this.tooltip == 'object'){\r
-                Ext.QuickTips.register(Ext.apply({\r
-                      target: btnEl.id\r
-                }, this.tooltip));\r
-            } else {\r
-                btnEl.dom[this.tooltipType] = this.tooltip;\r
-            }\r
-        }\r
-\r
-        if(this.pressed){\r
-            this.el.addClass("x-btn-pressed");\r
-        }\r
-\r
-        if(this.handleMouseEvents){\r
-            btn.on("mouseover", this.onMouseOver, this);\r
-            // new functionality for monitoring on the document level\r
-            //btn.on("mouseout", this.onMouseOut, this);\r
-            btn.on("mousedown", this.onMouseDown, this);\r
-        }\r
-\r
-        if(this.menu){\r
-            this.menu.on("show", this.onMenuShow, this);\r
-            this.menu.on("hide", this.onMenuHide, this);\r
-        }\r
-\r
-        if(this.repeat){\r
-            var repeater = new Ext.util.ClickRepeater(btn,\r
-                typeof this.repeat == "object" ? this.repeat : {}\r
-            );\r
-            repeater.on("click", this.onClick,  this);\r
-        }\r
-\r
-        btn.on(this.clickEvent, this.onClick, this);\r
-    },\r
-\r
-    // private\r
-    afterRender : function(){\r
-        Ext.Button.superclass.afterRender.call(this);\r
-        if(Ext.isIE6){\r
-            this.autoWidth.defer(1, this);\r
-        }else{\r
-            this.autoWidth();\r
-        }\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
-     */\r
-    setIconClass : function(cls){\r
-        if(this.el){\r
-            this.el.child(this.buttonSelector).replaceClass(this.iconCls, cls);\r
-        }\r
-        this.iconCls = cls;\r
-    },\r
-\r
-    // private\r
-    beforeDestroy: function(){\r
-       if(this.rendered){\r
-            var btnEl = this.el.child(this.buttonSelector);\r
-            if(btnEl){\r
-                if(this.tooltip){\r
-                    Ext.QuickTips.unregister(btnEl);\r
-                }\r
-                btnEl.removeAllListeners();\r
-            }\r
-           }\r
-        if(this.menu){\r
-            Ext.destroy(this.menu);\r
-        }\r
-    },\r
-\r
-    // private\r
-    onDestroy : function(){\r
-        if(this.rendered){\r
-            Ext.ButtonToggleMgr.unregister(this);\r
-        }\r
-    },\r
-\r
-    // private\r
-    autoWidth : function(){\r
-        if(this.el){\r
-            this.el.setWidth("auto");\r
-            if(Ext.isIE7 && Ext.isStrict){\r
-                var ib = this.el.child(this.buttonSelector);\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) Scope for the function passed in\r
-     */\r
-    setHandler : function(handler, scope){\r
-        this.handler = handler;\r
-        this.scope = scope;\r
-    },\r
-\r
-    /**\r
-     * Sets this button's text\r
-     * @param {String} text The button text\r
-     */\r
-    setText : function(text){\r
-        this.text = text;\r
-        if(this.el){\r
-            this.el.child("td.x-btn-center " + this.buttonSelector).update(text);\r
-        }\r
-        this.autoWidth();\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
-     */\r
-    toggle : function(state){\r
-        state = state === undefined ? !this.pressed : state;\r
-        if(state != this.pressed){\r
-            if(state){\r
-                this.el.addClass("x-btn-pressed");\r
-                this.pressed = true;\r
-                this.fireEvent("toggle", this, true);\r
-            }else{\r
-                this.el.removeClass("x-btn-pressed");\r
-                this.pressed = false;\r
-                this.fireEvent("toggle", this, false);\r
-            }\r
-            if(this.toggleHandler){\r
-                this.toggleHandler.call(this.scope || this, this, state);\r
-            }\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Focus the button\r
-     */\r
-    focus : function(){\r
-        this.el.child(this.buttonSelector).focus();\r
-    },\r
-\r
-    // private\r
-    onDisable : function(){\r
-        if(this.el){\r
-            if(!Ext.isIE6 || !this.text){\r
-                this.el.addClass(this.disabledClass);\r
-            }\r
-            this.el.dom.disabled = true;\r
-        }\r
-        this.disabled = true;\r
-    },\r
-\r
-    // private\r
-    onEnable : function(){\r
-        if(this.el){\r
-            if(!Ext.isIE6 || !this.text){\r
-                this.el.removeClass(this.disabledClass);\r
-            }\r
-            this.el.dom.disabled = false;\r
-        }\r
-        this.disabled = false;\r
-    },\r
-\r
-    /**\r
-     * Show this button's menu (if it has one)\r
-     */\r
-    showMenu : function(){\r
-        if(this.menu){\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.menu){\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.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.menu.isVisible() && !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
-                    Ext.getDoc().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
-                Ext.getDoc().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
-    // 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
-            Ext.getDoc().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
-            Ext.getDoc().un('mouseup', this.onMouseUp, this);\r
-        }\r
-    },\r
-    // private\r
-    onMenuShow : function(e){\r
-        this.ignoreNextClick = 0;\r
-        this.el.addClass("x-btn-menu-active");\r
-        this.fireEvent('menushow', this, this.menu);\r
-    },\r
-    // private\r
-    onMenuHide : function(e){\r
-        this.el.removeClass("x-btn-menu-active");\r
-        this.ignoreNextClick = this.restoreClick.defer(250, this);\r
-        this.fireEvent('menuhide', this, this.menu);\r
-    },\r
-\r
-    // private\r
-    restoreClick : function(){\r
-        this.ignoreNextClick = 0;\r
-    }\r
-\r
-\r
-\r
-    /**\r
-     * @cfg {String} autoEl @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
-}();
\ No newline at end of file