1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-toolbar.Toolbar-method-constructor'><span id='Ext-toolbar.Toolbar'>/**
2 </span></span> * @class Ext.toolbar.Toolbar
3 * @extends Ext.container.Container
5 Basic Toolbar class. Although the {@link Ext.container.Container#defaultType defaultType} for Toolbar is {@link Ext.button.Button button}, Toolbar
6 elements (child items for the Toolbar container) may be virtually any type of Component. Toolbar elements can be created explicitly via their
7 constructors, or implicitly via their xtypes, and can be {@link #add}ed dynamically.
9 __Some items have shortcut strings for creation:__
11 | Shortcut | xtype | Class | Description |
12 |:---------|:--------------|:------------------------------|:---------------------------------------------------|
13 | `->` | `tbspacer` | {@link Ext.toolbar.Fill} | begin using the right-justified button container |
14 | `-` | `tbseparator` | {@link Ext.toolbar.Separator} | add a vertical separator bar between toolbar items |
15 | ` ` | `tbspacer` | {@link Ext.toolbar.Spacer} | add horiztonal space between elements |
17 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar1.png Toolbar component}
20 Ext.create('Ext.toolbar.Toolbar", {
21 renderTo: document.body,
25 // xtype: 'button', // default for Toolbars
32 // begin using the right-justified button container
33 '->', // same as {xtype: 'tbfill'}, // Ext.toolbar.Fill
37 emptyText: 'enter search term'
39 // add a vertical separator bar between toolbar items
40 '-', // same as {xtype: 'tbseparator'} to create Ext.toolbar.Separator
41 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.toolbar.TextItem
42 {xtype: 'tbspacer'},// same as ' ' to create Ext.toolbar.Spacer
44 {xtype: 'tbspacer', width: 50}, // add a 50px space
49 Toolbars have {@link #enable} and {@link #disable} methods which when called, will enable/disable all items within your toolbar.
51 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar2.png Toolbar component}
54 Ext.create('Ext.toolbar.Toolbar', {
55 renderTo: document.body,
69 emptyText: 'enter search term'
74 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar3.png Toolbar component}
77 var enableBtn = Ext.create('Ext.button.Button', {
78 text : 'Enable All Items',
81 handler : function() {
82 //disable the enable button and enable the disable button
91 var disableBtn = Ext.create('Ext.button.Button', {
92 text : 'Disable All Items',
94 handler : function() {
95 //enable the enable button and disable button
104 var toolbar = Ext.create('Ext.toolbar.Toolbar', {
105 renderTo: document.body,
108 items : [enableBtn, disableBtn]
111 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
112 which remove all items within the toolbar.
114 {@img Ext.toolbar.Toolbar/Ext.toolbar.Toolbar4.png Toolbar component}
117 var toolbar = Ext.create('Ext.toolbar.Toolbar', {
118 renderTo: document.body,
122 text: 'Example Button'
129 Ext.create('Ext.toolbar.Toolbar', {
130 renderTo: document.body,
135 text : 'Add a button',
137 handler: function() {
138 var text = prompt('Please enter the text for your button:');
139 addedItems.push(toolbar.add({
145 text : 'Add a text item',
147 handler: function() {
148 var text = prompt('Please enter the text for your item:');
149 addedItems.push(toolbar.add(text));
153 text : 'Add a toolbar seperator',
155 handler: function() {
156 addedItems.push(toolbar.add('-'));
160 text : 'Add a toolbar spacer',
162 handler: function() {
163 addedItems.push(toolbar.add('->'));
168 text : 'Remove last inserted item',
170 handler: function() {
171 if (addedItems.length) {
172 toolbar.remove(addedItems.pop());
173 } else if (toolbar.items.length) {
174 toolbar.remove(toolbar.items.last());
176 alert('No items in the toolbar');
181 text : 'Remove all items',
183 handler: function() {
191 * Creates a new Toolbar
192 * @param {Object/Array} config A config object or an array of buttons to <code>{@link #add}</code>
194 * @docauthor Robert Dougan <rob@sencha.com>
197 Ext.define('Ext.toolbar.Toolbar', {
198 extend: 'Ext.container.Container',
201 'Ext.layout.container.HBox',
202 'Ext.layout.container.VBox',
206 'Ext.toolbar.Separator'
208 alias: 'widget.toolbar',
209 alternateClassName: 'Ext.Toolbar',
212 baseCls : Ext.baseCSSPrefix + 'toolbar',
213 ariaRole : 'toolbar',
215 defaultType: 'button',
217 <span id='Ext-toolbar.Toolbar-cfg-vertical'> /**
218 </span> * @cfg {Boolean} vertical
219 * Set to `true` to make the toolbar vertical. The layout will become a `vbox`.
220 * (defaults to `false`)
224 <span id='Ext-toolbar.Toolbar-cfg-layout'> /**
225 </span> * @cfg {String/Object} layout
226 * This class assigns a default layout (<code>layout:'<b>hbox</b>'</code>).
227 * Developers <i>may</i> override this configuration option if another layout
228 * is required (the constructor must be passed a configuration object in this
229 * case instead of an array).
230 * See {@link Ext.container.Container#layout} for additional information.
233 <span id='Ext-toolbar.Toolbar-cfg-enableOverflow'> /**
234 </span> * @cfg {Boolean} enableOverflow
235 * Defaults to false. Configure <code>true</code> to make the toolbar provide a button
236 * which activates a dropdown Menu to show items which overflow the Toolbar's width.
238 enableOverflow: false,
243 itemCls: Ext.baseCSSPrefix + 'toolbar-item',
245 initComponent: function() {
249 // check for simplified (old-style) overflow config:
250 if (!me.layout && me.enableOverflow) {
251 me.layout = { overflowHandler: 'Menu' };
254 if (me.dock === 'right' || me.dock === 'left') {
258 me.layout = Ext.applyIf(Ext.isString(me.layout) ? {
260 } : me.layout || {}, {
261 type: me.vertical ? 'vbox' : 'hbox',
262 align: me.vertical ? 'stretchmax' : 'middle'
266 me.addClsWithUI('vertical');
269 // @TODO: remove this hack and implement a more general solution
270 if (me.ui === 'footer') {
271 me.ignoreBorderManagement = true;
276 <span id='Ext-toolbar.Toolbar-event-overflowchange'> /**
277 </span> * @event overflowchange
278 * Fires after the overflow state has changed.
279 * @param {Object} c The Container
280 * @param {Boolean} lastOverflow overflow state
282 me.addEvents('overflowchange');
284 // Subscribe to Ext.FocusManager for key navigation
285 keys = me.vertical ? ['up', 'down'] : ['left', 'right'];
286 Ext.FocusManager.subscribe(me, {
291 <span id='Ext-toolbar.Toolbar-method-add'> /**
292 </span> * <p>Adds element(s) to the toolbar -- this function takes a variable number of
293 * arguments of mixed type and adds them to the toolbar.</p>
294 * <br><p><b>Note</b>: See the notes within {@link Ext.container.Container#add}.</p>
295 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
297 * <li>{@link Ext.button.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
298 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
299 * <li>Field: Any form field (equivalent to {@link #addField})</li>
300 * <li>Item: Any subclass of {@link Ext.toolbar.Item} (equivalent to {@link #addItem})</li>
301 * <li>String: Any generic string (gets wrapped in a {@link Ext.toolbar.TextItem}, equivalent to {@link #addText}).
302 * Note that there are a few special strings that are treated differently as explained next.</li>
303 * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>
304 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
305 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
307 * @param {Mixed} arg2
308 * @param {Mixed} etc.
313 lookupComponent: function(c) {
314 if (Ext.isString(c)) {
315 var shortcut = Ext.toolbar.Toolbar.shortcuts[c];
326 this.applyDefaults(c);
328 return this.callParent(arguments);
332 applyDefaults: function(c) {
333 if (!Ext.isString(c)) {
334 c = this.callParent(arguments);
335 var d = this.internalDefaults;
337 Ext.applyIf(c.initialConfig, d);
347 trackMenu: function(item, remove) {
348 if (this.trackMenus && item.menu) {
349 var method = remove ? 'mun' : 'mon',
352 me[method](item, 'menutriggerover', me.onButtonTriggerOver, me);
353 me[method](item, 'menushow', me.onButtonMenuShow, me);
354 me[method](item, 'menuhide', me.onButtonMenuHide, me);
359 constructButton: function(item) {
360 return item.events ? item : this.createComponent(item, item.split ? 'splitbutton' : this.defaultType);
364 onBeforeAdd: function(component) {
365 if (component.is('field') || (component.is('button') && this.ui != 'footer')) {
366 component.ui = component.ui + '-toolbar';
369 // Any separators needs to know if is vertical or not
370 if (component instanceof Ext.toolbar.Separator) {
371 component.setUI((this.vertical) ? 'vertical' : 'horizontal');
374 this.callParent(arguments);
378 onAdd: function(component) {
379 this.callParent(arguments);
381 this.trackMenu(component);
388 onRemove: function(c) {
389 this.callParent(arguments);
390 this.trackMenu(c, true);
394 onButtonTriggerOver: function(btn){
395 if (this.activeMenuBtn && this.activeMenuBtn != btn) {
396 this.activeMenuBtn.hideMenu();
398 this.activeMenuBtn = btn;
403 onButtonMenuShow: function(btn) {
404 this.activeMenuBtn = btn;
408 onButtonMenuHide: function(btn) {
409 delete this.activeMenuBtn;
417 });</pre></pre></body></html>