3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
11 * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
12 * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
13 * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
16 * @param {Object} config The configuration options
18 Ext.Tip = Ext.extend(Ext.Panel, {
20 * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
24 * Width in pixels of the tip (defaults to auto). Width will be ignored if it exceeds the bounds of
25 * {@link #minWidth} or {@link #maxWidth}. The maximum supported value is 500.
28 * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
32 * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300). The maximum supported value is 500.
36 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
37 * for bottom-right shadow (defaults to "sides").
41 * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
42 * for this tip relative to its element of origin (defaults to "tl-bl?").
44 defaultAlign : "tl-bl?",
46 quickShowInterval : 250,
48 // private panel overrides
52 floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
58 initComponent : function(){
59 Ext.Tip.superclass.initComponent.call(this);
60 if(this.closable && !this.title){
61 this.elements += ',header';
66 afterRender : function(){
67 Ext.Tip.superclass.afterRender.call(this);
71 handler: this[this.closeAction],
78 * Shows this tip at the specified XY position. Example usage:
80 // Show the tip at x:50 and y:100
83 * @param {Array} xy An array containing the x and y coordinates
85 showAt : function(xy){
86 Ext.Tip.superclass.show.call(this);
87 if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){
90 if(this.constrainPosition){
91 xy = this.el.adjustForConstraints(xy);
93 this.setPagePosition(xy[0], xy[1]);
97 doAutoWidth : function(adjust){
99 var bw = this.body.getTextWidth();
101 bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));
103 bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr") + adjust;
104 this.setWidth(bw.constrain(this.minWidth, this.maxWidth));
106 // IE7 repaint bug on initial show
107 if(Ext.isIE7 && !this.repainted){
109 this.repainted = true;
114 * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}
115 * anchor position value. Example usage:
117 // Show the tip at the default position ('tl-br?')
120 // Show the tip's top-left corner anchored to the element's top-right corner
121 tip.showBy('my-el', 'tl-tr');
123 * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to
124 * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or
125 * {@link #defaultAlign} if specified).
127 showBy : function(el, pos){
129 this.render(Ext.getBody());
131 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
134 initDraggable : function(){
135 this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);
136 this.header.addClass('x-tip-draggable');
140 Ext.reg('tip', Ext.Tip);
142 // private - custom Tip DD implementation
143 Ext.Tip.DD = function(tip, config){
144 Ext.apply(this, config);
146 Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);
147 this.setHandleElId(tip.header.id);
151 Ext.extend(Ext.Tip.DD, Ext.dd.DD, {
154 headerOffsets:[100, 25],
155 startDrag : function(){
156 this.tip.el.disableShadow();
158 endDrag : function(e){
159 this.tip.el.enableShadow(true);