Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Tip2.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-layout-component-Tip'>/**
19 </span> * Component layout for Tip/ToolTip/etc. components
20  * @class Ext.layout.component.Tip
21  * @extends Ext.layout.component.Dock
22  * @private
23  */
24
25 Ext.define('Ext.layout.component.Tip', {
26
27     /* Begin Definitions */
28
29     alias: ['layout.tip'],
30
31     extend: 'Ext.layout.component.Dock',
32
33     /* End Definitions */
34
35     type: 'tip',
36     
37     onLayout: function(width, height) {
38         var me = this,
39             owner = me.owner,
40             el = owner.el,
41             minWidth,
42             maxWidth,
43             naturalWidth,
44             constrainedWidth,
45             xy = el.getXY();
46
47         // Position offscreen so the natural width is not affected by the viewport's right edge
48         el.setXY([-9999,-9999]);
49
50         // Calculate initial layout
51         this.callParent(arguments);
52
53         // Handle min/maxWidth for auto-width tips
54         if (!Ext.isNumber(width)) {
55             minWidth = owner.minWidth;
56             maxWidth = owner.maxWidth;
57             // IE6/7 in strict mode have a problem doing an autoWidth
58             if (Ext.isStrict &amp;&amp; (Ext.isIE6 || Ext.isIE7)) {
59                 constrainedWidth = me.doAutoWidth();
60             } else {
61                 naturalWidth = el.getWidth();
62             }
63             if (naturalWidth &lt; minWidth) {
64                 constrainedWidth = minWidth;
65             }
66             else if (naturalWidth &gt; maxWidth) {
67                 constrainedWidth = maxWidth;
68             }
69             if (constrainedWidth) {
70                 this.callParent([constrainedWidth, height]);
71             }
72         }
73
74         // Restore position
75         el.setXY(xy);
76     },
77     
78     doAutoWidth: function(){
79         var me = this,
80             owner = me.owner,
81             body = owner.body,
82             width = body.getTextWidth();
83             
84         if (owner.header) {
85             width = Math.max(width, owner.header.getWidth());
86         }
87         if (!Ext.isDefined(me.frameWidth)) {
88             me.frameWidth = owner.el.getWidth() - body.getWidth();
89         }
90         width += me.frameWidth + body.getPadding('lr');
91         return width;
92     }
93 });
94 </pre>
95 </body>
96 </html>