4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-panel-Header'>/**
19 </span> * @class Ext.panel.Header
20 * @extends Ext.container.Container
21 * Simple header class which is used for on {@link Ext.panel.Panel} and {@link Ext.window.Window}
23 Ext.define('Ext.panel.Header', {
24 extend: 'Ext.container.Container',
25 uses: ['Ext.panel.Tool', 'Ext.draw.Component', 'Ext.util.CSS'],
26 alias: 'widget.header',
33 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>'],
35 initComponent: function() {
42 me.indicateDragCls = me.baseCls + '-draggable';
43 me.title = me.title || '&#160;';
44 me.tools = me.tools || [];
45 me.items = me.items || [];
46 me.orientation = me.orientation || 'horizontal';
47 me.dock = (me.dock) ? me.dock : (me.orientation == 'horizontal') ? 'top' : 'left';
49 //add the dock as a ui
50 //this is so we support top/right/left/bottom headers
51 me.addClsWithUI(me.orientation);
52 me.addClsWithUI(me.dock);
54 Ext.applyIf(me.renderSelectors, {
55 body: '.' + me.baseCls + '-body'
59 if (!Ext.isEmpty(me.iconCls)) {
61 me.items.push(me.iconCmp);
65 if (me.orientation == 'vertical') {
66 // Hack for IE6/7's inability to display an inline-block
67 if (Ext.isIE6 || Ext.isIE7) {
68 me.width = this.width || 24;
69 } else if (Ext.isIEQuirks) {
70 me.width = this.width || 25;
76 clearInnerCtOnLayout: true,
77 bindToOwnerCtContainer: false
80 cls: me.baseCls + '-text',
88 if (Ext.isArray(ui)) {
91 rule = Ext.util.CSS.getRule('.' + me.baseCls + '-text-' + ui);
96 Ext.apply(me.textConfig, {
97 'font-family': style.fontFamily,
98 'font-weight': style.fontWeight,
99 'font-size': style.fontSize,
103 me.titleCmp = Ext.create('Ext.draw.Component', {
104 ariaRole : 'heading',
110 items: [ me.textConfig ],
112 textEl: '.' + me.baseCls + '-text'
119 clearInnerCtOnLayout: true,
120 bindToOwnerCtContainer: false
122 me.titleCmp = Ext.create('Ext.Component', {
124 ariaRole : 'heading',
127 renderTpl : ['<span class="{cls}-text {cls}-text-{ui}">{title}</span>'],
134 textEl: '.' + me.baseCls + '-text'
138 me.items.push(me.titleCmp);
141 me.items = me.items.concat(me.tools);
145 initIconCmp: function() {
146 this.iconCmp = Ext.create('Ext.Component', {
148 renderTpl : ['<img alt="" src="{blank}" class="{cls}-icon {iconCls}"/>'],
150 blank : Ext.BLANK_IMAGE_URL,
152 iconCls: this.iconCls,
153 orientation: this.orientation
156 iconEl: '.' + this.baseCls + '-icon'
158 iconCls: this.iconCls
162 afterRender: function() {
165 me.el.unselectable();
166 if (me.indicateDrag) {
167 me.el.addCls(me.indicateDragCls);
176 afterLayout: function() {
178 me.callParent(arguments);
180 // IE7 needs a forced repaint to make the top framing div expand to full width
187 addUIClsToElement: function(cls, force) {
189 result = me.callParent(arguments),
190 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
193 if (!force && me.rendered) {
195 me.body.addCls(me.bodyCls);
197 me.body.addCls(classes);
201 array = me.bodyCls.split(' ');
203 for (i = 0; i < classes.length; i++) {
204 if (!Ext.Array.contains(array, classes[i])) {
205 array.push(classes[i]);
209 me.bodyCls = array.join(' ');
211 me.bodyCls = classes.join(' ');
219 removeUIClsFromElement: function(cls, force) {
221 result = me.callParent(arguments),
222 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
225 if (!force && me.rendered) {
227 me.body.removeCls(me.bodyCls);
229 me.body.removeCls(classes);
233 array = me.bodyCls.split(' ');
235 for (i = 0; i < classes.length; i++) {
236 Ext.Array.remove(array, classes[i]);
239 me.bodyCls = array.join(' ');
247 addUIToElement: function(force) {
251 me.callParent(arguments);
253 cls = me.baseCls + '-body-' + me.ui;
254 if (!force && me.rendered) {
256 me.body.addCls(me.bodyCls);
262 array = me.bodyCls.split(' ');
264 if (!Ext.Array.contains(array, cls)) {
268 me.bodyCls = array.join(' ');
274 if (!force && me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
275 me.titleCmp.textEl.addCls(me.baseCls + '-text-' + me.ui);
280 removeUIFromElement: function() {
284 me.callParent(arguments);
286 cls = me.baseCls + '-body-' + me.ui;
289 me.body.removeCls(me.bodyCls);
291 me.body.removeCls(cls);
295 array = me.bodyCls.split(' ');
296 Ext.Array.remove(array, cls);
297 me.bodyCls = array.join(' ');
303 if (me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
304 me.titleCmp.textEl.removeCls(me.baseCls + '-text-' + me.ui);
308 onClick: function(e) {
309 if (!e.getTarget(Ext.baseCSSPrefix + 'tool')) {
310 this.fireEvent('click', e);
314 getTargetEl: function() {
315 return this.body || this.frameBody || this.el;
318 <span id='Ext-panel-Header-method-setTitle'> /**
319 </span> * Sets the title of the header.
320 * @param {String} title The title to be set
322 setTitle: function(title) {
325 if (me.titleCmp.rendered) {
326 if (me.titleCmp.surface) {
327 me.title = title || '';
328 var sprite = me.titleCmp.surface.items.items[0],
329 surface = me.titleCmp.surface;
331 surface.remove(sprite);
332 me.textConfig.type = 'text';
333 me.textConfig.text = title;
334 sprite = surface.add(me.textConfig);
335 sprite.setAttributes({
340 me.titleCmp.autoSizeSurface();
342 me.title = title || '&#160;';
343 me.titleCmp.textEl.update(me.title);
364 <span id='Ext-panel-Header-method-setIconCls'> /**
365 </span> * Sets the CSS class that provides the icon image for this panel. This method will replace any existing
366 * icon class if one has already been set and fire the {@link #iconchange} event after completion.
367 * @param {String} cls The new CSS class name
369 setIconCls: function(cls) {
373 this.insert(0, this.iconCmp);
376 if (!cls || !cls.length) {
377 this.iconCmp.destroy();
380 var iconCmp = this.iconCmp,
383 el.removeCls(iconCmp.iconCls);
385 iconCmp.iconCls = cls;
390 <span id='Ext-panel-Header-method-addTool'> /**
391 </span> * Add a tool to the header
392 * @param {Object} tool
394 addTool: function(tool) {
395 this.tools.push(this.add(tool));
398 <span id='Ext-panel-Header-method-onAdd'> /**
400 * Set up the tools.&lt;tool type> link in the owning Panel.
401 * Bind the tool to its owning Panel.
405 onAdd: function(component, index) {
406 this.callParent([arguments]);
407 if (component instanceof Ext.panel.Tool) {
408 component.bindTo(this.ownerCt);
409 this.tools[component.type] = component;