source: trunk/web/addons/job_monarch/lib/extjs-30/src/widgets/tips/Tip.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 5.2 KB
Line 
1/*!
2 * Ext JS Library 3.0.0
3 * Copyright(c) 2006-2009 Ext JS, LLC
4 * licensing@extjs.com
5 * http://www.extjs.com/license
6 */
7/**
8 * @class Ext.Tip
9 * @extends Ext.Panel
10 * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
11 * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
12 * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
13 * @constructor
14 * Create a new Tip
15 * @param {Object} config The configuration options
16 */
17Ext.Tip = Ext.extend(Ext.Panel, {
18    /**
19     * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
20     */
21    /**
22     * @cfg {Number} width
23     * Width in pixels of the tip (defaults to auto).  Width will be ignored if it exceeds the bounds of
24     * {@link #minWidth} or {@link #maxWidth}.  The maximum supported value is 500.
25     */
26    /**
27     * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
28     */
29    minWidth : 40,
30    /**
31     * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300).  The maximum supported value is 500.
32     */
33    maxWidth : 300,
34    /**
35     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
36     * for bottom-right shadow (defaults to "sides").
37     */
38    shadow : "sides",
39    /**
40     * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
41     * for this tip relative to its element of origin (defaults to "tl-bl?").
42     */
43    defaultAlign : "tl-bl?",
44    autoRender: true,
45    quickShowInterval : 250,
46
47    // private panel overrides
48    frame:true,
49    hidden:true,
50    baseCls: 'x-tip',
51    floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
52    autoHeight:true,
53
54    closeAction: 'hide',
55
56    // private
57    initComponent : function(){
58        Ext.Tip.superclass.initComponent.call(this);
59        if(this.closable && !this.title){
60            this.elements += ',header';
61        }
62    },
63
64    // private
65    afterRender : function(){
66        Ext.Tip.superclass.afterRender.call(this);
67        if(this.closable){
68            this.addTool({
69                id: 'close',
70                handler: this[this.closeAction],
71                scope: this
72            });
73        }
74    },
75
76    /**
77     * Shows this tip at the specified XY position.  Example usage:
78     * <pre><code>
79// Show the tip at x:50 and y:100
80tip.showAt([50,100]);
81</code></pre>
82     * @param {Array} xy An array containing the x and y coordinates
83     */
84    showAt : function(xy){
85        Ext.Tip.superclass.show.call(this);
86        if(this.measureWidth !== false && (!this.initialConfig || typeof this.initialConfig.width != 'number')){
87            this.doAutoWidth();
88        }
89        if(this.constrainPosition){
90            xy = this.el.adjustForConstraints(xy);
91        }
92        this.setPagePosition(xy[0], xy[1]);
93    },
94
95    // protected
96    doAutoWidth : function(){
97        var bw = this.body.getTextWidth();
98        if(this.title){
99            bw = Math.max(bw, this.header.child('span').getTextWidth(this.title));
100        }
101        bw += this.getFrameWidth() + (this.closable ? 20 : 0) + this.body.getPadding("lr");
102        this.setWidth(bw.constrain(this.minWidth, this.maxWidth));
103       
104        // IE7 repaint bug on initial show
105        if(Ext.isIE7 && !this.repainted){
106            this.el.repaint();
107            this.repainted = true;
108        }
109    },
110
111    /**
112     * <b>Experimental</b>. Shows this tip at a position relative to another element using a standard {@link Ext.Element#alignTo}
113     * anchor position value.  Example usage:
114     * <pre><code>
115// Show the tip at the default position ('tl-br?')
116tip.showBy('my-el');
117
118// Show the tip's top-left corner anchored to the element's top-right corner
119tip.showBy('my-el', 'tl-tr');
120</code></pre>
121     * @param {Mixed} el An HTMLElement, Ext.Element or string id of the target element to align to
122     * @param {String} position (optional) A valid {@link Ext.Element#alignTo} anchor position (defaults to 'tl-br?' or
123     * {@link #defaultAlign} if specified).
124     */
125    showBy : function(el, pos){
126        if(!this.rendered){
127            this.render(Ext.getBody());
128        }
129        this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign));
130    },
131
132    initDraggable : function(){
133        this.dd = new Ext.Tip.DD(this, typeof this.draggable == 'boolean' ? null : this.draggable);
134        this.header.addClass('x-tip-draggable');
135    }
136});
137
138// private - custom Tip DD implementation
139Ext.Tip.DD = function(tip, config){
140    Ext.apply(this, config);
141    this.tip = tip;
142    Ext.Tip.DD.superclass.constructor.call(this, tip.el.id, 'WindowDD-'+tip.id);
143    this.setHandleElId(tip.header.id);
144    this.scroll = false;
145};
146
147Ext.extend(Ext.Tip.DD, Ext.dd.DD, {
148    moveOnly:true,
149    scroll:false,
150    headerOffsets:[100, 25],
151    startDrag : function(){
152        this.tip.el.disableShadow();
153    },
154    endDrag : function(e){
155        this.tip.el.enableShadow(true);
156    }
157});
Note: See TracBrowser for help on using the repository browser.