Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / toolbar / TextItem.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * A simple class that renders text directly into a toolbar.
17  *
18  *     @example
19  *     Ext.create('Ext.panel.Panel', {
20  *         title: 'Panel with TextItem',
21  *         width: 300,
22  *         height: 200,
23  *         tbar: [
24  *             { xtype: 'tbtext', text: 'Sample Text Item' }
25  *         ],
26  *         renderTo: Ext.getBody()
27  *     });
28  *
29  * @constructor
30  * Creates a new TextItem
31  * @param {Object} text A text string, or a config object containing a <tt>text</tt> property
32  */
33 Ext.define('Ext.toolbar.TextItem', {
34     extend: 'Ext.toolbar.Item',
35     requires: ['Ext.XTemplate'],
36     alias: 'widget.tbtext',
37     alternateClassName: 'Ext.Toolbar.TextItem',
38
39     /**
40      * @cfg {String} text The text to be used as innerHTML (html tags are accepted)
41      */
42     text: '',
43
44     renderTpl: '{text}',
45     //
46     baseCls: Ext.baseCSSPrefix + 'toolbar-text',
47
48     onRender : function() {
49         Ext.apply(this.renderData, {
50             text: this.text
51         });
52         this.callParent(arguments);
53     },
54
55     /**
56      * Updates this item's text, setting the text to be used as innerHTML.
57      * @param {String} t The text to display (html accepted).
58      */
59     setText : function(t) {
60         if (this.rendered) {
61             this.el.update(t);
62             this.ownerCt.doLayout(); // In case an empty text item (centered at zero height) receives new text.
63         } else {
64             this.text = t;
65         }
66     }
67 });