~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/widgets/tips/Tip.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 2.2
 
3
 * Copyright(c) 2006-2008, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.Tip
 
11
 * @extends Ext.Panel
 
12
 * This is the base class for {@link Ext.QuickTip} and {@link Ext.Tooltip} that provides the basic layout and
 
13
 * positioning that all tip-based classes require. This class can be used directly for simple, statically-positioned
 
14
 * tips that are displayed programmatically, or it can be extended to provide custom tip implementations.
 
15
 * @constructor
 
16
 * Create a new Tip
 
17
 * @param {Object} config The configuration options
 
18
 */
 
19
Ext.Tip = Ext.extend(Ext.Panel, {
 
20
    /**
 
21
     * @cfg {Boolean} closable True to render a close tool button into the tooltip header (defaults to false).
 
22
     */
 
23
    /**
 
24
     * @cfg {Number} width
 
25
     * Width in pixels of the tip (defaults to auto).  Width will be ignored if it exceeds the bounds of
 
26
     * {@link #minWidth} or {@link #maxWidth}.  The maximum supported value is 500.
 
27
     */
 
28
    /**
 
29
     * @cfg {Number} minWidth The minimum width of the tip in pixels (defaults to 40).
 
30
     */
 
31
    minWidth : 40,
 
32
    /**
 
33
     * @cfg {Number} maxWidth The maximum width of the tip in pixels (defaults to 300).  The maximum supported value is 500.
 
34
     */
 
35
    maxWidth : 300,
 
36
    /**
 
37
     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
 
38
     * for bottom-right shadow (defaults to "sides").
 
39
     */
 
40
    shadow : "sides",
 
41
    /**
 
42
     * @cfg {String} defaultAlign <b>Experimental</b>. The default {@link Ext.Element#alignTo} anchor position value
 
43
     * for this tip relative to its element of origin (defaults to "tl-bl?").
 
44
     */
 
45
    defaultAlign : "tl-bl?",
 
46
    autoRender: true,
 
47
    quickShowInterval : 250,
 
48
 
 
49
    // private panel overrides
 
50
    frame:true,
 
51
    hidden:true,
 
52
    baseCls: 'x-tip',
 
53
    floating:{shadow:true,shim:true,useDisplay:true,constrain:false},
 
54
    autoHeight:true,
 
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.hide,
 
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
 
80
tip.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?')
 
116
tip.showBy('my-el');
 
117
 
 
118
// Show the tip's top-left corner anchored to the element's top-right corner
 
119
tip.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
 
139
Ext.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
 
 
147
Ext.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
});
 
 
b'\\ No newline at end of file'