3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.SplitButton"></div>/**
\r
10 * @class Ext.SplitButton
\r
11 * @extends Ext.Button
\r
12 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
\r
13 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
\r
14 * options to the primary button action, but any custom handler can provide the arrowclick implementation. Example usage:
\r
16 // display a dropdown menu:
\r
17 new Ext.SplitButton({
\r
18 renderTo: 'button-ct', // the container id
\r
20 handler: optionsHandler, // handle a click on the button itself
\r
21 menu: new Ext.menu.Menu({
\r
23 // these items will render as dropdown menu items when the arrow is clicked:
\r
24 {text: 'Item 1', handler: item1Handler},
\r
25 {text: 'Item 2', handler: item2Handler}
\r
30 // Instead of showing a menu, you provide any type of custom
\r
31 // functionality you want when the dropdown arrow is clicked:
\r
32 new Ext.SplitButton({
\r
33 renderTo: 'button-ct',
\r
35 handler: optionsHandler,
\r
36 arrowHandler: myCustomHandler
\r
39 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
\r
40 * @cfg {String} arrowTooltip The title attribute of the arrow
\r
42 * Create a new menu button
\r
43 * @param {Object} config The config object
\r
44 * @xtype splitbutton
\r
46 Ext.SplitButton = Ext.extend(Ext.Button, {
\r
48 arrowSelector : 'em',
\r
52 initComponent : function(){
\r
53 Ext.SplitButton.superclass.initComponent.call(this);
\r
56 * Fires when this button's arrow is clicked
\r
57 * @param {MenuButton} this
\r
58 * @param {EventObject} e The click event
\r
60 this.addEvents("arrowclick");
\r
64 onRender : function(){
\r
65 Ext.SplitButton.superclass.onRender.apply(this, arguments);
\r
66 if(this.arrowTooltip){
\r
67 this.el.child(this.arrowSelector).dom[this.tooltipType] = this.arrowTooltip;
\r
72 * Sets this button's arrow click handler.
\r
73 * @param {Function} handler The function to call when the arrow is clicked
\r
74 * @param {Object} scope (optional) Scope for the function passed above
\r
76 setArrowHandler : function(handler, scope){
\r
77 this.arrowHandler = handler;
\r
81 getMenuClass : function(){
\r
82 return 'x-btn-split' + (this.arrowAlign == 'bottom' ? '-bottom' : '');
\r
85 isClickOnArrow : function(e){
\r
86 if (this.arrowAlign != 'bottom') {
\r
87 var visBtn = this.el.child('em.x-btn-split');
\r
88 var right = visBtn.getRegion().right - visBtn.getPadding('r');
\r
89 return e.getPageX() > right;
\r
91 return e.getPageY() > this.btnEl.getRegion().bottom;
\r
96 onClick : function(e, t){
\r
99 if(this.isClickOnArrow(e)){
\r
100 if(this.menu && !this.menu.isVisible() && !this.ignoreNextClick){
\r
103 this.fireEvent("arrowclick", this, e);
\r
104 if(this.arrowHandler){
\r
105 this.arrowHandler.call(this.scope || this, this, e);
\r
108 if(this.enableToggle){
\r
111 this.fireEvent("click", this, e);
\r
113 this.handler.call(this.scope || this, this, e);
\r
120 isMenuTriggerOver : function(e){
\r
121 return this.menu && e.target.tagName == this.arrowSelector;
\r
125 isMenuTriggerOut : function(e, internal){
\r
126 return this.menu && e.target.tagName != this.arrowSelector;
\r
130 Ext.reg('splitbutton', Ext.SplitButton);</pre>
\r