2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.Toolbar
\r
11 * @extends Ext.BoxComponent
\r
12 * Basic Toolbar class. Toolbar elements can be created explicitly via their constructors, or implicitly
\r
13 * via their xtypes. Some items also have shortcut strings for creation.
\r
15 * Creates a new Toolbar
\r
16 * @param {Object/Array} config A config object or an array of buttons to add
\r
18 Ext.Toolbar = function(config){
\r
19 if(Ext.isArray(config)){
\r
20 config = {buttons:config};
\r
22 Ext.Toolbar.superclass.constructor.call(this, config);
\r
27 var T = Ext.Toolbar;
\r
29 Ext.extend(T, Ext.BoxComponent, {
\r
34 initComponent : function(){
\r
35 T.superclass.initComponent.call(this);
\r
38 this.buttons = this.items;
\r
41 * A MixedCollection of this Toolbar's items
\r
43 * @type Ext.util.MixedCollection
\r
45 this.items = new Ext.util.MixedCollection(false, function(o){
\r
46 return o.itemId || o.id || Ext.id();
\r
52 cls:'x-toolbar x-small-editor',
\r
53 html:'<table cellspacing="0"><tr></tr></table>'
\r
57 onRender : function(ct, position){
\r
58 this.el = ct.createChild(Ext.apply({ id: this.id },this.autoCreate), position);
\r
59 this.tr = this.el.child("tr", true);
\r
63 afterRender : function(){
\r
64 T.superclass.afterRender.call(this);
\r
66 this.add.apply(this, this.buttons);
\r
67 delete this.buttons;
\r
72 * Adds element(s) to the toolbar -- this function takes a variable number of
\r
73 * arguments of mixed type and adds them to the toolbar.
\r
74 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
\r
76 * <li>{@link Ext.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
\r
77 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
\r
78 * <li>Field: Any form field (equivalent to {@link #addField})</li>
\r
79 * <li>Item: Any subclass of {@link Ext.Toolbar.Item} (equivalent to {@link #addItem})</li>
\r
80 * <li>String: Any generic string (gets wrapped in a {@link Ext.Toolbar.TextItem}, equivalent to {@link #addText}).
\r
81 * Note that there are a few special strings that are treated differently as explained next.</li>
\r
82 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
\r
83 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
\r
84 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
\r
86 * @param {Mixed} arg2
\r
87 * @param {Mixed} etc.
\r
90 var a = arguments, l = a.length;
\r
91 for(var i = 0; i < l; i++){
\r
93 if(el.isFormField){ // some kind of form field
\r
95 }else if(el.render){ // some kind of Toolbar.Item
\r
97 }else if(typeof el == "string"){ // string
\r
98 if(el == "separator" || el == "-"){
\r
99 this.addSeparator();
\r
100 }else if(el == " "){
\r
102 }else if(el == "->"){
\r
107 }else if(el.tagName){ // element
\r
108 this.addElement(el);
\r
109 }else if(typeof el == "object"){ // must be button config?
\r
111 this.addField(Ext.ComponentMgr.create(el, 'button'));
\r
113 this.addButton(el);
\r
121 * @return {Ext.Toolbar.Item} The separator item
\r
123 addSeparator : function(){
\r
124 return this.addItem(new T.Separator());
\r
128 * Adds a spacer element
\r
129 * @return {Ext.Toolbar.Spacer} The spacer item
\r
131 addSpacer : function(){
\r
132 return this.addItem(new T.Spacer());
\r
136 * Adds a fill element that forces subsequent additions to the right side of the toolbar
\r
137 * @return {Ext.Toolbar.Fill} The fill item
\r
139 addFill : function(){
\r
140 return this.addItem(new T.Fill());
\r
144 * Adds any standard HTML element to the toolbar
\r
145 * @param {Mixed} el The element or id of the element to add
\r
146 * @return {Ext.Toolbar.Item} The element's item
\r
148 addElement : function(el){
\r
149 return this.addItem(new T.Item(el));
\r
153 * Adds any Toolbar.Item or subclass
\r
154 * @param {Ext.Toolbar.Item} item
\r
155 * @return {Ext.Toolbar.Item} The item
\r
157 addItem : function(item){
\r
158 var td = this.nextBlock();
\r
159 this.initMenuTracking(item);
\r
161 this.items.add(item);
\r
166 * Adds a button (or buttons). See {@link Ext.Toolbar.Button} for more info on the config.
\r
167 * @param {Object/Array} config A button config or array of configs
\r
168 * @return {Ext.Toolbar.Button/Array}
\r
170 addButton : function(config){
\r
171 if(Ext.isArray(config)){
\r
173 for(var i = 0, len = config.length; i < len; i++) {
\r
174 buttons.push(this.addButton(config[i]));
\r
179 if(!(config instanceof T.Button)){
\r
180 b = config.split ?
\r
181 new T.SplitButton(config) :
\r
182 new T.Button(config);
\r
184 var td = this.nextBlock();
\r
185 this.initMenuTracking(b);
\r
192 initMenuTracking : function(item){
\r
193 if(this.trackMenus && item.menu){
\r
195 'menutriggerover' : this.onButtonTriggerOver,
\r
196 'menushow' : this.onButtonMenuShow,
\r
197 'menuhide' : this.onButtonMenuHide,
\r
204 * Adds text to the toolbar
\r
205 * @param {String} text The text to add
\r
206 * @return {Ext.Toolbar.Item} The element's item
\r
208 addText : function(text){
\r
209 return this.addItem(new T.TextItem(text));
\r
213 * Inserts any {@link Ext.Toolbar.Item}/{@link Ext.Toolbar.Button} at the specified index.
\r
214 * @param {Number} index The index where the item is to be inserted
\r
215 * @param {Object/Ext.Toolbar.Item/Ext.Toolbar.Button/Array} item The button, or button config object to be
\r
216 * inserted, or an array of buttons/configs.
\r
217 * @return {Ext.Toolbar.Button/Item}
\r
219 insertButton : function(index, item){
\r
220 if(Ext.isArray(item)){
\r
222 for(var i = 0, len = item.length; i < len; i++) {
\r
223 buttons.push(this.insertButton(index + i, item[i]));
\r
227 if (!(item instanceof T.Button)){
\r
228 item = new T.Button(item);
\r
230 var td = document.createElement("td");
\r
231 this.tr.insertBefore(td, this.tr.childNodes[index]);
\r
232 this.initMenuTracking(item);
\r
234 this.items.insert(index, item);
\r
239 * Adds a new element to the toolbar from the passed {@link Ext.DomHelper} config
\r
240 * @param {Object} config
\r
241 * @return {Ext.Toolbar.Item} The element's item
\r
243 addDom : function(config, returnEl){
\r
244 var td = this.nextBlock();
\r
245 Ext.DomHelper.overwrite(td, config);
\r
246 var ti = new T.Item(td.firstChild);
\r
248 this.items.add(ti);
\r
253 * Adds a dynamically rendered Ext.form field (TextField, ComboBox, etc). Note: the field should not have
\r
254 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
\r
255 * @param {Ext.form.Field} field
\r
256 * @return {Ext.Toolbar.Item}
\r
258 addField : function(field){
\r
259 var td = this.nextBlock();
\r
261 var ti = new T.Item(td.firstChild);
\r
263 this.items.add(field);
\r
268 nextBlock : function(){
\r
269 var td = document.createElement("td");
\r
270 this.tr.appendChild(td);
\r
275 onDestroy : function(){
\r
276 Ext.Toolbar.superclass.onDestroy.call(this);
\r
278 if(this.items){ // rendered?
\r
279 Ext.destroy.apply(Ext, this.items.items);
\r
281 Ext.Element.uncache(this.tr);
\r
286 onDisable : function(){
\r
287 this.items.each(function(item){
\r
295 onEnable : function(){
\r
296 this.items.each(function(item){
\r
304 onButtonTriggerOver : function(btn){
\r
305 if(this.activeMenuBtn && this.activeMenuBtn != btn){
\r
306 this.activeMenuBtn.hideMenu();
\r
308 this.activeMenuBtn = btn;
\r
313 onButtonMenuShow : function(btn){
\r
314 this.activeMenuBtn = btn;
\r
318 onButtonMenuHide : function(btn){
\r
319 delete this.activeMenuBtn;
\r
323 * @cfg {String} autoEl @hide
\r
326 Ext.reg('toolbar', Ext.Toolbar);
\r
329 * @class Ext.Toolbar.Item
\r
330 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
\r
332 * Creates a new Item
\r
333 * @param {HTMLElement} el
\r
335 T.Item = function(el){
\r
336 this.el = Ext.getDom(el);
\r
337 this.id = Ext.id(this.el);
\r
338 this.hidden = false;
\r
341 T.Item.prototype = {
\r
344 * Get this item's HTML Element
\r
345 * @return {HTMLElement}
\r
347 getEl : function(){
\r
352 render : function(td){
\r
354 td.appendChild(this.el);
\r
358 * Removes and destroys this item.
\r
360 destroy : function(){
\r
362 var el = Ext.get(this.el);
\r
365 Ext.removeNode(this.td);
\r
372 this.hidden = false;
\r
373 this.td.style.display = "";
\r
380 this.hidden = true;
\r
381 this.td.style.display = "none";
\r
385 * Convenience function for boolean show/hide.
\r
386 * @param {Boolean} visible true to show/false to hide
\r
388 setVisible: function(visible){
\r
397 * Try to focus this item
\r
399 focus : function(){
\r
400 Ext.fly(this.el).focus();
\r
404 * Disables this item.
\r
406 disable : function(){
\r
407 Ext.fly(this.td).addClass("x-item-disabled");
\r
408 this.disabled = true;
\r
409 this.el.disabled = true;
\r
413 * Enables this item.
\r
415 enable : function(){
\r
416 Ext.fly(this.td).removeClass("x-item-disabled");
\r
417 this.disabled = false;
\r
418 this.el.disabled = false;
\r
421 Ext.reg('tbitem', T.Item);
\r
425 * @class Ext.Toolbar.Separator
\r
426 * @extends Ext.Toolbar.Item
\r
427 * A simple class that adds a vertical separator bar between toolbar items. Example usage:
\r
432 {xtype: 'tbseparator'}, // or '-'
\r
438 * Creates a new Separator
\r
440 T.Separator = function(){
\r
441 var s = document.createElement("span");
\r
442 s.className = "ytb-sep";
\r
443 T.Separator.superclass.constructor.call(this, s);
\r
445 Ext.extend(T.Separator, T.Item, {
\r
446 enable:Ext.emptyFn,
\r
447 disable:Ext.emptyFn,
\r
450 Ext.reg('tbseparator', T.Separator);
\r
453 * @class Ext.Toolbar.Spacer
\r
454 * @extends Ext.Toolbar.Item
\r
455 * A simple element that adds extra horizontal space between items in a toolbar.
\r
460 {xtype: 'tbspacer'}, // or ' '
\r
466 * Creates a new Spacer
\r
468 T.Spacer = function(){
\r
469 var s = document.createElement("div");
\r
470 s.className = "ytb-spacer";
\r
471 T.Spacer.superclass.constructor.call(this, s);
\r
473 Ext.extend(T.Spacer, T.Item, {
\r
474 enable:Ext.emptyFn,
\r
475 disable:Ext.emptyFn,
\r
479 Ext.reg('tbspacer', T.Spacer);
\r
482 * @class Ext.Toolbar.Fill
\r
483 * @extends Ext.Toolbar.Spacer
\r
484 * A simple element that adds a greedy (100% width) horizontal space between items in a toolbar.
\r
489 {xtype: 'tbfill'}, // or '->'
\r
495 * Creates a new Spacer
\r
497 T.Fill = Ext.extend(T.Spacer, {
\r
499 render : function(td){
\r
500 td.style.width = '100%';
\r
501 T.Fill.superclass.render.call(this, td);
\r
504 Ext.reg('tbfill', T.Fill);
\r
507 * @class Ext.Toolbar.TextItem
\r
508 * @extends Ext.Toolbar.Item
\r
509 * A simple class that renders text directly into a toolbar.
\r
513 {xtype: 'tbtext', text: 'Item 1'} // or simply 'Item 1'
\r
518 * Creates a new TextItem
\r
519 * @param {String/Object} text A text string, or a config object containing a <tt>text</tt> property
\r
521 T.TextItem = function(t){
\r
522 var s = document.createElement("span");
\r
523 s.className = "ytb-text";
\r
524 s.innerHTML = t.text ? t.text : t;
\r
525 T.TextItem.superclass.constructor.call(this, s);
\r
527 Ext.extend(T.TextItem, T.Item, {
\r
528 enable:Ext.emptyFn,
\r
529 disable:Ext.emptyFn,
\r
532 Ext.reg('tbtext', T.TextItem);
\r
536 * @class Ext.Toolbar.Button
\r
537 * @extends Ext.Button
\r
538 * A button that renders into a toolbar. Use the <tt>handler</tt> config to specify a callback function
\r
539 * to handle the button's click event.
\r
543 {text: 'OK', handler: okHandler} // tbbutton is the default xtype if not specified
\r
548 * Creates a new Button
\r
549 * @param {Object} config A standard {@link Ext.Button} config object
\r
551 T.Button = Ext.extend(Ext.Button, {
\r
554 onDestroy : function(){
\r
555 T.Button.superclass.onDestroy.call(this);
\r
556 if(this.container){
\r
557 this.container.remove();
\r
561 Ext.reg('tbbutton', T.Button);
\r
564 * @class Ext.Toolbar.SplitButton
\r
565 * @extends Ext.SplitButton
\r
566 * A split button that renders into a toolbar.
\r
573 handler: optionsHandler, // handle a click on the button itself
\r
574 menu: new Ext.menu.Menu({
\r
576 // These items will display in a dropdown menu when the split arrow is clicked
\r
577 {text: 'Item 1', handler: item1Handler},
\r
578 {text: 'Item 2', handler: item2Handler}
\r
586 * Creates a new SplitButton
\r
587 * @param {Object} config A standard {@link Ext.SplitButton} config object
\r
589 T.SplitButton = Ext.extend(Ext.SplitButton, {
\r
592 onDestroy : function(){
\r
593 T.SplitButton.superclass.onDestroy.call(this);
\r
594 if(this.container){
\r
595 this.container.remove();
\r
600 Ext.reg('tbsplit', T.SplitButton);
\r
601 // backwards compat
\r
602 T.MenuButton = T.SplitButton;
\r