Upgrade to ExtJS 4.0.2 - Released 06/09/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  * @class Ext.toolbar.TextItem
17  * @extends Ext.toolbar.Item
18  *
19  * A simple class that renders text directly into a toolbar.
20  *
21  * ## Example usage
22  *
23  * {@img Ext.toolbar.TextItem/Ext.toolbar.TextItem.png TextItem component}
24  *
25  *      Ext.create('Ext.panel.Panel', {
26  *          title: 'Panel with TextItem',
27  *          width: 300,
28  *          height: 200,
29  *          tbar: [
30  *              {xtype: 'tbtext', text: 'Sample TextItem'}
31  *          ],
32  *          renderTo: Ext.getBody()
33  *      });
34  *
35  * @constructor
36  * Creates a new TextItem
37  * @param {Object} text A text string, or a config object containing a <tt>text</tt> property
38  */
39 Ext.define('Ext.toolbar.TextItem', {
40     extend: 'Ext.toolbar.Item',
41     requires: ['Ext.XTemplate'],
42     alias: 'widget.tbtext',
43     alternateClassName: 'Ext.Toolbar.TextItem',
44     
45     /**
46      * @cfg {String} text The text to be used as innerHTML (html tags are accepted)
47      */
48     text: '',
49     
50     renderTpl: '{text}',
51     //
52     baseCls: Ext.baseCSSPrefix + 'toolbar-text',
53     
54     onRender : function() {
55         Ext.apply(this.renderData, {
56             text: this.text
57         });
58         this.callParent(arguments);
59     },
60
61     /**
62      * Updates this item's text, setting the text to be used as innerHTML.
63      * @param {String} t The text to display (html accepted).
64      */
65     setText : function(t) {
66         if (this.rendered) {
67             this.el.update(t);
68             this.ownerCt.doLayout(); // In case an empty text item (centered at zero height) receives new text.
69         } else {
70             this.text = t;
71         }
72     }
73 });