Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / QuickTip.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-tip-QuickTip'>/**
19 </span> * @class Ext.tip.QuickTip
20  * @extends Ext.tip.ToolTip
21  * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global
22  * {@link Ext.tip.QuickTipManager} instance.  See the QuickTipManager class header for additional usage details and examples.
23  * @xtype quicktip
24  */
25 Ext.define('Ext.tip.QuickTip', {
26     extend: 'Ext.tip.ToolTip',
27     alternateClassName: 'Ext.QuickTip',
28 <span id='Ext-tip-QuickTip-cfg-target'>    /**
29 </span>     * @cfg {Mixed} target The target HTMLElement, Ext.core.Element or id to associate with this Quicktip (defaults to the document).
30      */
31 <span id='Ext-tip-QuickTip-cfg-interceptTitles'>    /**
32 </span>     * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false).
33      */
34     interceptTitles : false,
35
36     // Force creation of header Component
37     title: '&amp;#160;',
38
39     // private
40     tagConfig : {
41         namespace : &quot;data-&quot;,
42         attribute : &quot;qtip&quot;,
43         width : &quot;qwidth&quot;,
44         target : &quot;target&quot;,
45         title : &quot;qtitle&quot;,
46         hide : &quot;hide&quot;,
47         cls : &quot;qclass&quot;,
48         align : &quot;qalign&quot;,
49         anchor : &quot;anchor&quot;
50     },
51
52     // private
53     initComponent : function(){
54         var me = this;
55         
56         me.target = me.target || Ext.getDoc();
57         me.targets = me.targets || {};
58         me.callParent();
59     },
60
61 <span id='Ext-tip-QuickTip-method-register'>    /**
62 </span>     * Configures a new quick tip instance and assigns it to a target element.  The following config values are
63      * supported (for example usage, see the {@link Ext.tip.QuickTipManager} class header):
64      * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
65      * &lt;li&gt;autoHide&lt;/li&gt;
66      * &lt;li&gt;cls&lt;/li&gt;
67      * &lt;li&gt;dismissDelay (overrides the singleton value)&lt;/li&gt;
68      * &lt;li&gt;target (required)&lt;/li&gt;
69      * &lt;li&gt;text (required)&lt;/li&gt;
70      * &lt;li&gt;title&lt;/li&gt;
71      * &lt;li&gt;width&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;
72      * @param {Object} config The config object
73      */
74     register : function(config){
75         var configs = Ext.isArray(config) ? config : arguments,
76             i = 0,
77             len = configs.length,
78             target, j, targetLen;
79             
80         for (; i &lt; len; i++) {
81             config = configs[i];
82             target = config.target;
83             if (target) {
84                 if (Ext.isArray(target)) {
85                     for (j = 0, targetLen = target.length; j &lt; targetLen; j++) {
86                         this.targets[Ext.id(target[j])] = config;
87                     }
88                 } else{
89                     this.targets[Ext.id(target)] = config;
90                 }
91             }
92         }
93     },
94
95 <span id='Ext-tip-QuickTip-method-unregister'>    /**
96 </span>     * Removes this quick tip from its element and destroys it.
97      * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
98      */
99     unregister : function(el){
100         delete this.targets[Ext.id(el)];
101     },
102     
103 <span id='Ext-tip-QuickTip-method-cancelShow'>    /**
104 </span>     * Hides a visible tip or cancels an impending show for a particular element.
105      * @param {String/HTMLElement/Element} el The element that is the target of the tip.
106      */
107     cancelShow: function(el){
108         var me = this,
109             activeTarget = me.activeTarget;
110             
111         el = Ext.get(el).dom;
112         if (me.isVisible()) {
113             if (activeTarget &amp;&amp; activeTarget.el == el) {
114                 me.hide();
115             }
116         } else if (activeTarget &amp;&amp; activeTarget.el == el) {
117             me.clearTimer('show');
118         }
119     },
120     
121     getTipCfg: function(e) {
122         var t = e.getTarget(),
123             ttp, 
124             cfg;
125         
126         if(this.interceptTitles &amp;&amp; t.title &amp;&amp; Ext.isString(t.title)){
127             ttp = t.title;
128             t.qtip = ttp;
129             t.removeAttribute(&quot;title&quot;);
130             e.preventDefault();
131         } 
132         else {            
133             cfg = this.tagConfig;
134             t = e.getTarget('[' + cfg.namespace + cfg.attribute + ']');
135             if (t) {
136                 ttp = t.getAttribute(cfg.namespace + cfg.attribute);
137             }
138         }
139         return ttp;
140     },
141
142     // private
143     onTargetOver : function(e){
144         var me = this,
145             target = e.getTarget(),
146             elTarget,
147             cfg,
148             ns,
149             ttp,
150             autoHide;
151         
152         if (me.disabled) {
153             return;
154         }
155
156         // TODO - this causes &quot;e&quot; to be recycled in IE6/7 (EXTJSIV-1608) so ToolTip#setTarget
157         // was changed to include freezeEvent. The issue seems to be a nested 'resize' event
158         // that smashed Ext.EventObject.
159         me.targetXY = e.getXY();
160
161         if(!target || target.nodeType !== 1 || target == document || target == document.body){
162             return;
163         }
164         
165         if (me.activeTarget &amp;&amp; ((target == me.activeTarget.el) || Ext.fly(me.activeTarget.el).contains(target))) {
166             me.clearTimer('hide');
167             me.show();
168             return;
169         }
170         
171         if (target) {
172             Ext.Object.each(me.targets, function(key, value) {
173                 var targetEl = Ext.fly(value.target);
174                 if (targetEl &amp;&amp; (targetEl.dom === target || targetEl.contains(target))) {
175                     elTarget = targetEl.dom;
176                     return false;
177                 }
178             });
179             if (elTarget) {
180                 me.activeTarget = me.targets[elTarget.id];
181                 me.activeTarget.el = target;
182                 me.anchor = me.activeTarget.anchor;
183                 if (me.anchor) {
184                     me.anchorTarget = target;
185                 }
186                 me.delayShow();
187                 return;
188             }
189         }
190
191         elTarget = Ext.get(target);
192         cfg = me.tagConfig;
193         ns = cfg.namespace; 
194         ttp = me.getTipCfg(e);
195         
196         if (ttp) {
197             autoHide = elTarget.getAttribute(ns + cfg.hide);
198                  
199             me.activeTarget = {
200                 el: target,
201                 text: ttp,
202                 width: +elTarget.getAttribute(ns + cfg.width) || null,
203                 autoHide: autoHide != &quot;user&quot; &amp;&amp; autoHide !== 'false',
204                 title: elTarget.getAttribute(ns + cfg.title),
205                 cls: elTarget.getAttribute(ns + cfg.cls),
206                 align: elTarget.getAttribute(ns + cfg.align)
207                 
208             };
209             me.anchor = elTarget.getAttribute(ns + cfg.anchor);
210             if (me.anchor) {
211                 me.anchorTarget = target;
212             }
213             me.delayShow();
214         }
215     },
216
217     // private
218     onTargetOut : function(e){
219         var me = this;
220         
221         // If moving within the current target, and it does not have a new tip, ignore the mouseout
222         if (me.activeTarget &amp;&amp; e.within(me.activeTarget.el) &amp;&amp; !me.getTipCfg(e)) {
223             return;
224         }
225
226         me.clearTimer('show');
227         if (me.autoHide !== false) {
228             me.delayHide();
229         }
230     },
231
232     // inherit docs
233     showAt : function(xy){
234         var me = this,
235             target = me.activeTarget;
236         
237         if (target) {
238             if (!me.rendered) {
239                 me.render(Ext.getBody());
240                 me.activeTarget = target;
241             }
242             if (target.title) {
243                 me.setTitle(target.title || '');
244                 me.header.show();
245             } else {
246                 me.header.hide();
247             }
248             me.body.update(target.text);
249             me.autoHide = target.autoHide;
250             me.dismissDelay = target.dismissDelay || me.dismissDelay;
251             if (me.lastCls) {
252                 me.el.removeCls(me.lastCls);
253                 delete me.lastCls;
254             }
255             if (target.cls) {
256                 me.el.addCls(target.cls);
257                 me.lastCls = target.cls;
258             }
259
260             me.setWidth(target.width);
261             
262             if (me.anchor) {
263                 me.constrainPosition = false;
264             } else if (target.align) { // TODO: this doesn't seem to work consistently
265                 xy = me.el.getAlignToXY(target.el, target.align);
266                 me.constrainPosition = false;
267             }else{
268                 me.constrainPosition = true;
269             }
270         }
271         me.callParent([xy]);
272     },
273
274     // inherit docs
275     hide: function(){
276         delete this.activeTarget;
277         this.callParent();
278     }
279 });
280 </pre>
281 </body>
282 </html>