2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.ToolTip
\r
12 * A standard tooltip implementation for providing additional information when hovering over a target element.
\r
14 * Create a new Tooltip
\r
15 * @param {Object} config The configuration options
\r
17 Ext.ToolTip = Ext.extend(Ext.Tip, {
\r
19 * @cfg {Mixed} target The target HTMLElement, Ext.Element or id to associate with this tooltip.
\r
22 * @cfg {Boolean} autoHide True to automatically hide the tooltip after the mouse exits the target element
\r
23 * or after the {@link #dismissDelay} has expired if set (defaults to true). If {@link closable} = true a close
\r
24 * tool button will be rendered into the tooltip header.
\r
27 * @cfg {Number} showDelay Delay in milliseconds before the tooltip displays after the mouse enters the
\r
28 * target element (defaults to 500)
\r
32 * @cfg {Number} hideDelay Delay in milliseconds after the mouse exits the target element but before the
\r
33 * tooltip actually hides (defaults to 200). Set to 0 for the tooltip to hide immediately.
\r
37 * @cfg {Number} dismissDelay Delay in milliseconds before the tooltip automatically hides (defaults to 5000).
\r
38 * To disable automatic hiding, set dismissDelay = 0.
\r
42 * @cfg {Array} mouseOffset An XY offset from the mouse position where the tooltip should be shown (defaults to [15,18]).
\r
44 mouseOffset: [15,18],
\r
46 * @cfg {Boolean} trackMouse True to have the tooltip follow the mouse as it moves over the target element (defaults to false).
\r
49 constrainPosition: true,
\r
52 initComponent: function(){
\r
53 Ext.ToolTip.superclass.initComponent.call(this);
\r
54 this.lastActive = new Date();
\r
59 initTarget : function(){
\r
61 this.target = Ext.get(this.target);
\r
62 this.target.on('mouseover', this.onTargetOver, this);
\r
63 this.target.on('mouseout', this.onTargetOut, this);
\r
64 this.target.on('mousemove', this.onMouseMove, this);
\r
69 onMouseMove : function(e){
\r
70 this.targetXY = e.getXY();
\r
71 if(!this.hidden && this.trackMouse){
\r
72 this.setPagePosition(this.getTargetXY());
\r
77 getTargetXY : function(){
\r
78 return [this.targetXY[0]+this.mouseOffset[0], this.targetXY[1]+this.mouseOffset[1]];
\r
82 onTargetOver : function(e){
\r
83 if(this.disabled || e.within(this.target.dom, true)){
\r
86 this.clearTimer('hide');
\r
87 this.targetXY = e.getXY();
\r
92 delayShow : function(){
\r
93 if(this.hidden && !this.showTimer){
\r
94 if(this.lastActive.getElapsed() < this.quickShowInterval){
\r
97 this.showTimer = this.show.defer(this.showDelay, this);
\r
99 }else if(!this.hidden && this.autoHide !== false){
\r
105 onTargetOut : function(e){
\r
106 if(this.disabled || e.within(this.target.dom, true)){
\r
109 this.clearTimer('show');
\r
110 if(this.autoHide !== false){
\r
116 delayHide : function(){
\r
117 if(!this.hidden && !this.hideTimer){
\r
118 this.hideTimer = this.hide.defer(this.hideDelay, this);
\r
123 * Hides this tooltip if visible.
\r
126 this.clearTimer('dismiss');
\r
127 this.lastActive = new Date();
\r
128 Ext.ToolTip.superclass.hide.call(this);
\r
132 * Shows this tooltip at the current event target XY position.
\r
135 this.showAt(this.getTargetXY());
\r
139 showAt : function(xy){
\r
140 this.lastActive = new Date();
\r
141 this.clearTimers();
\r
142 Ext.ToolTip.superclass.showAt.call(this, xy);
\r
143 if(this.dismissDelay && this.autoHide !== false){
\r
144 this.dismissTimer = this.hide.defer(this.dismissDelay, this);
\r
149 clearTimer : function(name){
\r
150 name = name + 'Timer';
\r
151 clearTimeout(this[name]);
\r
156 clearTimers : function(){
\r
157 this.clearTimer('show');
\r
158 this.clearTimer('dismiss');
\r
159 this.clearTimer('hide');
\r
163 onShow : function(){
\r
164 Ext.ToolTip.superclass.onShow.call(this);
\r
165 Ext.getDoc().on('mousedown', this.onDocMouseDown, this);
\r
169 onHide : function(){
\r
170 Ext.ToolTip.superclass.onHide.call(this);
\r
171 Ext.getDoc().un('mousedown', this.onDocMouseDown, this);
\r
175 onDocMouseDown : function(e){
\r
176 if(this.autoHide !== false && !e.within(this.el.dom)){
\r
178 this.enable.defer(100, this);
\r
183 onDisable : function(){
\r
184 this.clearTimers();
\r
189 adjustPosition : function(x, y){
\r
190 // keep the position from being under the mouse
\r
191 var ay = this.targetXY[1], h = this.getSize().height;
\r
192 if(this.constrainPosition && y <= ay && (y+h) >= ay){
\r
195 return {x : x, y: y};
\r
199 onDestroy : function(){
\r
200 Ext.ToolTip.superclass.onDestroy.call(this);
\r
202 this.target.un('mouseover', this.onTargetOver, this);
\r
203 this.target.un('mouseout', this.onTargetOut, this);
\r
204 this.target.un('mousemove', this.onMouseMove, this);
\r