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