1 | /* |
---|
2 | * Ext JS Library 2.2.1 |
---|
3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
4 | * licensing@extjs.com |
---|
5 | * |
---|
6 | * http://extjs.com/license |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * @class Ext.QuickTip |
---|
11 | * @extends Ext.ToolTip |
---|
12 | * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global |
---|
13 | * {@link Ext.QuickTips} instance. See the QuickTips class header for additional usage details and examples. |
---|
14 | * @constructor |
---|
15 | * Create a new Tip |
---|
16 | * @param {Object} config The configuration options |
---|
17 | */ |
---|
18 | Ext.QuickTip = Ext.extend(Ext.ToolTip, { |
---|
19 | /** |
---|
20 | * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to associate with this quicktip (defaults to the document). |
---|
21 | */ |
---|
22 | /** |
---|
23 | * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false). |
---|
24 | */ |
---|
25 | interceptTitles : false, |
---|
26 | |
---|
27 | // private |
---|
28 | tagConfig : { |
---|
29 | namespace : "ext", |
---|
30 | attribute : "qtip", |
---|
31 | width : "qwidth", |
---|
32 | target : "target", |
---|
33 | title : "qtitle", |
---|
34 | hide : "hide", |
---|
35 | cls : "qclass", |
---|
36 | align : "qalign" |
---|
37 | }, |
---|
38 | |
---|
39 | // private |
---|
40 | initComponent : function(){ |
---|
41 | this.target = this.target || Ext.getDoc(); |
---|
42 | this.targets = this.targets || {}; |
---|
43 | Ext.QuickTip.superclass.initComponent.call(this); |
---|
44 | }, |
---|
45 | |
---|
46 | /** |
---|
47 | * Configures a new quick tip instance and assigns it to a target element. The following config values are |
---|
48 | * supported (for example usage, see the {@link Ext.QuickTips} class header): |
---|
49 | * <div class="mdetail-params"><ul> |
---|
50 | * <li>autoHide</li> |
---|
51 | * <li>cls</li> |
---|
52 | * <li>dismissDelay (overrides the singleton value)</li> |
---|
53 | * <li>target (required)</li> |
---|
54 | * <li>text (required)</li> |
---|
55 | * <li>title</li> |
---|
56 | * <li>width</li></ul></div> |
---|
57 | * @param {Object} config The config object |
---|
58 | */ |
---|
59 | register : function(config){ |
---|
60 | var cs = Ext.isArray(config) ? config : arguments; |
---|
61 | for(var i = 0, len = cs.length; i < len; i++){ |
---|
62 | var c = cs[i]; |
---|
63 | var target = c.target; |
---|
64 | if(target){ |
---|
65 | if(Ext.isArray(target)){ |
---|
66 | for(var j = 0, jlen = target.length; j < jlen; j++){ |
---|
67 | this.targets[Ext.id(target[j])] = c; |
---|
68 | } |
---|
69 | } else{ |
---|
70 | this.targets[Ext.id(target)] = c; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | }, |
---|
75 | |
---|
76 | /** |
---|
77 | * Removes this quick tip from its element and destroys it. |
---|
78 | * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed. |
---|
79 | */ |
---|
80 | unregister : function(el){ |
---|
81 | delete this.targets[Ext.id(el)]; |
---|
82 | }, |
---|
83 | |
---|
84 | // private |
---|
85 | onTargetOver : function(e){ |
---|
86 | if(this.disabled){ |
---|
87 | return; |
---|
88 | } |
---|
89 | this.targetXY = e.getXY(); |
---|
90 | var t = e.getTarget(); |
---|
91 | if(!t || t.nodeType !== 1 || t == document || t == document.body){ |
---|
92 | return; |
---|
93 | } |
---|
94 | if(this.activeTarget && t == this.activeTarget.el){ |
---|
95 | this.clearTimer('hide'); |
---|
96 | this.show(); |
---|
97 | return; |
---|
98 | } |
---|
99 | if(t && this.targets[t.id]){ |
---|
100 | this.activeTarget = this.targets[t.id]; |
---|
101 | this.activeTarget.el = t; |
---|
102 | this.delayShow(); |
---|
103 | return; |
---|
104 | } |
---|
105 | var ttp, et = Ext.fly(t), cfg = this.tagConfig; |
---|
106 | var ns = cfg.namespace; |
---|
107 | if(this.interceptTitles && t.title){ |
---|
108 | ttp = t.title; |
---|
109 | t.qtip = ttp; |
---|
110 | t.removeAttribute("title"); |
---|
111 | e.preventDefault(); |
---|
112 | } else{ |
---|
113 | ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute); |
---|
114 | } |
---|
115 | if(ttp){ |
---|
116 | var autoHide = et.getAttributeNS(ns, cfg.hide); |
---|
117 | this.activeTarget = { |
---|
118 | el: t, |
---|
119 | text: ttp, |
---|
120 | width: et.getAttributeNS(ns, cfg.width), |
---|
121 | autoHide: autoHide != "user" && autoHide !== 'false', |
---|
122 | title: et.getAttributeNS(ns, cfg.title), |
---|
123 | cls: et.getAttributeNS(ns, cfg.cls), |
---|
124 | align: et.getAttributeNS(ns, cfg.align) |
---|
125 | }; |
---|
126 | this.delayShow(); |
---|
127 | } |
---|
128 | }, |
---|
129 | |
---|
130 | // private |
---|
131 | onTargetOut : function(e){ |
---|
132 | this.clearTimer('show'); |
---|
133 | if(this.autoHide !== false){ |
---|
134 | this.delayHide(); |
---|
135 | } |
---|
136 | }, |
---|
137 | |
---|
138 | // inherit docs |
---|
139 | showAt : function(xy){ |
---|
140 | var t = this.activeTarget; |
---|
141 | if(t){ |
---|
142 | if(!this.rendered){ |
---|
143 | this.render(Ext.getBody()); |
---|
144 | this.activeTarget = t; |
---|
145 | } |
---|
146 | if(t.width){ |
---|
147 | this.setWidth(t.width); |
---|
148 | this.body.setWidth(this.adjustBodyWidth(t.width - this.getFrameWidth())); |
---|
149 | this.measureWidth = false; |
---|
150 | } else{ |
---|
151 | this.measureWidth = true; |
---|
152 | } |
---|
153 | this.setTitle(t.title || ''); |
---|
154 | this.body.update(t.text); |
---|
155 | this.autoHide = t.autoHide; |
---|
156 | this.dismissDelay = t.dismissDelay || this.dismissDelay; |
---|
157 | if(this.lastCls){ |
---|
158 | this.el.removeClass(this.lastCls); |
---|
159 | delete this.lastCls; |
---|
160 | } |
---|
161 | if(t.cls){ |
---|
162 | this.el.addClass(t.cls); |
---|
163 | this.lastCls = t.cls; |
---|
164 | } |
---|
165 | if(t.align){ // TODO: this doesn't seem to work consistently |
---|
166 | xy = this.el.getAlignToXY(t.el, t.align); |
---|
167 | this.constrainPosition = false; |
---|
168 | } else{ |
---|
169 | this.constrainPosition = true; |
---|
170 | } |
---|
171 | } |
---|
172 | Ext.QuickTip.superclass.showAt.call(this, xy); |
---|
173 | }, |
---|
174 | |
---|
175 | // inherit docs |
---|
176 | hide: function(){ |
---|
177 | delete this.activeTarget; |
---|
178 | Ext.QuickTip.superclass.hide.call(this); |
---|
179 | } |
---|
180 | }); |
---|