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.layout.ToolbarLayout"></div>/**
10 * @class Ext.layout.ToolbarLayout
11 * @extends Ext.layout.ContainerLayout
12 * Layout manager implicitly used by Ext.Toolbar.
14 Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
20 noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
22 onLayout : function(ct, target){
24 var align = ct.buttonAlign == 'center' ? 'center' : 'left';
25 target.addClass('x-toolbar-layout-ct');
26 target.insertHtml('beforeEnd',
27 '<table cellspacing="0" class="x-toolbar-ct"><tbody><tr><td class="x-toolbar-left" align="' + align + '"><table cellspacing="0"><tbody><tr class="x-toolbar-left-row"></tr></tbody></table></td><td class="x-toolbar-right" align="right"><table cellspacing="0" class="x-toolbar-right-ct"><tbody><tr><td><table cellspacing="0"><tbody><tr class="x-toolbar-right-row"></tr></tbody></table></td><td><table cellspacing="0"><tbody><tr class="x-toolbar-extras-row"></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>');
28 this.leftTr = target.child('tr.x-toolbar-left-row', true);
29 this.rightTr = target.child('tr.x-toolbar-right-row', true);
30 this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
32 var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
34 items = ct.items.items;
36 for(var i = 0, len = items.length, c; i < len; i++, pos++) {
41 }else if(!c.rendered){
42 c.render(this.insertCell(c, side, pos));
44 if(!c.xtbHidden && !this.isValidParent(c, side.childNodes[pos])){
45 var td = this.insertCell(c, side, pos);
46 td.appendChild(c.getPositionEl().dom);
47 c.container = Ext.get(td);
51 //strip extra empty cells
52 this.cleanup(this.leftTr);
53 this.cleanup(this.rightTr);
54 this.cleanup(this.extrasTr);
55 this.fitToSize(target);
58 cleanup : function(row){
59 var cn = row.childNodes;
60 for(var i = cn.length-1, c; i >= 0 && (c = cn[i]); i--){
67 insertCell : function(c, side, pos){
68 var td = document.createElement('td');
69 td.className='x-toolbar-cell';
70 side.insertBefore(td, side.childNodes[pos]||null);
74 hideItem : function(item){
75 var h = (this.hiddens = this.hiddens || []);
77 item.xtbHidden = true;
78 item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
82 unhideItem : function(item){
84 item.xtbHidden = false;
85 this.hiddens.remove(item);
86 if(this.hiddens.length < 1){
91 getItemWidth : function(c){
92 return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
95 fitToSize : function(t){
96 if(this.container.enableOverflow === false){
99 var w = t.dom.clientWidth,
100 lw = this.lastWidth || 0,
101 iw = t.dom.firstChild.offsetWidth,
102 clipWidth = w - this.triggerWidth,
107 if(iw > w || (this.hiddens && w >= lw)){
108 var i, items = this.container.items.items,
109 len = items.length, c,
112 for(i = 0; i < len; i++) {
115 loopWidth += this.getItemWidth(c);
116 if(loopWidth > clipWidth){
117 if(!(c.hidden || c.xtbHidden)){
120 }else if(c.xtbHidden){
128 if(!this.lastOverflow){
129 this.container.fireEvent('overflowchange', this.container, true);
130 this.lastOverflow = true;
136 if(this.lastOverflow){
137 this.container.fireEvent('overflowchange', this.container, false);
138 this.lastOverflow = false;
143 createMenuConfig : function(c, hideOnClick){
144 var cfg = Ext.apply({}, c.initialConfig),
145 group = c.toggleGroup;
148 text: c.overflowText || c.text,
152 disabled: c.disabled,
156 hideOnClick: hideOnClick
158 if(group || c.enableToggle){
163 checkchange: function(item, checked){
176 addComponentToMenu : function(m, c){
177 if(c instanceof Ext.Toolbar.Separator){
179 }else if(Ext.isFunction(c.isXType)){
180 if(c.isXType('splitbutton')){
181 m.add(this.createMenuConfig(c, true));
182 }else if(c.isXType('button')){
183 m.add(this.createMenuConfig(c, !c.menu));
184 }else if(c.isXType('buttongroup')){
185 c.items.each(function(item){
186 this.addComponentToMenu(m, item);
192 clearMenu : function(){
193 var m = this.moreMenu;
195 m.items.each(function(item){
202 beforeMoreShow : function(m){
203 var h = this.container.items.items,
207 needsSep = function(group, item){
208 return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
213 for(var i = 0; i < len; i++){
216 if(prev && (needsSep(c, prev) || needsSep(prev, c))){
219 this.addComponentToMenu(m, c);
223 // put something so the menu isn't empty
224 // if no compatible items found
225 if(m.items.length < 1){
226 m.add(this.noItemsMenuText);
230 initMore : function(){
232 this.moreMenu = new Ext.menu.Menu({
234 beforeshow: this.beforeMoreShow,
238 this.moreMenu.ownerCt = this.container;
239 this.more = new Ext.Button({
240 iconCls: 'x-toolbar-more-icon',
241 cls: 'x-toolbar-more',
244 var td = this.insertCell(this.more, this.extrasTr, 100);
245 this.more.render(td);
249 onRemove : function(c){
252 delete this.extrasTr;
253 Ext.layout.ToolbarLayout.superclass.onRemove.call(this, c);
256 destroy : function(){
257 Ext.destroy(this.more, this.moreMenu);
260 delete this.extrasTr;
261 Ext.layout.ToolbarLayout.superclass.destroy.call(this);
263 <div id="prop-Ext.layout.ToolbarLayout-activeItem"></div>/**
264 * @property activeItem
269 Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
271 <div id="cls-Ext.Toolbar"></div>/**
273 * @extends Ext.Container
274 * <p>Basic Toolbar class. Although the <tt>{@link Ext.Container#defaultType defaultType}</tt> for Toolbar
275 * is <tt>{@link Ext.Button button}</tt>, Toolbar elements (child items for the Toolbar container) may
276 * be virtually any type of Component. Toolbar elements can be created explicitly via their constructors,
277 * or implicitly via their xtypes, and can be <tt>{@link #add}</tt>ed dynamically.</p>
278 * <p>Some items have shortcut strings for creation:</p>
280 <u>Shortcut</u> <u>xtype</u> <u>Class</u> <u>Description</u>
281 '->' 'tbfill' {@link Ext.Toolbar.Fill} begin using the right-justified button container
282 '-' 'tbseparator' {@link Ext.Toolbar.Separator} add a vertical separator bar between toolbar items
283 ' ' 'tbspacer' {@link Ext.Toolbar.Spacer} add horiztonal space between elements
286 * Example usage of various elements:
288 var tb = new Ext.Toolbar({
289 renderTo: document.body,
294 // xtype: 'button', // default for Toolbars, same as 'tbbutton'
298 xtype: 'splitbutton', // same as 'tbsplitbutton'
301 // begin using the right-justified button container
302 '->', // same as {xtype: 'tbfill'}, // Ext.Toolbar.Fill
306 emptyText: 'enter search term'
308 // add a vertical separator bar between toolbar items
309 '-', // same as {xtype: 'tbseparator'} to create Ext.Toolbar.Separator
310 'text 1', // same as {xtype: 'tbtext', text: 'text1'} to create Ext.Toolbar.TextItem
311 {xtype: 'tbspacer'},// same as ' ' to create Ext.Toolbar.Spacer
313 {xtype: 'tbspacer', width: 50}, // add a 50px space
318 * Example adding a ComboBox within a menu of a button:
321 var combo = new Ext.form.ComboBox({
322 store: new Ext.data.ArrayStore({
324 fields: ['initials', 'fullname'],
326 ['FF', 'Fred Flintstone'],
327 ['BR', 'Barney Rubble']
330 displayField: 'fullname',
333 forceSelection: true,
334 triggerAction: 'all',
335 emptyText: 'Select a name...',
338 getListParent: function() {
339 return this.el.up('.x-menu');
341 iconCls: 'no-icon' //use iconCls if placing within menu to shift to right side of menu
344 // put ComboBox in a Menu
345 var menu = new Ext.menu.Menu({
348 combo // A Field in a Menu
352 // add a Button with the menu
354 text:'Button w/ Menu',
355 menu: menu // assign menu by instance
360 * Creates a new Toolbar
361 * @param {Object/Array} config A config object or an array of buttons to <tt>{@link #add}</tt>
364 Ext.Toolbar = function(config){
365 if(Ext.isArray(config)){
366 config = {items: config, layout: 'toolbar'};
372 config.items = config.buttons;
375 Ext.Toolbar.superclass.constructor.call(this, config);
382 Ext.extend(T, Ext.Container, {
384 defaultType: 'button',
386 <div id="cfg-Ext.Toolbar-layout"></div>/**
387 * @cfg {String/Object} layout
388 * This class assigns a default layout (<code>layout:'<b>toolbar</b>'</code>).
389 * Developers <i>may</i> override this configuration option if another layout
390 * is required (the constructor must be passed a configuration object in this
391 * case instead of an array).
392 * See {@link Ext.Container#layout} for additional information.
394 <div id="cfg-Ext.Toolbar-enableOverflow"></div>/**
395 * @cfg {Boolean} enableOverflow
396 * Defaults to false. Configure <code>true<code> to make the toolbar provide a button
397 * which activates a dropdown Menu to show items which overflow the Toolbar's width.
401 internalDefaults: {removeMode: 'container', hideParent: true},
402 toolbarCls: 'x-toolbar',
404 initComponent : function(){
405 T.superclass.initComponent.call(this);
407 <div id="event-Ext.Toolbar-overflowchange"></div>/**
408 * @event overflowchange
409 * Fires after the overflow state has changed.
410 * @param {Object} c The Container
411 * @param {Boolean} lastOverflow overflow state
413 this.addEvents('overflowchange');
417 onRender : function(ct, position){
419 if(!this.autoCreate){
421 cls: this.toolbarCls + ' x-small-editor'
424 this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position);
425 Ext.Toolbar.superclass.onRender.apply(this, arguments);
429 <div id="method-Ext.Toolbar-add"></div>/**
430 * <p>Adds element(s) to the toolbar -- this function takes a variable number of
431 * arguments of mixed type and adds them to the toolbar.</p>
432 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
433 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
435 * <li>{@link Ext.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
436 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
437 * <li>Field: Any form field (equivalent to {@link #addField})</li>
438 * <li>Item: Any subclass of {@link Ext.Toolbar.Item} (equivalent to {@link #addItem})</li>
439 * <li>String: Any generic string (gets wrapped in a {@link Ext.Toolbar.TextItem}, equivalent to {@link #addText}).
440 * Note that there are a few special strings that are treated differently as explained next.</li>
441 * <li>'-': Creates a separator element (equivalent to {@link #addSeparator})</li>
442 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
443 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
445 * @param {Mixed} arg2
446 * @param {Mixed} etc.
451 lookupComponent : function(c){
454 c = new T.Separator();
460 c = new T.TextItem(c);
462 this.applyDefaults(c);
464 if(c.isFormField || c.render){ // some kind of form field, some kind of Toolbar.Item
465 c = this.createComponent(c);
466 }else if(c.tag){ // DomHelper spec
467 c = new T.Item({autoEl: c});
468 }else if(c.tagName){ // element
469 c = new T.Item({el:c});
470 }else if(Ext.isObject(c)){ // must be button config?
471 c = c.xtype ? this.createComponent(c) : this.constructButton(c);
478 applyDefaults : function(c){
479 if(!Ext.isString(c)){
480 c = Ext.Toolbar.superclass.applyDefaults.call(this, c);
481 var d = this.internalDefaults;
483 Ext.applyIf(c.initialConfig, d);
492 <div id="method-Ext.Toolbar-addSeparator"></div>/**
494 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
495 * @return {Ext.Toolbar.Item} The separator {@link Ext.Toolbar.Item item}
497 addSeparator : function(){
498 return this.add(new T.Separator());
501 <div id="method-Ext.Toolbar-addSpacer"></div>/**
502 * Adds a spacer element
503 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
504 * @return {Ext.Toolbar.Spacer} The spacer item
506 addSpacer : function(){
507 return this.add(new T.Spacer());
510 <div id="method-Ext.Toolbar-addFill"></div>/**
511 * Forces subsequent additions into the float:right toolbar
512 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
514 addFill : function(){
515 this.add(new T.Fill());
518 <div id="method-Ext.Toolbar-addElement"></div>/**
519 * Adds any standard HTML element to the toolbar
520 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
521 * @param {Mixed} el The element or id of the element to add
522 * @return {Ext.Toolbar.Item} The element's item
524 addElement : function(el){
525 return this.addItem(new T.Item({el:el}));
528 <div id="method-Ext.Toolbar-addItem"></div>/**
529 * Adds any Toolbar.Item or subclass
530 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
531 * @param {Ext.Toolbar.Item} item
532 * @return {Ext.Toolbar.Item} The item
534 addItem : function(item){
535 return this.add.apply(this, arguments);
538 <div id="method-Ext.Toolbar-addButton"></div>/**
539 * Adds a button (or buttons). See {@link Ext.Button} for more info on the config.
540 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
541 * @param {Object/Array} config A button config or array of configs
542 * @return {Ext.Button/Array}
544 addButton : function(config){
545 if(Ext.isArray(config)){
547 for(var i = 0, len = config.length; i < len; i++) {
548 buttons.push(this.addButton(config[i]));
552 return this.add(this.constructButton(config));
555 <div id="method-Ext.Toolbar-addText"></div>/**
556 * Adds text to the toolbar
557 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
558 * @param {String} text The text to add
559 * @return {Ext.Toolbar.Item} The element's item
561 addText : function(text){
562 return this.addItem(new T.TextItem(text));
565 <div id="method-Ext.Toolbar-addDom"></div>/**
566 * Adds a new element to the toolbar from the passed {@link Ext.DomHelper} config
567 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
568 * @param {Object} config
569 * @return {Ext.Toolbar.Item} The element's item
571 addDom : function(config){
572 return this.add(new T.Item({autoEl: config}));
575 <div id="method-Ext.Toolbar-addField"></div>/**
576 * Adds a dynamically rendered Ext.form field (TextField, ComboBox, etc). Note: the field should not have
577 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
578 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
579 * @param {Ext.form.Field} field
580 * @return {Ext.Toolbar.Item}
582 addField : function(field){
583 return this.add(field);
586 <div id="method-Ext.Toolbar-insertButton"></div>/**
587 * Inserts any {@link Ext.Toolbar.Item}/{@link Ext.Button} at the specified index.
588 * <br><p><b>Note</b>: See the notes within {@link Ext.Container#add}.</p>
589 * @param {Number} index The index where the item is to be inserted
590 * @param {Object/Ext.Toolbar.Item/Ext.Button/Array} item The button, or button config object to be
591 * inserted, or an array of buttons/configs.
592 * @return {Ext.Button/Item}
594 insertButton : function(index, item){
595 if(Ext.isArray(item)){
597 for(var i = 0, len = item.length; i < len; i++) {
598 buttons.push(this.insertButton(index + i, item[i]));
602 return Ext.Toolbar.superclass.insert.call(this, index, item);
606 trackMenu : function(item, remove){
607 if(this.trackMenus && item.menu){
608 var method = remove ? 'mun' : 'mon';
609 this[method](item, 'menutriggerover', this.onButtonTriggerOver, this);
610 this[method](item, 'menushow', this.onButtonMenuShow, this);
611 this[method](item, 'menuhide', this.onButtonMenuHide, this);
616 constructButton : function(item){
617 var b = item.events ? item : this.createComponent(item, item.split ? 'splitbutton' : this.defaultType);
623 Ext.Toolbar.superclass.onAdd.call(this);
628 onRemove : function(c){
629 Ext.Toolbar.superclass.onRemove.call(this);
630 this.trackMenu(c, true);
634 onDisable : function(){
635 this.items.each(function(item){
643 onEnable : function(){
644 this.items.each(function(item){
652 onButtonTriggerOver : function(btn){
653 if(this.activeMenuBtn && this.activeMenuBtn != btn){
654 this.activeMenuBtn.hideMenu();
656 this.activeMenuBtn = btn;
661 onButtonMenuShow : function(btn){
662 this.activeMenuBtn = btn;
666 onButtonMenuHide : function(btn){
667 delete this.activeMenuBtn;
670 Ext.reg('toolbar', Ext.Toolbar);
672 <div id="cls-Ext.Toolbar.Item"></div>/**
673 * @class Ext.Toolbar.Item
674 * @extends Ext.BoxComponent
675 * The base class that other non-interacting Toolbar Item classes should extend in order to
676 * get some basic common toolbar item functionality.
679 * @param {HTMLElement} el
682 T.Item = Ext.extend(Ext.BoxComponent, {
683 hideParent: true, // Hiding a Toolbar.Item hides its containing TD
687 <div id="cfg-Ext.Toolbar.Item-overflowText"></div>/**
688 * @cfg {String} overflowText Text to be used for the menu if the item is overflowed.
691 Ext.reg('tbitem', T.Item);
693 <div id="cls-Ext.Toolbar.Separator"></div>/**
694 * @class Ext.Toolbar.Separator
695 * @extends Ext.Toolbar.Item
696 * A simple class that adds a vertical separator bar between toolbar items
697 * (css class:<tt>'xtb-sep'</tt>). Example usage:
702 {xtype: 'tbseparator'}, // or '-'
708 * Creates a new Separator
711 T.Separator = Ext.extend(T.Item, {
712 onRender : function(ct, position){
713 this.el = ct.createChild({tag:'span', cls:'xtb-sep'}, position);
716 Ext.reg('tbseparator', T.Separator);
718 <div id="cls-Ext.Toolbar.Spacer"></div>/**
719 * @class Ext.Toolbar.Spacer
720 * @extends Ext.Toolbar.Item
721 * A simple element that adds extra horizontal space between items in a toolbar.
722 * By default a 2px wide space is added via css specification:<pre><code>
723 .x-toolbar .xtb-spacer {
727 * <p>Example usage:</p>
732 {xtype: 'tbspacer'}, // or ' '
734 // space width is also configurable via javascript
735 {xtype: 'tbspacer', width: 50}, // add a 50px space
741 * Creates a new Spacer
744 T.Spacer = Ext.extend(T.Item, {
745 <div id="cfg-Ext.Toolbar.Spacer-width"></div>/**
746 * @cfg {Number} width
747 * The width of the spacer in pixels (defaults to 2px via css style <tt>.x-toolbar .xtb-spacer</tt>).
750 onRender : function(ct, position){
751 this.el = ct.createChild({tag:'div', cls:'xtb-spacer', style: this.width?'width:'+this.width+'px':''}, position);
754 Ext.reg('tbspacer', T.Spacer);
756 <div id="cls-Ext.Toolbar.Fill"></div>/**
757 * @class Ext.Toolbar.Fill
758 * @extends Ext.Toolbar.Spacer
759 * A non-rendering placeholder item which instructs the Toolbar's Layout to begin using
760 * the right-justified button container.
765 {xtype: 'tbfill'}, // or '->'
774 T.Fill = Ext.extend(T.Item, {
776 render : Ext.emptyFn,
779 Ext.reg('tbfill', T.Fill);
781 <div id="cls-Ext.Toolbar.TextItem"></div>/**
782 * @class Ext.Toolbar.TextItem
783 * @extends Ext.Toolbar.Item
784 * A simple class that renders text directly into a toolbar
785 * (with css class:<tt>'xtb-text'</tt>). Example usage:
789 {xtype: 'tbtext', text: 'Item 1'} // or simply 'Item 1'
794 * Creates a new TextItem
795 * @param {String/Object} text A text string, or a config object containing a <tt>text</tt> property
798 T.TextItem = Ext.extend(T.Item, {
799 <div id="cfg-Ext.Toolbar.TextItem-text"></div>/**
800 * @cfg {String} text The text to be used as innerHTML (html tags are accepted)
803 constructor: function(config){
804 T.TextItem.superclass.constructor.call(this, Ext.isString(config) ? {text: config} : config);
808 onRender : function(ct, position) {
809 this.autoEl = {cls: 'xtb-text', html: this.text || ''};
810 T.TextItem.superclass.onRender.call(this, ct, position);
813 <div id="method-Ext.Toolbar.TextItem-setText"></div>/**
814 * Updates this item's text, setting the text to be used as innerHTML.
815 * @param {String} t The text to display (html accepted).
817 setText : function(t) {
825 Ext.reg('tbtext', T.TextItem);
828 T.Button = Ext.extend(Ext.Button, {});
829 T.SplitButton = Ext.extend(Ext.SplitButton, {});
830 Ext.reg('tbbutton', T.Button);
831 Ext.reg('tbsplit', T.SplitButton);