TextItem.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * A simple class that renders text directly into a toolbar.
  3. *
  4. * @example
  5. * Ext.create('Ext.panel.Panel', {
  6. * title: 'Panel with TextItem',
  7. * width: 300,
  8. * height: 200,
  9. * tbar: [
  10. * { xtype: 'tbtext', text: 'Sample Text Item' }
  11. * ],
  12. * renderTo: Ext.getBody()
  13. * });
  14. *
  15. * @constructor
  16. * Creates a new TextItem
  17. * @param {Object} text A text string, or a config object containing a #text property
  18. */
  19. Ext.define('Ext.toolbar.TextItem', {
  20. extend: 'Ext.toolbar.Item',
  21. requires: ['Ext.XTemplate'],
  22. alias: 'widget.tbtext',
  23. alternateClassName: 'Ext.Toolbar.TextItem',
  24. /**
  25. * @cfg {String} text
  26. * The text to be used as innerHTML (html tags are accepted).
  27. */
  28. text: '',
  29. renderTpl: '{text}',
  30. //
  31. baseCls: Ext.baseCSSPrefix + 'toolbar-text',
  32. beforeRender : function() {
  33. var me = this;
  34. me.callParent();
  35. Ext.apply(me.renderData, {
  36. text: me.text
  37. });
  38. },
  39. /**
  40. * Updates this item's text, setting the text to be used as innerHTML.
  41. * @param {String} text The text to display (html accepted).
  42. */
  43. setText : function(text) {
  44. var me = this;
  45. if (me.rendered) {
  46. me.el.update(text);
  47. me.updateLayout();
  48. } else {
  49. this.text = text;
  50. }
  51. }
  52. });