3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.SplitButton
10 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
11 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
12 * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
14 // display a dropdown menu:
16 renderTo: 'button-ct', // the container id
18 handler: optionsHandler, // handle a click on the button itself
19 menu: new Ext.menu.Menu({
21 // these items will render as dropdown menu items when the arrow is clicked:
22 {text: 'Item 1', handler: item1Handler},
23 {text: 'Item 2', handler: item2Handler}
28 // Instead of showing a menu, you provide any type of custom
29 // functionality you want when the dropdown arrow is clicked:
31 renderTo: 'button-ct',
33 handler: optionsHandler,
34 arrowHandler: myCustomHandler
37 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
38 * @cfg {String} arrowTooltip The title attribute of the arrow
40 * Create a new menu button
41 * @param {Object} config The config object
44 Ext.SplitButton = Ext.extend(Ext.Button, {
50 initComponent : function(){
51 Ext.SplitButton.superclass.initComponent.call(this);
54 * Fires when this button's arrow is clicked
55 * @param {MenuButton} this
56 * @param {EventObject} e The click event
58 this.addEvents("arrowclick");
62 onRender : function(){
63 Ext.SplitButton.superclass.onRender.apply(this, arguments);
64 if(this.arrowTooltip){
65 this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
70 * Sets this button's arrow click handler.
71 * @param {Function} handler The function to call when the arrow is clicked
72 * @param {Object} scope (optional) Scope for the function passed above
74 setArrowHandler : function(handler, scope){
75 this.arrowHandler = handler;
79 getMenuClass : function(){
80 return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
83 isClickOnArrow : function(e){
84 if (this.arrowAlign != 'bottom') {
85 var visBtn = this.el.child('em.x-btn-split');
86 var right = visBtn.getRegion().right - visBtn.getPadding('r');
87 return e.getPageX() > right;
89 return e.getPageY() > this.btnEl.getRegion().bottom;
94 onClick : function(e, t){
97 if(this.isClickOnArrow(e)){
98 if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
101 this.fireEvent("arrowclick", this, e);
102 if(this.arrowHandler){
103 this.arrowHandler.call(this.scope || this, this, e);
106 if(this.enableToggle){
109 this.fireEvent("click", this, e);
111 this.handler.call(this.scope || this, this, e);
118 isMenuTriggerOver : function(e){
119 return this.menu && e.target.tagName == this.arrowSelector;
123 isMenuTriggerOut : function(e, internal){
124 return this.menu && e.target.tagName != this.arrowSelector;
128 Ext.reg('splitbutton', Ext.SplitButton);