source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/tips/QuickTip.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

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