4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
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 documentation for additional usage details and examples.
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 {String/HTMLElement/Ext.Element} target The target HTMLElement, Ext.Element or id to associate with this Quicktip (defaults to the document).
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.
34 interceptTitles : false,
36 // Force creation of header Component
41 namespace : "data-",
42 attribute : "qtip",
43 width : "qwidth",
44 target : "target",
45 title : "qtitle",
46 hide : "hide",
47 cls : "qclass",
48 align : "qalign",
49 anchor : "anchor"
53 initComponent : function(){
56 me.target = me.target || Ext.getDoc();
57 me.targets = me.targets || {};
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 * <div class="mdetail-params"><ul>
65 * <li>autoHide</li>
66 * <li>cls</li>
67 * <li>dismissDelay (overrides the singleton value)</li>
68 * <li>target (required)</li>
69 * <li>text (required)</li>
70 * <li>title</li>
71 * <li>width</li></ul></div>
72 * @param {Object} config The config object
74 register : function(config){
75 var configs = Ext.isArray(config) ? config : arguments,
80 for (; i < len; i++) {
82 target = config.target;
84 if (Ext.isArray(target)) {
85 for (j = 0, targetLen = target.length; j < targetLen; j++) {
86 this.targets[Ext.id(target[j])] = config;
89 this.targets[Ext.id(target)] = config;
95 <span id='Ext-tip-QuickTip-method-unregister'> /**
96 </span> * Removes this quick tip from its element and destroys it.
97 * @param {String/HTMLElement/Ext.Element} el The element from which the quick tip is to be removed or ID of the element.
99 unregister : function(el){
100 delete this.targets[Ext.id(el)];
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/Ext.Element} el The element that is the target of the tip or ID of the element.
107 cancelShow: function(el){
109 activeTarget = me.activeTarget;
111 el = Ext.get(el).dom;
112 if (me.isVisible()) {
113 if (activeTarget && activeTarget.el == el) {
116 } else if (activeTarget && activeTarget.el == el) {
117 me.clearTimer('show');
121 <span id='Ext-tip-QuickTip-method-getTipCfg'> /**
123 * Reads the tip text from the closest node to the event target which contains the attribute we
124 * are configured to look for. Returns an object containing the text from the attribute, and the target element from
125 * which the text was read.
127 getTipCfg: function(e) {
128 var t = e.getTarget(),
132 if (this.interceptTitles && titleText && Ext.isString(titleText)) {
134 t.removeAttribute("title");
141 cfg = this.tagConfig;
142 t = e.getTarget('[' + cfg.namespace + cfg.attribute + ']');
146 text: t.getAttribute(cfg.namespace + cfg.attribute)
153 onTargetOver : function(e){
155 target = e.getTarget(),
166 // TODO - this causes "e" to be recycled in IE6/7 (EXTJSIV-1608) so ToolTip#setTarget
167 // was changed to include freezeEvent. The issue seems to be a nested 'resize' event
168 // that smashed Ext.EventObject.
169 me.targetXY = e.getXY();
171 if(!target || target.nodeType !== 1 || target == document || target == document.body){
175 if (me.activeTarget && ((target == me.activeTarget.el) || Ext.fly(me.activeTarget.el).contains(target))) {
176 me.clearTimer('hide');
182 Ext.Object.each(me.targets, function(key, value) {
183 var targetEl = Ext.fly(value.target);
184 if (targetEl && (targetEl.dom === target || targetEl.contains(target))) {
185 elTarget = targetEl.dom;
190 me.activeTarget = me.targets[elTarget.id];
191 me.activeTarget.el = target;
192 me.anchor = me.activeTarget.anchor;
194 me.anchorTarget = target;
201 elTarget = Ext.get(target);
204 tipConfig = me.getTipCfg(e);
208 // getTipCfg may look up the parentNode axis for a tip text attribute and will return the new target node.
209 // Change our target element to match that from which the tip text attribute was read.
210 if (tipConfig.target) {
211 target = tipConfig.target;
212 elTarget = Ext.get(target);
214 autoHide = elTarget.getAttribute(ns + cfg.hide);
218 text: tipConfig.text,
219 width: +elTarget.getAttribute(ns + cfg.width) || null,
220 autoHide: autoHide != "user" && autoHide !== 'false',
221 title: elTarget.getAttribute(ns + cfg.title),
222 cls: elTarget.getAttribute(ns + cfg.cls),
223 align: elTarget.getAttribute(ns + cfg.align)
226 me.anchor = elTarget.getAttribute(ns + cfg.anchor);
228 me.anchorTarget = target;
235 onTargetOut : function(e){
238 // If moving within the current target, and it does not have a new tip, ignore the mouseout
239 if (me.activeTarget && e.within(me.activeTarget.el) && !me.getTipCfg(e)) {
243 me.clearTimer('show');
244 if (me.autoHide !== false) {
250 showAt : function(xy){
252 target = me.activeTarget;
256 me.render(Ext.getBody());
257 me.activeTarget = target;
260 me.setTitle(target.title || '');
265 me.body.update(target.text);
266 me.autoHide = target.autoHide;
267 me.dismissDelay = target.dismissDelay || me.dismissDelay;
269 me.el.removeCls(me.lastCls);
273 me.el.addCls(target.cls);
274 me.lastCls = target.cls;
277 me.setWidth(target.width);
280 me.constrainPosition = false;
281 } else if (target.align) { // TODO: this doesn't seem to work consistently
282 xy = me.el.getAlignToXY(target.el, target.align);
283 me.constrainPosition = false;
285 me.constrainPosition = true;
293 delete this.activeTarget;