Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / QuickTip.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.QuickTip"></div>/**\r
15  * @class Ext.QuickTip\r
16  * @extends Ext.ToolTip\r
17  * @xtype quicktip\r
18  * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global\r
19  * {@link Ext.QuickTips} instance.  See the QuickTips class header for additional usage details and examples.\r
20  * @constructor\r
21  * Create a new Tip\r
22  * @param {Object} config The configuration options\r
23  */\r
24 Ext.QuickTip = Ext.extend(Ext.ToolTip, {\r
25     <div id="cfg-Ext.QuickTip-target"></div>/**\r
26      * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to associate with this quicktip (defaults to the document).\r
27      */\r
28     <div id="cfg-Ext.QuickTip-interceptTitles"></div>/**\r
29      * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false).\r
30      */\r
31     interceptTitles : false,\r
32 \r
33     // private\r
34     tagConfig : {\r
35         namespace : "ext",\r
36         attribute : "qtip",\r
37         width : "qwidth",\r
38         target : "target",\r
39         title : "qtitle",\r
40         hide : "hide",\r
41         cls : "qclass",\r
42         align : "qalign",\r
43         anchor : "anchor"\r
44     },\r
45 \r
46     // private\r
47     initComponent : function(){\r
48         this.target = this.target || Ext.getDoc();\r
49         this.targets = this.targets || {};\r
50         Ext.QuickTip.superclass.initComponent.call(this);\r
51     },\r
52 \r
53     <div id="method-Ext.QuickTip-register"></div>/**\r
54      * Configures a new quick tip instance and assigns it to a target element.  The following config values are\r
55      * supported (for example usage, see the {@link Ext.QuickTips} class header):\r
56      * <div class="mdetail-params"><ul>\r
57      * <li>autoHide</li>\r
58      * <li>cls</li>\r
59      * <li>dismissDelay (overrides the singleton value)</li>\r
60      * <li>target (required)</li>\r
61      * <li>text (required)</li>\r
62      * <li>title</li>\r
63      * <li>width</li></ul></div>\r
64      * @param {Object} config The config object\r
65      */\r
66     register : function(config){\r
67         var cs = Ext.isArray(config) ? config : arguments;\r
68         for(var i = 0, len = cs.length; i < len; i++){\r
69             var c = cs[i];\r
70             var target = c.target;\r
71             if(target){\r
72                 if(Ext.isArray(target)){\r
73                     for(var j = 0, jlen = target.length; j < jlen; j++){\r
74                         this.targets[Ext.id(target[j])] = c;\r
75                     }\r
76                 } else{\r
77                     this.targets[Ext.id(target)] = c;\r
78                 }\r
79             }\r
80         }\r
81     },\r
82 \r
83     <div id="method-Ext.QuickTip-unregister"></div>/**\r
84      * Removes this quick tip from its element and destroys it.\r
85      * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.\r
86      */\r
87     unregister : function(el){\r
88         delete this.targets[Ext.id(el)];\r
89     },\r
90     \r
91     <div id="method-Ext.QuickTip-cancelShow"></div>/**\r
92      * Hides a visible tip or cancels an impending show for a particular element.\r
93      * @param {String/HTMLElement/Element} el The element that is the target of the tip.\r
94      */\r
95     cancelShow: function(el){\r
96         var at = this.activeTarget;\r
97         el = Ext.get(el).dom;\r
98         if(this.isVisible()){\r
99             if(at && at.el == el){\r
100                 this.hide();\r
101             }\r
102         }else if(at && at.el == el){\r
103             this.clearTimer('show');\r
104         }\r
105     },\r
106 \r
107     // private\r
108     getTipCfg: function(e) {\r
109         var t = e.getTarget(), \r
110             ttp, \r
111             cfg;\r
112         if(this.interceptTitles && t.title){\r
113             ttp = t.title;\r
114             t.qtip = ttp;\r
115             t.removeAttribute("title");\r
116             e.preventDefault();\r
117         }else{\r
118             cfg = this.tagConfig;\r
119             ttp = t.qtip || Ext.fly(t).getAttribute(cfg.attribute, cfg.namespace);\r
120         }\r
121         return ttp;\r
122     },\r
123 \r
124     // private\r
125     onTargetOver : function(e){\r
126         if(this.disabled){\r
127             return;\r
128         }\r
129         this.targetXY = e.getXY();\r
130         var t = e.getTarget();\r
131         if(!t || t.nodeType !== 1 || t == document || t == document.body){\r
132             return;\r
133         }\r
134         if(this.activeTarget && ((t == this.activeTarget.el) || Ext.fly(this.activeTarget.el).contains(t))){\r
135             this.clearTimer('hide');\r
136             this.show();\r
137             return;\r
138         }\r
139         if(t && this.targets[t.id]){\r
140             this.activeTarget = this.targets[t.id];\r
141             this.activeTarget.el = t;\r
142             this.anchor = this.activeTarget.anchor;\r
143             if(this.anchor){\r
144                 this.anchorTarget = t;\r
145             }\r
146             this.delayShow();\r
147             return;\r
148         }\r
149         var ttp, et = Ext.fly(t), cfg = this.tagConfig, ns = cfg.namespace;\r
150         if(ttp = this.getTipCfg(e)){\r
151             var autoHide = et.getAttribute(cfg.hide, ns);\r
152             this.activeTarget = {\r
153                 el: t,\r
154                 text: ttp,\r
155                 width: et.getAttribute(cfg.width, ns),\r
156                 autoHide: autoHide != "user" && autoHide !== 'false',\r
157                 title: et.getAttribute(cfg.title, ns),\r
158                 cls: et.getAttribute(cfg.cls, ns),\r
159                 align: et.getAttribute(cfg.align, ns)\r
160                 \r
161             };\r
162             this.anchor = et.getAttribute(cfg.anchor, ns);\r
163             if(this.anchor){\r
164                 this.anchorTarget = t;\r
165             }\r
166             this.delayShow();\r
167         }\r
168     },\r
169 \r
170     // private\r
171     onTargetOut : function(e){\r
172 \r
173         // If moving within the current target, and it does not have a new tip, ignore the mouseout\r
174         if (this.activeTarget && e.within(this.activeTarget.el) && !this.getTipCfg(e)) {\r
175             return;\r
176         }\r
177 \r
178         this.clearTimer('show');\r
179         if(this.autoHide !== false){\r
180             this.delayHide();\r
181         }\r
182     },\r
183 \r
184     // inherit docs\r
185     showAt : function(xy){\r
186         var t = this.activeTarget;\r
187         if(t){\r
188             if(!this.rendered){\r
189                 this.render(Ext.getBody());\r
190                 this.activeTarget = t;\r
191             }\r
192             if(t.width){\r
193                 this.setWidth(t.width);\r
194                 this.body.setWidth(this.adjustBodyWidth(t.width - this.getFrameWidth()));\r
195                 this.measureWidth = false;\r
196             } else{\r
197                 this.measureWidth = true;\r
198             }\r
199             this.setTitle(t.title || '');\r
200             this.body.update(t.text);\r
201             this.autoHide = t.autoHide;\r
202             this.dismissDelay = t.dismissDelay || this.dismissDelay;\r
203             if(this.lastCls){\r
204                 this.el.removeClass(this.lastCls);\r
205                 delete this.lastCls;\r
206             }\r
207             if(t.cls){\r
208                 this.el.addClass(t.cls);\r
209                 this.lastCls = t.cls;\r
210             }\r
211             if(this.anchor){\r
212                 this.constrainPosition = false;\r
213             }else if(t.align){ // TODO: this doesn't seem to work consistently\r
214                 xy = this.el.getAlignToXY(t.el, t.align);\r
215                 this.constrainPosition = false;\r
216             }else{\r
217                 this.constrainPosition = true;\r
218             }\r
219         }\r
220         Ext.QuickTip.superclass.showAt.call(this, xy);\r
221     },\r
222 \r
223     // inherit docs\r
224     hide: function(){\r
225         delete this.activeTarget;\r
226         Ext.QuickTip.superclass.hide.call(this);\r
227     }\r
228 });\r
229 Ext.reg('quicktip', Ext.QuickTip);</pre>
230 </body>
231 </html>