4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * Basic Toolbar class. Although the {@link Ext.container.Container#defaultType defaultType} for Toolbar is {@link Ext.button.Button button}, Toolbar
20 * elements (child items for the Toolbar container) may be virtually any type of Component. Toolbar elements can be created explicitly via their
21 * constructors, or implicitly via their xtypes, and can be {@link #add}ed dynamically.
23 * ## Some items have shortcut strings for creation:
25 * | Shortcut | xtype | Class | Description
26 * |:---------|:--------------|:------------------------------|:---------------------------------------------------
27 * | `->` | `tbfill` | {@link Ext.toolbar.Fill} | begin using the right-justified button container
28 * | `-` | `tbseparator` | {@link Ext.toolbar.Separator} | add a vertical separator bar between toolbar items
29 * | ` ` | `tbspacer` | {@link Ext.toolbar.Spacer} | add horiztonal space between elements
32 * Ext.create('Ext.toolbar.Toolbar', {
33 * renderTo: document.body,
37 * // xtype: 'button', // default for Toolbars
41 * xtype: 'splitbutton',
42 * text : 'Split Button'
44 * // begin using the right-justified button container
45 * '->', // same as { xtype: 'tbfill' }
47 * xtype : 'textfield',
49 * emptyText: 'enter search term'
51 * // add a vertical separator bar between toolbar items
52 * '-', // same as {xtype: 'tbseparator'} to create Ext.toolbar.Separator
53 * 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.toolbar.TextItem
54 * { xtype: 'tbspacer' },// same as ' ' to create Ext.toolbar.Spacer
56 * { xtype: 'tbspacer', width: 50 }, // add a 50px space
61 * Toolbars have {@link #enable} and {@link #disable} methods which when called, will enable/disable all items within your toolbar.
64 * Ext.create('Ext.toolbar.Toolbar', {
65 * renderTo: document.body,
72 * xtype: 'splitbutton',
73 * text : 'Split Button'
77 * xtype : 'textfield',
79 * emptyText: 'enter search term'
87 * var enableBtn = Ext.create('Ext.button.Button', {
88 * text : 'Enable All Items',
91 * handler : function() {
92 * //disable the enable button and enable the disable button
93 * enableBtn.disable();
94 * disableBtn.enable();
96 * //enable the toolbar
101 * var disableBtn = Ext.create('Ext.button.Button', {
102 * text : 'Disable All Items',
104 * handler : function() {
105 * //enable the enable button and disable button
106 * disableBtn.disable();
107 * enableBtn.enable();
109 * //disable the toolbar
114 * var toolbar = Ext.create('Ext.toolbar.Toolbar', {
115 * renderTo: document.body,
117 * margin : '5 0 0 0',
118 * items : [enableBtn, disableBtn]
121 * 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
122 * which remove all items within the toolbar.
125 * var toolbar = Ext.create('Ext.toolbar.Toolbar', {
126 * renderTo: document.body,
130 * text: 'Example Button'
135 * var addedItems = [];
137 * Ext.create('Ext.toolbar.Toolbar', {
138 * renderTo: document.body,
140 * margin : '5 0 0 0',
143 * text : 'Add a button',
145 * handler: function() {
146 * var text = prompt('Please enter the text for your button:');
147 * addedItems.push(toolbar.add({
153 * text : 'Add a text item',
155 * handler: function() {
156 * var text = prompt('Please enter the text for your item:');
157 * addedItems.push(toolbar.add(text));
161 * text : 'Add a toolbar seperator',
163 * handler: function() {
164 * addedItems.push(toolbar.add('-'));
168 * text : 'Add a toolbar spacer',
170 * handler: function() {
171 * addedItems.push(toolbar.add('->'));
176 * text : 'Remove last inserted item',
178 * handler: function() {
179 * if (addedItems.length) {
180 * toolbar.remove(addedItems.pop());
181 * } else if (toolbar.items.length) {
182 * toolbar.remove(toolbar.items.last());
184 * alert('No items in the toolbar');
189 * text : 'Remove all items',
191 * handler: function() {
192 * toolbar.removeAll();
199 * Creates a new Toolbar
200 * @param {Object/Object[]} config A config object or an array of buttons to <code>{@link #add}</code>
201 * @docauthor Robert Dougan <rob@sencha.com>
203 Ext.define('Ext.toolbar.Toolbar', {
204 extend: 'Ext.container.Container',
207 'Ext.layout.container.HBox',
208 'Ext.layout.container.VBox',
212 'Ext.toolbar.Separator'
214 alias: 'widget.toolbar',
215 alternateClassName: 'Ext.Toolbar',
218 baseCls : Ext.baseCSSPrefix + 'toolbar',
219 ariaRole : 'toolbar',
221 defaultType: 'button',
223 <span id='Ext-toolbar-Toolbar-cfg-vertical'> /**
224 </span> * @cfg {Boolean} vertical
225 * Set to `true` to make the toolbar vertical. The layout will become a `vbox`.
229 <span id='Ext-toolbar-Toolbar-cfg-layout'> /**
230 </span> * @cfg {String/Object} layout
231 * This class assigns a default layout (`layout: 'hbox'`).
232 * Developers _may_ override this configuration option if another layout
233 * is required (the constructor must be passed a configuration object in this
234 * case instead of an array).
235 * See {@link Ext.container.Container#layout} for additional information.
238 <span id='Ext-toolbar-Toolbar-cfg-enableOverflow'> /**
239 </span> * @cfg {Boolean} enableOverflow
240 * Configure true to make the toolbar provide a button which activates a dropdown Menu to show
241 * items which overflow the Toolbar's width.
243 enableOverflow: false,
245 <span id='Ext-toolbar-Toolbar-cfg-menuTriggerCls'> /**
246 </span> * @cfg {String} menuTriggerCls
247 * Configure the icon class of the overflow button.
249 menuTriggerCls: Ext.baseCSSPrefix + 'toolbar-more-icon',
254 itemCls: Ext.baseCSSPrefix + 'toolbar-item',
256 initComponent: function() {
260 // check for simplified (old-style) overflow config:
261 if (!me.layout && me.enableOverflow) {
262 me.layout = { overflowHandler: 'Menu' };
265 if (me.dock === 'right' || me.dock === 'left') {
269 me.layout = Ext.applyIf(Ext.isString(me.layout) ? {
271 } : me.layout || {}, {
272 type: me.vertical ? 'vbox' : 'hbox',
273 align: me.vertical ? 'stretchmax' : 'middle',
274 clearInnerCtOnLayout: true
278 me.addClsWithUI('vertical');
281 // @TODO: remove this hack and implement a more general solution
282 if (me.ui === 'footer') {
283 me.ignoreBorderManagement = true;
288 <span id='Ext-toolbar-Toolbar-event-overflowchange'> /**
289 </span> * @event overflowchange
290 * Fires after the overflow state has changed.
291 * @param {Object} c The Container
292 * @param {Boolean} lastOverflow overflow state
294 me.addEvents('overflowchange');
296 // Subscribe to Ext.FocusManager for key navigation
297 keys = me.vertical ? ['up', 'down'] : ['left', 'right'];
298 Ext.FocusManager.subscribe(me, {
303 getRefItems: function(deep) {
305 items = me.callParent(arguments),
309 if (deep && me.enableOverflow) {
310 handler = layout.overflowHandler;
311 if (handler && handler.menu) {
312 items = items.concat(handler.menu.getRefItems(deep));
318 <span id='Ext-toolbar-Toolbar-method-add'> /**
319 </span> * Adds element(s) to the toolbar -- this function takes a variable number of
320 * arguments of mixed type and adds them to the toolbar.
322 * **Note**: See the notes within {@link Ext.container.Container#add}.
324 * @param {Object...} args The following types of arguments are all valid:
325 * - `{@link Ext.button.Button config}`: A valid button config object
326 * - `HtmlElement`: Any standard HTML element
327 * - `Field`: Any form field
328 * - `Item`: Any subclass of {@link Ext.toolbar.Item}
329 * - `String`: Any generic string (gets wrapped in a {@link Ext.toolbar.TextItem}).
330 * Note that there are a few special strings that are treated differently as explained next.
331 * - `'-'`: Creates a separator element
332 * - `' '`: Creates a spacer element
333 * - `'->'`: Creates a fill element
339 lookupComponent: function(c) {
340 if (Ext.isString(c)) {
341 var shortcut = Ext.toolbar.Toolbar.shortcuts[c];
352 this.applyDefaults(c);
354 return this.callParent(arguments);
358 applyDefaults: function(c) {
359 if (!Ext.isString(c)) {
360 c = this.callParent(arguments);
361 var d = this.internalDefaults;
363 Ext.applyIf(c.initialConfig, d);
373 trackMenu: function(item, remove) {
374 if (this.trackMenus && item.menu) {
375 var method = remove ? 'mun' : 'mon',
378 me[method](item, 'mouseover', me.onButtonOver, me);
379 me[method](item, 'menushow', me.onButtonMenuShow, me);
380 me[method](item, 'menuhide', me.onButtonMenuHide, me);
385 constructButton: function(item) {
386 return item.events ? item : this.createComponent(item, item.split ? 'splitbutton' : this.defaultType);
390 onBeforeAdd: function(component) {
391 if (component.is('field') || (component.is('button') && this.ui != 'footer')) {
392 component.ui = component.ui + '-toolbar';
395 // Any separators needs to know if is vertical or not
396 if (component instanceof Ext.toolbar.Separator) {
397 component.setUI((this.vertical) ? 'vertical' : 'horizontal');
400 this.callParent(arguments);
404 onAdd: function(component) {
405 this.callParent(arguments);
407 this.trackMenu(component);
414 onRemove: function(c) {
415 this.callParent(arguments);
416 this.trackMenu(c, true);
420 onButtonOver: function(btn){
421 if (this.activeMenuBtn && this.activeMenuBtn != btn) {
422 this.activeMenuBtn.hideMenu();
424 this.activeMenuBtn = btn;
429 onButtonMenuShow: function(btn) {
430 this.activeMenuBtn = btn;
434 onButtonMenuHide: function(btn) {
435 delete this.activeMenuBtn;