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