3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.tip.QuickTip
17 * @extends Ext.tip.ToolTip
18 * A specialized tooltip class for tooltips that can be specified in markup and automatically managed by the global
19 * {@link Ext.tip.QuickTipManager} instance. See the QuickTipManager class header for additional usage details and examples.
22 Ext.define('Ext.tip.QuickTip', {
23 extend: 'Ext.tip.ToolTip',
24 alternateClassName: 'Ext.QuickTip',
26 * @cfg {Mixed} target The target HTMLElement, Ext.core.Element or id to associate with this Quicktip (defaults to the document).
29 * @cfg {Boolean} interceptTitles True to automatically use the element's DOM title value if available (defaults to false).
31 interceptTitles : false,
33 // Force creation of header Component
50 initComponent : function(){
53 me.target = me.target || Ext.getDoc();
54 me.targets = me.targets || {};
59 * Configures a new quick tip instance and assigns it to a target element. The following config values are
60 * supported (for example usage, see the {@link Ext.tip.QuickTipManager} class header):
61 * <div class="mdetail-params"><ul>
64 * <li>dismissDelay (overrides the singleton value)</li>
65 * <li>target (required)</li>
66 * <li>text (required)</li>
68 * <li>width</li></ul></div>
69 * @param {Object} config The config object
71 register : function(config){
72 var configs = Ext.isArray(config) ? config : arguments,
77 for (; i < len; i++) {
79 target = config.target;
81 if (Ext.isArray(target)) {
82 for (j = 0, targetLen = target.length; j < targetLen; j++) {
83 this.targets[Ext.id(target[j])] = config;
86 this.targets[Ext.id(target)] = config;
93 * Removes this quick tip from its element and destroys it.
94 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
96 unregister : function(el){
97 delete this.targets[Ext.id(el)];
101 * Hides a visible tip or cancels an impending show for a particular element.
102 * @param {String/HTMLElement/Element} el The element that is the target of the tip.
104 cancelShow: function(el){
106 activeTarget = me.activeTarget;
108 el = Ext.get(el).dom;
109 if (me.isVisible()) {
110 if (activeTarget && activeTarget.el == el) {
113 } else if (activeTarget && activeTarget.el == el) {
114 me.clearTimer('show');
118 getTipCfg: function(e) {
119 var t = e.getTarget(),
123 if(this.interceptTitles && t.title && Ext.isString(t.title)){
126 t.removeAttribute("title");
130 cfg = this.tagConfig;
131 t = e.getTarget('[' + cfg.namespace + cfg.attribute + ']');
133 ttp = t.getAttribute(cfg.namespace + cfg.attribute);
140 onTargetOver : function(e){
142 target = e.getTarget(),
153 // TODO - this causes "e" to be recycled in IE6/7 (EXTJSIV-1608) so ToolTip#setTarget
154 // was changed to include freezeEvent. The issue seems to be a nested 'resize' event
155 // that smashed Ext.EventObject.
156 me.targetXY = e.getXY();
158 if(!target || target.nodeType !== 1 || target == document || target == document.body){
162 if (me.activeTarget && ((target == me.activeTarget.el) || Ext.fly(me.activeTarget.el).contains(target))) {
163 me.clearTimer('hide');
169 Ext.Object.each(me.targets, function(key, value) {
170 var targetEl = Ext.fly(value.target);
171 if (targetEl && (targetEl.dom === target || targetEl.contains(target))) {
172 elTarget = targetEl.dom;
177 me.activeTarget = me.targets[elTarget.id];
178 me.activeTarget.el = target;
179 me.anchor = me.activeTarget.anchor;
181 me.anchorTarget = target;
188 elTarget = Ext.get(target);
191 ttp = me.getTipCfg(e);
194 autoHide = elTarget.getAttribute(ns + cfg.hide);
199 width: +elTarget.getAttribute(ns + cfg.width) || null,
200 autoHide: autoHide != "user" && autoHide !== 'false',
201 title: elTarget.getAttribute(ns + cfg.title),
202 cls: elTarget.getAttribute(ns + cfg.cls),
203 align: elTarget.getAttribute(ns + cfg.align)
206 me.anchor = elTarget.getAttribute(ns + cfg.anchor);
208 me.anchorTarget = target;
215 onTargetOut : function(e){
218 // If moving within the current target, and it does not have a new tip, ignore the mouseout
219 if (me.activeTarget && e.within(me.activeTarget.el) && !me.getTipCfg(e)) {
223 me.clearTimer('show');
224 if (me.autoHide !== false) {
230 showAt : function(xy){
232 target = me.activeTarget;
236 me.render(Ext.getBody());
237 me.activeTarget = target;
240 me.setTitle(target.title || '');
245 me.body.update(target.text);
246 me.autoHide = target.autoHide;
247 me.dismissDelay = target.dismissDelay || me.dismissDelay;
249 me.el.removeCls(me.lastCls);
253 me.el.addCls(target.cls);
254 me.lastCls = target.cls;
257 me.setWidth(target.width);
260 me.constrainPosition = false;
261 } else if (target.align) { // TODO: this doesn't seem to work consistently
262 xy = me.el.getAlignToXY(target.el, target.align);
263 me.constrainPosition = false;
265 me.constrainPosition = true;
273 delete this.activeTarget;