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