Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Tip.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js"><div id="cls-Ext.Tip"></div>/**\r
9  * @class Ext.Tip\r
10  * @extends Ext.Panel\r
11  * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and\r
12  * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned\r
13  * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.\r
14  * @constructor\r
15  * Create a new Tip\r
16  * @param {Object} config The configuration options\r
17  */\r
18 Ext.Tip = Ext.extend(Ext.Panel, {\r
19     <div id="cfg-Ext.Tip-closable"></div>/**\r
20      * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).\r
21      */\r
22     <div id="cfg-Ext.Tip-width"></div>/**\r
23      * @cfg {Number} width\r
24      * Width in pixels of the tip (defaults to auto).  Width will be ignored if it exceeds the bounds of\r
25      * {@link #minWidth} or {@link #maxWidth}.  The maximum supported value is 500.\r
26      */\r
27     <div id="cfg-Ext.Tip-minWidth"></div>/**\r
28      * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).\r
29      */\r
30     minWidth : 40,\r
31     <div id="cfg-Ext.Tip-maxWidth"></div>/**\r
32      * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300).  The maximum supported value is 500.\r
33      */\r
34     maxWidth : 300,\r
35     <div id="cfg-Ext.Tip-shadow"></div>/**\r
36      * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"\r
37      * for bottom-right shadow (defaults to "sides").\r
38      */\r
39     shadow : "sides",\r
40     <div id="cfg-Ext.Tip-defaultAlign"></div>/**\r
41      * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value\r
42      * for this tip relative to its element of origin (defaults to "tl-bl?").\r
43      */\r
44     defaultAlign : "tl-bl?",\r
45     autoRender: true,\r
46     quickShowInterval : 250,\r
47 \r
48     // private panel overrides\r
49     frame:true,\r
50     hidden:true,\r
51     baseCls: 'x-tip',\r
52     floating:{shadow:true,shim:true,useDisplay:true,constrain:false},\r
53     autoHeight:true,\r
54 \r
55     closeAction: 'hide',\r
56 \r
57     // private\r
58     initComponent : function(){\r
59         Ext.Tip.superclass.initComponent.call(this);\r
60         if(this.closable && !this.title){\r
61             this.elements += ',header';\r
62         }\r
63     },\r
64 \r
65     // private\r
66     afterRender : function(){\r
67         Ext.Tip.superclass.afterRender.call(this);\r
68         if(this.closable){\r
69             this.addTool({\r
70                 id: 'close',\r
71                 handler: this[this.closeAction],\r
72                 scope: this\r
73             });\r
74         }\r
75     },\r
76 \r
77     <div id="method-Ext.Tip-showAt"></div>/**\r
78      * Shows this tip at the specified XY position.  Example usage:\r
79      * <pre><code>\r
80 // Show the tip at x:50 and y:100\r
81 tip.showAt([50,100]);\r
82 </code></pre>\r
83      * @param {Array} xy An array containing the x and y coordinates\r
84      */\r
85     showAt : function(xy){\r
86         Ext.Tip.superclass.show.call(this);\r
87         if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){\r
88             this.doAutoWidth();\r
89         }\r
90         if(this.constrainPosition){\r
91             xy = this.el.adjustForConstraints(xy);\r
92         }\r
93         this.setPagePosition(xy[0], xy[1]);\r
94     },\r
95 \r
96     // protected\r
97     doAutoWidth : function(){\r
98         var bw = this.body.getTextWidth();\r
99         if(this.title){\r
100             bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));\r
101         }\r
102         bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr");\r
103         this.setWidth(bw.constrain(this.minWidth, this.maxWidth));\r
104         \r
105         // IE7 repaint bug on initial show\r
106         if(Ext.isIE7 && !this.repainted){\r
107             this.el.repaint();\r
108             this.repainted = true;\r
109         }\r
110     },\r
111 \r
112     <div id="method-Ext.Tip-showBy"></div>/**\r
113      * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}\r
114      * anchor position value.  Example usage:\r
115      * <pre><code>\r
116 // Show the tip at the default position ('tl-br?')\r
117 tip.showBy('my-el');\r
118 \r
119 // Show the tip's top-left corner anchored to the element's top-right corner\r
120 tip.showBy('my-el', 'tl-tr');\r
121 </code></pre>\r
122      * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to\r
123      * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or\r
124      * {@link #defaultAlign} if specified).\r
125      */\r
126     showBy : function(el, pos){\r
127         if(!this.rendered){\r
128             this.render(Ext.getBody());\r
129         }\r
130         this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));\r
131     },\r
132 \r
133     initDraggable : function(){\r
134         this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);\r
135         this.header.addClass('x-tip-draggable');\r
136     }\r
137 });\r
138 \r
139 // private - custom Tip DD implementation\r
140 Ext.Tip.DD = function(tip, config){\r
141     Ext.apply(this, config);\r
142     this.tip = tip;\r
143     Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);\r
144     this.setHandleElId(tip.header.id);\r
145     this.scroll = false;\r
146 };\r
147 \r
148 Ext.extend(Ext.Tip.DD, Ext.dd.DD, {\r
149     moveOnly:true,\r
150     scroll:false,\r
151     headerOffsets:[100, 25],\r
152     startDrag : function(){\r
153         this.tip.el.disableShadow();\r
154     },\r
155     endDrag : function(e){\r
156         this.tip.el.enableShadow(true);\r
157     }\r
158 });</pre>    \r
159 </body>\r
160 </html>