3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.ToolTip"></div>/**
\r
10 * @class Ext.ToolTip
\r
12 * A standard tooltip implementation for providing additional information when hovering over a target element.
\r
15 * Create a new Tooltip
\r
16 * @param {Object} config The configuration options
\r
18 Ext.ToolTip = Ext.extend(Ext.Tip, {
\r
19 <div id="prop-Ext.ToolTip-triggerElement"></div>/**
\r
20 * When a Tooltip is configured with the <code>{@link #delegate}</code>
\r
21 * option to cause selected child elements of the <code>{@link #target}</code>
\r
22 * Element to each trigger a seperate show event, this property is set to
\r
23 * the DOM element which triggered the show.
\r
25 * @property triggerElement
\r
27 <div id="cfg-Ext.ToolTip-target"></div>/**
\r
28 * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to monitor
\r
29 * for mouseover events to trigger showing this ToolTip.
\r
31 <div id="cfg-Ext.ToolTip-autoHide"></div>/**
\r
32 * @cfg {Boolean} autoHide True to automatically hide the tooltip after the
\r
33 * mouse exits the target element or after the <code>{@link #dismissDelay}</code>
\r
34 * has expired if set (defaults to true). If <code>{@link closable} = true</code>
\r
35 * a close tool button will be rendered into the tooltip header.
\r
37 <div id="cfg-Ext.ToolTip-showDelay"></div>/**
\r
38 * @cfg {Number} showDelay Delay in milliseconds before the tooltip displays
\r
39 * after the mouse enters the target element (defaults to 500)
\r
42 <div id="cfg-Ext.ToolTip-hideDelay"></div>/**
\r
43 * @cfg {Number} hideDelay Delay in milliseconds after the mouse exits the
\r
44 * target element but before the tooltip actually hides (defaults to 200).
\r
45 * Set to 0 for the tooltip to hide immediately.
\r
48 <div id="cfg-Ext.ToolTip-dismissDelay"></div>/**
\r
49 * @cfg {Number} dismissDelay Delay in milliseconds before the tooltip
\r
50 * automatically hides (defaults to 5000). To disable automatic hiding, set
\r
53 dismissDelay : 5000,
\r
54 <div id="cfg-Ext.ToolTip-mouseOffset"></div>/**
\r
55 * @cfg {Array} mouseOffset An XY offset from the mouse position where the
\r
56 * tooltip should be shown (defaults to [15,18]).
\r
58 <div id="cfg-Ext.ToolTip-trackMouse"></div>/**
\r
59 * @cfg {Boolean} trackMouse True to have the tooltip follow the mouse as it
\r
60 * moves over the target element (defaults to false).
\r
63 <div id="cfg-Ext.ToolTip-anchorToTarget"></div>/**
\r
64 * @cfg {Boolean} anchorToTarget True to anchor the tooltip to the target
\r
65 * element, false to anchor it relative to the mouse coordinates (defaults
\r
66 * to true). When <code>anchorToTarget</code> is true, use
\r
67 * <code>{@link #defaultAlign}</code> to control tooltip alignment to the
\r
68 * target element. When <code>anchorToTarget</code> is false, use
\r
69 * <code>{@link #anchorPosition}</code> instead to control alignment.
\r
71 anchorToTarget : true,
\r
72 <div id="cfg-Ext.ToolTip-anchorOffset"></div>/**
\r
73 * @cfg {Number} anchorOffset A numeric pixel value used to offset the
\r
74 * default position of the anchor arrow (defaults to 0). When the anchor
\r
75 * position is on the top or bottom of the tooltip, <code>anchorOffset</code>
\r
76 * will be used as a horizontal offset. Likewise, when the anchor position
\r
77 * is on the left or right side, <code>anchorOffset</code> will be used as
\r
78 * a vertical offset.
\r
81 <div id="cfg-Ext.ToolTip-delegate"></div>/**
\r
82 * @cfg {String} delegate <p>Optional. A {@link Ext.DomQuery DomQuery}
\r
83 * selector which allows selection of individual elements within the
\r
84 * <code>{@link #target}</code> element to trigger showing and hiding the
\r
85 * ToolTip as the mouse moves within the target.</p>
\r
86 * <p>When specified, the child element of the target which caused a show
\r
87 * event is placed into the <code>{@link #triggerElement}</code> property
\r
88 * before the ToolTip is shown.</p>
\r
89 * <p>This may be useful when a Component has regular, repeating elements
\r
90 * in it, each of which need a Tooltip which contains information specific
\r
91 * to that element. For example:</p><pre><code>
\r
92 var myGrid = new Ext.grid.gridPanel(gridConfig);
\r
93 myGrid.on('render', function(grid) {
\r
94 var store = grid.getStore(); // Capture the Store.
\r
95 var view = grid.getView(); // Capture the GridView.
\r
96 myGrid.tip = new Ext.ToolTip({
\r
97 target: view.mainBody, // The overall target element.
\r
98 delegate: '.x-grid3-row', // Each grid row causes its own seperate show and hide.
\r
99 trackMouse: true, // Moving within the row should not hide the tip.
\r
100 renderTo: document.body, // Render immediately so that tip.body can be
\r
101 // referenced prior to the first show.
\r
102 listeners: { // Change content dynamically depending on which element
\r
103 // triggered the show.
\r
104 beforeshow: function updateTipBody(tip) {
\r
105 var rowIndex = view.findRowIndex(tip.triggerElement);
\r
106 tip.body.dom.innerHTML = 'Over Record ID ' + store.getAt(rowIndex).id;
\r
117 constrainPosition : false,
\r
120 initComponent : function(){
\r
121 Ext.ToolTip.superclass.initComponent.call(this);
\r
122 this.lastActive = new Date();
\r
123 this.initTarget(this.target);
\r
124 this.origAnchor = this.anchor;
\r
128 onRender : function(ct, position){
\r
129 Ext.ToolTip.superclass.onRender.call(this, ct, position);
\r
130 this.anchorCls = 'x-tip-anchor-' + this.getAnchorPosition();
\r
131 this.anchorEl = this.el.createChild({
\r
132 cls: 'x-tip-anchor ' + this.anchorCls
\r
137 afterRender : function(){
\r
138 Ext.ToolTip.superclass.afterRender.call(this);
\r
139 this.anchorEl.setStyle('z-index', this.el.getZIndex() + 1);
\r
142 <div id="method-Ext.ToolTip-initTarget"></div>/**
\r
143 * Binds this ToolTip to the specified element. The tooltip will be displayed when the mouse moves over the element.
\r
144 * @param {Mixed} t The Element, HtmlElement, or ID of an element to bind to
\r
146 initTarget : function(target){
\r
148 if((t = Ext.get(target))){
\r
150 var tg = Ext.get(this.target);
\r
151 this.mun(tg, 'mouseover', this.onTargetOver, this);
\r
152 this.mun(tg, 'mouseout', this.onTargetOut, this);
\r
153 this.mun(tg, 'mousemove', this.onMouseMove, this);
\r
156 mouseover: this.onTargetOver,
\r
157 mouseout: this.onTargetOut,
\r
158 mousemove: this.onMouseMove,
\r
164 this.anchorTarget = this.target;
\r
169 onMouseMove : function(e){
\r
170 var t = this.delegate ? e.getTarget(this.delegate) : this.triggerElement = true;
\r
172 this.targetXY = e.getXY();
\r
173 if (t === this.triggerElement) {
\r
174 if(!this.hidden && this.trackMouse){
\r
175 this.setPagePosition(this.getTargetXY());
\r
179 this.lastActive = new Date(0);
\r
180 this.onTargetOver(e);
\r
182 } else if (!this.closable && this.isVisible()) {
\r
188 getTargetXY : function(){
\r
190 this.anchorTarget = this.triggerElement;
\r
193 this.targetCounter++;
\r
194 var offsets = this.getOffsets(),
\r
195 xy = (this.anchorToTarget && !this.trackMouse) ? this.el.getAlignToXY(this.anchorTarget, this.getAnchorAlign()) : this.targetXY,
\r
196 dw = Ext.lib.Dom.getViewWidth() - 5,
\r
197 dh = Ext.lib.Dom.getViewHeight() - 5,
\r
198 de = document.documentElement,
\r
199 bd = document.body,
\r
200 scrollX = (de.scrollLeft || bd.scrollLeft || 0) + 5,
\r
201 scrollY = (de.scrollTop || bd.scrollTop || 0) + 5,
\r
202 axy = [xy[0] + offsets[0], xy[1] + offsets[1]]
\r
203 sz = this.getSize();
\r
205 this.anchorEl.removeClass(this.anchorCls);
\r
207 if(this.targetCounter < 2){
\r
208 if(axy[0] < scrollX){
\r
209 if(this.anchorToTarget){
\r
210 this.defaultAlign = 'l-r';
\r
211 if(this.mouseOffset){this.mouseOffset[0] *= -1;}
\r
213 this.anchor = 'left';
\r
214 return this.getTargetXY();
\r
216 if(axy[0]+sz.width > dw){
\r
217 if(this.anchorToTarget){
\r
218 this.defaultAlign = 'r-l';
\r
219 if(this.mouseOffset){this.mouseOffset[0] *= -1;}
\r
221 this.anchor = 'right';
\r
222 return this.getTargetXY();
\r
224 if(axy[1] < scrollY){
\r
225 if(this.anchorToTarget){
\r
226 this.defaultAlign = 't-b';
\r
227 if(this.mouseOffset){this.mouseOffset[1] *= -1;}
\r
229 this.anchor = 'top';
\r
230 return this.getTargetXY();
\r
232 if(axy[1]+sz.height > dh){
\r
233 if(this.anchorToTarget){
\r
234 this.defaultAlign = 'b-t';
\r
235 if(this.mouseOffset){this.mouseOffset[1] *= -1;}
\r
237 this.anchor = 'bottom';
\r
238 return this.getTargetXY();
\r
242 this.anchorCls = 'x-tip-anchor-'+this.getAnchorPosition();
\r
243 this.anchorEl.addClass(this.anchorCls);
\r
244 this.targetCounter = 0;
\r
247 var mouseOffset = this.getMouseOffset();
\r
248 return [this.targetXY[0]+mouseOffset[0], this.targetXY[1]+mouseOffset[1]];
\r
252 getMouseOffset : function(){
\r
253 var offset = this.anchor ? [0,0] : [15,18];
\r
254 if(this.mouseOffset){
\r
255 offset[0] += this.mouseOffset[0];
\r
256 offset[1] += this.mouseOffset[1];
\r
262 getAnchorPosition : function(){
\r
264 this.tipAnchor = this.anchor.charAt(0);
\r
266 var m = this.defaultAlign.match(/^([a-z]+)-([a-z]+)(\?)?$/);
\r
268 throw 'AnchorTip.defaultAlign is invalid';
\r
270 this.tipAnchor = m[1].charAt(0);
\r
273 switch(this.tipAnchor){
\r
274 case 't': return 'top';
\r
275 case 'b': return 'bottom';
\r
276 case 'r': return 'right';
\r
282 getAnchorAlign : function(){
\r
283 switch(this.anchor){
\r
284 case 'top' : return 'tl-bl';
\r
285 case 'left' : return 'tl-tr';
\r
286 case 'right': return 'tr-tl';
\r
287 default : return 'bl-tl';
\r
292 getOffsets : function(){
\r
294 ap = this.getAnchorPosition().charAt(0);
\r
295 if(this.anchorToTarget && !this.trackMouse){
\r
301 offsets = [0, -13];
\r
304 offsets = [-13, 0];
\r
313 offsets = [-15-this.anchorOffset, 30];
\r
316 offsets = [-19-this.anchorOffset, -13-this.el.dom.offsetHeight];
\r
319 offsets = [-15-this.el.dom.offsetWidth, -13-this.anchorOffset];
\r
322 offsets = [25, -13-this.anchorOffset];
\r
326 var mouseOffset = this.getMouseOffset();
\r
327 offsets[0] += mouseOffset[0];
\r
328 offsets[1] += mouseOffset[1];
\r
334 onTargetOver : function(e){
\r
335 if(this.disabled || e.within(this.target.dom, true)){
\r
338 var t = e.getTarget(this.delegate);
\r
340 this.triggerElement = t;
\r
341 this.clearTimer('hide');
\r
342 this.targetXY = e.getXY();
\r
348 delayShow : function(){
\r
349 if(this.hidden && !this.showTimer){
\r
350 if(this.lastActive.getElapsed() < this.quickShowInterval){
\r
353 this.showTimer = this.show.defer(this.showDelay, this);
\r
355 }else if(!this.hidden && this.autoHide !== false){
\r
361 onTargetOut : function(e){
\r
362 if(this.disabled || e.within(this.target.dom, true)){
\r
365 this.clearTimer('show');
\r
366 if(this.autoHide !== false){
\r
372 delayHide : function(){
\r
373 if(!this.hidden && !this.hideTimer){
\r
374 this.hideTimer = this.hide.defer(this.hideDelay, this);
\r
378 <div id="method-Ext.ToolTip-hide"></div>/**
\r
379 * Hides this tooltip if visible.
\r
382 this.clearTimer('dismiss');
\r
383 this.lastActive = new Date();
\r
385 this.anchorEl.hide();
\r
387 Ext.ToolTip.superclass.hide.call(this);
\r
388 delete this.triggerElement;
\r
391 <div id="method-Ext.ToolTip-show"></div>/**
\r
392 * Shows this tooltip at the current event target XY position.
\r
396 // pre-show it off screen so that the el will have dimensions
\r
397 // for positioning calcs when getting xy next
\r
398 this.showAt([-1000,-1000]);
\r
399 this.origConstrainPosition = this.constrainPosition;
\r
400 this.constrainPosition = false;
\r
401 this.anchor = this.origAnchor;
\r
403 this.showAt(this.getTargetXY());
\r
407 this.anchorEl.show();
\r
408 this.constrainPosition = this.origConstrainPosition;
\r
410 this.anchorEl.hide();
\r
415 showAt : function(xy){
\r
416 this.lastActive = new Date();
\r
417 this.clearTimers();
\r
418 Ext.ToolTip.superclass.showAt.call(this, xy);
\r
419 if(this.dismissDelay && this.autoHide !== false){
\r
420 this.dismissTimer = this.hide.defer(this.dismissDelay, this);
\r
422 if(this.anchor && !this.anchorEl.isVisible()){
\r
424 this.anchorEl.show();
\r
429 syncAnchor : function(){
\r
430 var anchorPos, targetPos, offset;
\r
431 switch(this.tipAnchor.charAt(0)){
\r
435 offset = [20+this.anchorOffset, 2];
\r
440 offset = [-2, 11+this.anchorOffset];
\r
445 offset = [20+this.anchorOffset, -2];
\r
450 offset = [2, 11+this.anchorOffset];
\r
453 this.anchorEl.alignTo(this.el, anchorPos+'-'+targetPos, offset);
\r
457 setPagePosition : function(x, y){
\r
458 Ext.ToolTip.superclass.setPagePosition.call(this, x, y);
\r
465 clearTimer : function(name){
\r
466 name = name + 'Timer';
\r
467 clearTimeout(this[name]);
\r
472 clearTimers : function(){
\r
473 this.clearTimer('show');
\r
474 this.clearTimer('dismiss');
\r
475 this.clearTimer('hide');
\r
479 onShow : function(){
\r
480 Ext.ToolTip.superclass.onShow.call(this);
\r
481 Ext.getDoc().on('mousedown', this.onDocMouseDown, this);
\r
485 onHide : function(){
\r
486 Ext.ToolTip.superclass.onHide.call(this);
\r
487 Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
\r
491 onDocMouseDown : function(e){
\r
492 if(this.autoHide !== true && !this.closable && !e.within(this.el.dom)){
\r
494 this.enable.defer(100, this);
\r
499 onDisable : function(){
\r
500 this.clearTimers();
\r
505 adjustPosition : function(x, y){
\r
506 if(this.contstrainPosition){
\r
507 var ay = this.targetXY[1], h = this.getSize().height;
\r
508 if(y <= ay && (y+h) >= ay){
\r
512 return {x : x, y: y};
\r
515 beforeDestroy : function(){
\r
516 this.clearTimers();
\r
517 Ext.destroy(this.anchorEl);
\r
518 delete this.anchorEl;
\r
519 delete this.target;
\r
520 delete this.anchorTarget;
\r
521 delete this.triggerElement;
\r
522 Ext.ToolTip.superclass.beforeDestroy.call(this);
\r
526 onDestroy : function(){
\r
527 Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
\r
528 Ext.ToolTip.superclass.onDestroy.call(this);
\r
532 Ext.reg('tooltip', Ext.ToolTip);</pre>
\r