4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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',
34 '<div id="{id}-body" class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl>',
35 '<tpl if="uiCls">',
36 '<tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl>',
38 '<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>></div>'],
40 <span id='Ext-panel-Header-cfg-title'> /**
41 </span> * @cfg {String} title
42 * The title text to display
45 <span id='Ext-panel-Header-cfg-iconCls'> /**
46 </span> * @cfg {String} iconCls
47 * CSS class for icon in header. Used for displaying an icon to the left of a title.
50 initComponent: function() {
58 me.indicateDragCls = me.baseCls + '-draggable';
59 me.title = me.title || '&#160;';
60 me.tools = me.tools || [];
61 me.items = me.items || [];
62 me.orientation = me.orientation || 'horizontal';
63 me.dock = (me.dock) ? me.dock : (me.orientation == 'horizontal') ? 'top' : 'left';
65 //add the dock as a ui
66 //this is so we support top/right/left/bottom headers
67 me.addClsWithUI(me.orientation);
68 me.addClsWithUI(me.dock);
70 me.addChildEls('body');
73 if (!Ext.isEmpty(me.iconCls)) {
75 me.items.push(me.iconCmp);
79 if (me.orientation == 'vertical') {
80 // Hack for IE6/7's inability to display an inline-block
81 if (Ext.isIE6 || Ext.isIE7) {
82 me.width = this.width || 24;
83 } else if (Ext.isIEQuirks) {
84 me.width = this.width || 25;
90 clearInnerCtOnLayout: true,
91 bindToOwnerCtContainer: false
94 cls: me.baseCls + '-text',
102 if (Ext.isArray(ui)) {
105 ruleStyle = '.' + me.baseCls + '-text-' + ui;
106 if (Ext.scopeResetCSS) {
107 ruleStyle = '.' + Ext.baseCSSPrefix + 'reset ' + ruleStyle;
109 rule = Ext.util.CSS.getRule(ruleStyle);
114 Ext.apply(me.textConfig, {
115 'font-family': style.fontFamily,
116 'font-weight': style.fontWeight,
117 'font-size': style.fontSize,
121 me.titleCmp = Ext.create('Ext.draw.Component', {
122 ariaRole : 'heading',
128 items: [ me.textConfig ],
129 // this is a bit of a cheat: we are not selecting an element of titleCmp
130 // but rather of titleCmp.items[0] (so we cannot use childEls)
132 textEl: '.' + me.baseCls + '-text'
139 clearInnerCtOnLayout: true,
140 bindToOwnerCtContainer: false
142 me.titleCmp = Ext.create('Ext.Component', {
144 ariaRole : 'heading',
147 cls: me.baseCls + '-text-container',
149 '<span id="{id}-textEl" class="{cls}-text {cls}-text-{ui}">{title}</span>'
159 me.items.push(me.titleCmp);
162 me.items = me.items.concat(me.tools);
166 initIconCmp: function() {
167 this.iconCmp = Ext.create('Ext.Component', {
170 '<img id="{id}-iconEl" alt="" src="{blank}" class="{cls}-icon {iconCls}"/>'
173 blank : Ext.BLANK_IMAGE_URL,
175 iconCls: this.iconCls,
176 orientation: this.orientation
178 childEls: ['iconEl'],
179 iconCls: this.iconCls
183 afterRender: function() {
186 me.el.unselectable();
187 if (me.indicateDrag) {
188 me.el.addCls(me.indicateDragCls);
197 afterLayout: function() {
199 me.callParent(arguments);
201 // IE7 needs a forced repaint to make the top framing div expand to full width
208 addUIClsToElement: function(cls, force) {
210 result = me.callParent(arguments),
211 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
214 if (!force && me.rendered) {
216 me.body.addCls(me.bodyCls);
218 me.body.addCls(classes);
222 array = me.bodyCls.split(' ');
224 for (i = 0; i < classes.length; i++) {
225 if (!Ext.Array.contains(array, classes[i])) {
226 array.push(classes[i]);
230 me.bodyCls = array.join(' ');
232 me.bodyCls = classes.join(' ');
240 removeUIClsFromElement: function(cls, force) {
242 result = me.callParent(arguments),
243 classes = [me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
246 if (!force && me.rendered) {
248 me.body.removeCls(me.bodyCls);
250 me.body.removeCls(classes);
254 array = me.bodyCls.split(' ');
256 for (i = 0; i < classes.length; i++) {
257 Ext.Array.remove(array, classes[i]);
260 me.bodyCls = array.join(' ');
268 addUIToElement: function(force) {
272 me.callParent(arguments);
274 cls = me.baseCls + '-body-' + me.ui;
275 if (!force && me.rendered) {
277 me.body.addCls(me.bodyCls);
283 array = me.bodyCls.split(' ');
285 if (!Ext.Array.contains(array, cls)) {
289 me.bodyCls = array.join(' ');
295 if (!force && me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
296 me.titleCmp.textEl.addCls(me.baseCls + '-text-' + me.ui);
301 removeUIFromElement: function() {
305 me.callParent(arguments);
307 cls = me.baseCls + '-body-' + me.ui;
310 me.body.removeCls(me.bodyCls);
312 me.body.removeCls(cls);
316 array = me.bodyCls.split(' ');
317 Ext.Array.remove(array, cls);
318 me.bodyCls = array.join(' ');
324 if (me.titleCmp && me.titleCmp.rendered && me.titleCmp.textEl) {
325 me.titleCmp.textEl.removeCls(me.baseCls + '-text-' + me.ui);
329 onClick: function(e) {
330 if (!e.getTarget(Ext.baseCSSPrefix + 'tool')) {
331 this.fireEvent('click', e);
335 getTargetEl: function() {
336 return this.body || this.frameBody || this.el;
339 <span id='Ext-panel-Header-method-setTitle'> /**
340 </span> * Sets the title of the header.
341 * @param {String} title The title to be set
343 setTitle: function(title) {
346 if (me.titleCmp.rendered) {
347 if (me.titleCmp.surface) {
348 me.title = title || '';
349 var sprite = me.titleCmp.surface.items.items[0],
350 surface = me.titleCmp.surface;
352 surface.remove(sprite);
353 me.textConfig.type = 'text';
354 me.textConfig.text = title;
355 sprite = surface.add(me.textConfig);
356 sprite.setAttributes({
361 me.titleCmp.autoSizeSurface();
363 me.title = title || '&#160;';
364 me.titleCmp.textEl.update(me.title);
385 <span id='Ext-panel-Header-method-setIconCls'> /**
386 </span> * Sets the CSS class that provides the icon image for this header. This method will replace any existing
387 * icon class if one has already been set.
388 * @param {String} cls The new CSS class name
390 setIconCls: function(cls) {
392 isEmpty = !cls || !cls.length,
393 iconCmp = me.iconCmp,
397 if (!me.iconCmp && !isEmpty) {
399 me.insert(0, me.iconCmp);
400 } else if (iconCmp) {
402 me.iconCmp.destroy();
405 el.removeCls(iconCmp.iconCls);
407 iconCmp.iconCls = cls;
412 <span id='Ext-panel-Header-method-addTool'> /**
413 </span> * Add a tool to the header
414 * @param {Object} tool
416 addTool: function(tool) {
417 this.tools.push(this.add(tool));
420 <span id='Ext-panel-Header-method-onAdd'> /**
422 * Set up the tools.&lt;tool type> link in the owning Panel.
423 * Bind the tool to its owning Panel.
427 onAdd: function(component, index) {
428 this.callParent([arguments]);
429 if (component instanceof Ext.panel.Tool) {
430 component.bindTo(this.ownerCt);
431 this.tools[component.type] = component;