3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.Tip"></div>/**
\r
16 * @extends Ext.Panel
\r
18 * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
\r
19 * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
\r
20 * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
\r
23 * @param {Object} config The configuration options
\r
25 Ext.Tip = Ext.extend(Ext.Panel, {
\r
26 <div id="cfg-Ext.Tip-closable"></div>/**
\r
27 * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
\r
29 <div id="cfg-Ext.Tip-width"></div>/**
\r
30 * @cfg {Number} width
\r
31 * Width in pixels of the tip (defaults to auto). Width will be ignored if it exceeds the bounds of
\r
32 * {@link #minWidth} or {@link #maxWidth}. The maximum supported value is 500.
\r
34 <div id="cfg-Ext.Tip-minWidth"></div>/**
\r
35 * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
\r
38 <div id="cfg-Ext.Tip-maxWidth"></div>/**
\r
39 * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300). The maximum supported value is 500.
\r
42 <div id="cfg-Ext.Tip-shadow"></div>/**
\r
43 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
\r
44 * for bottom-right shadow (defaults to "sides").
\r
47 <div id="cfg-Ext.Tip-defaultAlign"></div>/**
\r
48 * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
\r
49 * for this tip relative to its element of origin (defaults to "tl-bl?").
\r
51 defaultAlign : "tl-bl?",
\r
53 quickShowInterval : 250,
\r
55 // private panel overrides
\r
59 floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
\r
62 closeAction: 'hide',
\r
65 initComponent : function(){
\r
66 Ext.Tip.superclass.initComponent.call(this);
\r
67 if(this.closable && !this.title){
\r
68 this.elements += ',header';
\r
73 afterRender : function(){
\r
74 Ext.Tip.superclass.afterRender.call(this);
\r
78 handler: this[this.closeAction],
\r
84 <div id="method-Ext.Tip-showAt"></div>/**
\r
85 * Shows this tip at the specified XY position. Example usage:
\r
87 // Show the tip at x:50 and y:100
\r
88 tip.showAt([50,100]);
\r
90 * @param {Array} xy An array containing the x and y coordinates
\r
92 showAt : function(xy){
\r
93 Ext.Tip.superclass.show.call(this);
\r
94 if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){
\r
97 if(this.constrainPosition){
\r
98 xy = this.el.adjustForConstraints(xy);
\r
100 this.setPagePosition(xy[0], xy[1]);
\r
104 doAutoWidth : function(){
\r
105 var bw = this.body.getTextWidth();
\r
107 bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));
\r
109 bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr");
\r
110 this.setWidth(bw.constrain(this.minWidth, this.maxWidth));
\r
112 // IE7 repaint bug on initial show
\r
113 if(Ext.isIE7 && !this.repainted){
\r
115 this.repainted = true;
\r
119 <div id="method-Ext.Tip-showBy"></div>/**
\r
120 * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}
\r
121 * anchor position value. Example usage:
\r
123 // Show the tip at the default position ('tl-br?')
\r
124 tip.showBy('my-el');
\r
126 // Show the tip's top-left corner anchored to the element's top-right corner
\r
127 tip.showBy('my-el', 'tl-tr');
\r
129 * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to
\r
130 * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or
\r
131 * {@link #defaultAlign} if specified).
\r
133 showBy : function(el, pos){
\r
134 if(!this.rendered){
\r
135 this.render(Ext.getBody());
\r
137 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
\r
140 initDraggable : function(){
\r
141 this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);
\r
142 this.header.addClass('x-tip-draggable');
\r
146 Ext.reg('tip', Ext.Tip);
\r
148 // private - custom Tip DD implementation
\r
149 Ext.Tip.DD = function(tip, config){
\r
150 Ext.apply(this, config);
\r
152 Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);
\r
153 this.setHandleElId(tip.header.id);
\r
154 this.scroll = false;
\r
157 Ext.extend(Ext.Tip.DD, Ext.dd.DD, {
\r
160 headerOffsets:[100, 25],
\r
161 startDrag : function(){
\r
162 this.tip.el.disableShadow();
\r
164 endDrag : function(e){
\r
165 this.tip.el.enableShadow(true);
\r