2 * @class Ext.panel.Header
3 * @extends Ext.container.Container
4 * Simple header class which is used for on {@link Ext.panel.Panel} and {@link Ext.window.Window}
7 Ext.define('Ext.panel.Header', {
8 extend: 'Ext.container.Container',
9 uses: ['Ext.panel.Tool', 'Ext.draw.Component', 'Ext.util.CSS'],
10 alias: 'widget.header',
17 renderTpl: ['<div class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl><tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl></tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>></div>'],
19 initComponent: function() {
26 me.indicateDragCls = me.baseCls + '-draggable';
27 me.title = me.title || ' ';
28 me.tools = me.tools || [];
29 me.items = me.items || [];
30 me.orientation = me.orientation || 'horizontal';
31 me.dock = (me.dock) ? me.dock : (me.orientation == 'horizontal') ? 'top' : 'left';
33 //add the dock as a ui
34 //this is so we support top/right/left/bottom headers
35 me.addClsWithUI(me.orientation);
36 me.addClsWithUI(me.dock);
38 Ext.applyIf(me.renderSelectors, {
39 body: '.' + me.baseCls + '-body'
43 if (!Ext.isEmpty(me.iconCls)) {
45 me.items.push(me.iconCmp);
49 if (me.orientation == 'vertical') {
50 // Hack for IE6/7's inability to display an inline-block
51 if (Ext.isIE6 || Ext.isIE7) {
52 me.width = this.width || 24;
53 } else if (Ext.isIEQuirks) {
54 me.width = this.width || 25;
60 clearInnerCtOnLayout: true,
61 bindToOwnerCtContainer: false
64 cls: me.baseCls + '-text',
72 if (Ext.isArray(ui)) {
75 rule = Ext.util.CSS.getRule('.' + me.baseCls + '-text-' + ui);
80 Ext.apply(me.textConfig, {
81 'font-family': style.fontFamily,
82 'font-weight': style.fontWeight,
83 'font-size': style.fontSize,
87 me.titleCmp = Ext.create('Ext.draw.Component', {
93 items: [ me.textConfig ],
95 textEl: '.' + me.baseCls + '-text'
102 clearInnerCtOnLayout: true,
103 bindToOwnerCtContainer: false
105 me.titleCmp = Ext.create('Ext.Component', {
107 ariaRole : 'heading',
109 renderTpl : ['<span class="{cls}-text {cls}-text-{ui}">{title}</span>'],
116 textEl: '.' + me.baseCls + '-text'
120 me.items.push(me.titleCmp);
131 me.items = me.items.concat(me.tools);
135 initIconCmp: function() {
136 this.iconCmp = Ext.create('Ext.Component', {
138 renderTpl : ['<img alt="" src="{blank}" class="{cls}-icon {iconCls}"/>'],
140 blank : Ext.BLANK_IMAGE_URL,
142 iconCls: this.iconCls,
143 orientation: this.orientation
146 iconEl: '.' + this.baseCls + '-icon'
148 iconCls: this.iconCls
152 afterRender: function() {
155 me.el.unselectable();
156 if (me.indicateDrag) {
157 me.el.addCls(me.indicateDragCls);
166 afterLayout: function() {
168 me.callParent(arguments);
170 // IE7 needs a forced repaint to make the top framing div expand to full width
177 addUIClsToElement: function(cls, force) {
180 me.callParent(arguments);
182 if (!force && me.rendered) {
183 me.body.addCls(me.baseCls + '-body-' + cls);
184 me.body.addCls(me.baseCls + '-body-' + me.ui + '-' + cls);
189 removeUIClsFromElement: function(cls, force) {
192 me.callParent(arguments);
194 if (!force && me.rendered) {
195 me.body.removeCls(me.baseCls + '-body-' + cls);
196 me.body.removeCls(me.baseCls + '-body-' + me.ui + '-' + cls);
201 addUIToElement: function(force) {
204 me.callParent(arguments);
206 if (!force && me.rendered) {
207 me.body.addCls(me.baseCls + '-body-' + me.ui);
210 if (!force && me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
211 me.titleCmp.textEl.addCls(me.baseCls + '-text-' + me.ui);
216 removeUIFromElement: function() {
219 me.callParent(arguments);
222 me.body.removeCls(me.baseCls + '-body-' + me.ui);
225 if (me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
226 me.titleCmp.textEl.removeCls(me.baseCls + '-text-' + me.ui);
230 onClick: function(e) {
231 if (!e.getTarget(Ext.baseCSSPrefix + 'tool')) {
232 this.fireEvent('click', e);
236 getTargetEl: function() {
237 return this.body || this.frameBody || this.el;
241 * Sets the title of the header.
242 * @param {String} title The title to be set
244 setTitle: function(title) {
247 if (me.titleCmp.rendered) {
248 if (me.titleCmp.surface) {
249 me.title = title || '';
250 var sprite = me.titleCmp.surface.items.items[0],
251 surface = me.titleCmp.surface;
253 surface.remove(sprite);
254 me.textConfig.type = 'text';
255 me.textConfig.text = title;
256 sprite = surface.add(me.textConfig);
257 sprite.setAttributes({
262 me.titleCmp.autoSizeSurface();
264 me.title = title || ' ';
265 me.titleCmp.textEl.update(me.title);
287 * Sets the CSS class that provides the icon image for this panel. This method will replace any existing
288 * icon class if one has already been set and fire the {@link #iconchange} event after completion.
289 * @param {String} cls The new CSS class name
291 setIconCls: function(cls) {
295 this.insert(0, this.iconCmp);
298 if (!cls || !cls.length) {
299 this.iconCmp.destroy();
302 var iconCmp = this.iconCmp,
305 el.removeCls(iconCmp.iconCls);
307 iconCmp.iconCls = cls;
313 * Add a tool to the header
314 * @param {Object} tool
316 addTool: function(tool) {
317 this.tools.push(this.add(tool));
322 * Set up the tools.<tool type> link in the owning Panel.
323 * Bind the tool to its owning Panel.
327 onAdd: function(component, index) {
328 this.callParent([arguments]);
329 if (component instanceof Ext.panel.Tool) {
330 component.bindTo(this.ownerCt);
331 this.tools[component.type] = component;