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