4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-toolbar-Toolbar-method-constructor'><span id='Ext-toolbar-Toolbar'>/**
19 </span></span> * @class Ext.toolbar.Toolbar
20 * @extends Ext.container.Container
22 Basic Toolbar class. Although the {@link Ext.container.Container#defaultType defaultType} for Toolbar is {@link Ext.button.Button button}, Toolbar
23 elements (child items for the Toolbar container) may be virtually any type of Component. Toolbar elements can be created explicitly via their
24 constructors, or implicitly via their xtypes, and can be {@link #add}ed dynamically.
26 __Some items have shortcut strings for creation:__
28 | Shortcut | xtype | Class | Description |
29 |:---------|:--------------|:------------------------------|:---------------------------------------------------|
30 | `->` | `tbspacer` | {@link Ext.toolbar.Fill} | begin using the right-justified button container |
31 | `-` | `tbseparator` | {@link Ext.toolbar.Separator} | add a vertical separator bar between toolbar items |
32 | ` ` | `tbspacer` | {@link Ext.toolbar.Spacer} | add horiztonal space between elements |
34 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar1.png Toolbar component}
37 Ext.create('Ext.toolbar.Toolbar', {
38 renderTo: document.body,
42 // xtype: 'button', // default for Toolbars
49 // begin using the right-justified button container
50 '->', // same as {xtype: 'tbfill'}, // Ext.toolbar.Fill
54 emptyText: 'enter search term'
56 // add a vertical separator bar between toolbar items
57 '-', // same as {xtype: 'tbseparator'} to create Ext.toolbar.Separator
58 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.toolbar.TextItem
59 {xtype: 'tbspacer'},// same as ' ' to create Ext.toolbar.Spacer
61 {xtype: 'tbspacer', width: 50}, // add a 50px space
66 Toolbars have {@link #enable} and {@link #disable} methods which when called, will enable/disable all items within your toolbar.
68 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar2.png Toolbar component}
71 Ext.create('Ext.toolbar.Toolbar', {
72 renderTo: document.body,
86 emptyText: 'enter search term'
91 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar3.png Toolbar component}
94 var enableBtn = Ext.create('Ext.button.Button', {
95 text : 'Enable All Items',
98 handler : function() {
99 //disable the enable button and enable the disable button
108 var disableBtn = Ext.create('Ext.button.Button', {
109 text : 'Disable All Items',
111 handler : function() {
112 //enable the enable button and disable button
113 disableBtn.disable();
116 //disable the toolbar
121 var toolbar = Ext.create('Ext.toolbar.Toolbar', {
122 renderTo: document.body,
125 items : [enableBtn, disableBtn]
128 Adding items to and removing items from a toolbar is as simple as calling the {@link #add} and {@link #remove} methods. There is also a {@link #removeAll} method
129 which remove all items within the toolbar.
131 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar4.png Toolbar component}
134 var toolbar = Ext.create('Ext.toolbar.Toolbar', {
135 renderTo: document.body,
139 text: 'Example Button'
146 Ext.create('Ext.toolbar.Toolbar', {
147 renderTo: document.body,
152 text : 'Add a button',
154 handler: function() {
155 var text = prompt('Please enter the text for your button:');
156 addedItems.push(toolbar.add({
162 text : 'Add a text item',
164 handler: function() {
165 var text = prompt('Please enter the text for your item:');
166 addedItems.push(toolbar.add(text));
170 text : 'Add a toolbar seperator',
172 handler: function() {
173 addedItems.push(toolbar.add('-'));
177 text : 'Add a toolbar spacer',
179 handler: function() {
180 addedItems.push(toolbar.add('->'));
185 text : 'Remove last inserted item',
187 handler: function() {
188 if (addedItems.length) {
189 toolbar.remove(addedItems.pop());
190 } else if (toolbar.items.length) {
191 toolbar.remove(toolbar.items.last());
193 alert('No items in the toolbar');
198 text : 'Remove all items',
200 handler: function() {
208 * Creates a new Toolbar
209 * @param {Object/Array} config A config object or an array of buttons to <code>{@link #add}</code>
210 * @docauthor Robert Dougan <rob@sencha.com>
213 Ext.define('Ext.toolbar.Toolbar', {
214 extend: 'Ext.container.Container',
217 'Ext.layout.container.HBox',
218 'Ext.layout.container.VBox',
222 'Ext.toolbar.Separator'
224 alias: 'widget.toolbar',
225 alternateClassName: 'Ext.Toolbar',
228 baseCls : Ext.baseCSSPrefix + 'toolbar',
229 ariaRole : 'toolbar',
231 defaultType: 'button',
233 <span id='Ext-toolbar-Toolbar-cfg-vertical'> /**
234 </span> * @cfg {Boolean} vertical
235 * Set to `true` to make the toolbar vertical. The layout will become a `vbox`.
236 * (defaults to `false`)
240 <span id='Ext-toolbar-Toolbar-cfg-layout'> /**
241 </span> * @cfg {String/Object} layout
242 * This class assigns a default layout (<code>layout:'<b>hbox</b>'</code>).
243 * Developers <i>may</i> override this configuration option if another layout
244 * is required (the constructor must be passed a configuration object in this
245 * case instead of an array).
246 * See {@link Ext.container.Container#layout} for additional information.
249 <span id='Ext-toolbar-Toolbar-cfg-enableOverflow'> /**
250 </span> * @cfg {Boolean} enableOverflow
251 * Defaults to false. Configure <code>true</code> to make the toolbar provide a button
252 * which activates a dropdown Menu to show items which overflow the Toolbar's width.
254 enableOverflow: false,
259 itemCls: Ext.baseCSSPrefix + 'toolbar-item',
261 initComponent: function() {
265 // check for simplified (old-style) overflow config:
266 if (!me.layout && me.enableOverflow) {
267 me.layout = { overflowHandler: 'Menu' };
270 if (me.dock === 'right' || me.dock === 'left') {
274 me.layout = Ext.applyIf(Ext.isString(me.layout) ? {
276 } : me.layout || {}, {
277 type: me.vertical ? 'vbox' : 'hbox',
278 align: me.vertical ? 'stretchmax' : 'middle',
279 clearInnerCtOnLayout: true
283 me.addClsWithUI('vertical');
286 // @TODO: remove this hack and implement a more general solution
287 if (me.ui === 'footer') {
288 me.ignoreBorderManagement = true;
293 <span id='Ext-toolbar-Toolbar-event-overflowchange'> /**
294 </span> * @event overflowchange
295 * Fires after the overflow state has changed.
296 * @param {Object} c The Container
297 * @param {Boolean} lastOverflow overflow state
299 me.addEvents('overflowchange');
301 // Subscribe to Ext.FocusManager for key navigation
302 keys = me.vertical ? ['up', 'down'] : ['left', 'right'];
303 Ext.FocusManager.subscribe(me, {
308 <span id='Ext-toolbar-Toolbar-method-add'> /**
309 </span> * <p>Adds element(s) to the toolbar -- this function takes a variable number of
310 * arguments of mixed type and adds them to the toolbar.</p>
311 * <br><p><b>Note</b>: See the notes within {@link Ext.container.Container#add}.</p>
312 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
314 * <li>{@link Ext.button.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
315 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
316 * <li>Field: Any form field (equivalent to {@link #addField})</li>
317 * <li>Item: Any subclass of {@link Ext.toolbar.Item} (equivalent to {@link #addItem})</li>
318 * <li>String: Any generic string (gets wrapped in a {@link Ext.toolbar.TextItem}, equivalent to {@link #addText}).
319 * Note that there are a few special strings that are treated differently as explained next.</li>
320 * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>
321 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
322 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
324 * @param {Mixed} arg2
325 * @param {Mixed} etc.
330 lookupComponent: function(c) {
331 if (Ext.isString(c)) {
332 var shortcut = Ext.toolbar.Toolbar.shortcuts[c];
343 this.applyDefaults(c);
345 return this.callParent(arguments);
349 applyDefaults: function(c) {
350 if (!Ext.isString(c)) {
351 c = this.callParent(arguments);
352 var d = this.internalDefaults;
354 Ext.applyIf(c.initialConfig, d);
364 trackMenu: function(item, remove) {
365 if (this.trackMenus && item.menu) {
366 var method = remove ? 'mun' : 'mon',
369 me[method](item, 'menutriggerover', me.onButtonTriggerOver, me);
370 me[method](item, 'menushow', me.onButtonMenuShow, me);
371 me[method](item, 'menuhide', me.onButtonMenuHide, me);
376 constructButton: function(item) {
377 return item.events ? item : this.createComponent(item, item.split ? 'splitbutton' : this.defaultType);
381 onBeforeAdd: function(component) {
382 if (component.is('field') || (component.is('button') && this.ui != 'footer')) {
383 component.ui = component.ui + '-toolbar';
386 // Any separators needs to know if is vertical or not
387 if (component instanceof Ext.toolbar.Separator) {
388 component.setUI((this.vertical) ? 'vertical' : 'horizontal');
391 this.callParent(arguments);
395 onAdd: function(component) {
396 this.callParent(arguments);
398 this.trackMenu(component);
405 onRemove: function(c) {
406 this.callParent(arguments);
407 this.trackMenu(c, true);
411 onButtonTriggerOver: function(btn){
412 if (this.activeMenuBtn && this.activeMenuBtn != btn) {
413 this.activeMenuBtn.hideMenu();
415 this.activeMenuBtn = btn;
420 onButtonMenuShow: function(btn) {
421 this.activeMenuBtn = btn;
425 onButtonMenuHide: function(btn) {
426 delete this.activeMenuBtn;