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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/ext/source/dd/DragTracker.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
Ext.dd.DragTracker = function(config){
 
10
    Ext.apply(this, config);
 
11
    this.addEvents(
 
12
        'mousedown',
 
13
        'mouseup',
 
14
        'mousemove',
 
15
        'dragstart',
 
16
        'dragend',
 
17
        'drag'
 
18
    );
 
19
 
 
20
    this.dragRegion = new Ext.lib.Region(0,0,0,0);
 
21
 
 
22
    if(this.el){
 
23
        this.initEl(this.el);
 
24
    }
 
25
}
 
26
 
 
27
Ext.extend(Ext.dd.DragTracker, Ext.util.Observable,  {
 
28
    active: false,
 
29
    tolerance: 5,
 
30
    autoStart: false,
 
31
 
 
32
    initEl: function(el){
 
33
        this.el = Ext.get(el);
 
34
        el.on('mousedown', this.onMouseDown, this,
 
35
                this.delegate ? {delegate: this.delegate} : undefined);
 
36
    },
 
37
 
 
38
    destroy : function(){
 
39
        this.el.un('mousedown', this.onMouseDown, this);
 
40
    },
 
41
 
 
42
    onMouseDown: function(e, target){
 
43
        if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
 
44
            this.startXY = this.lastXY = e.getXY();
 
45
            this.dragTarget = this.delegate ? target : this.el.dom;
 
46
            e.preventDefault();
 
47
            var doc = Ext.getDoc();
 
48
            doc.on('mouseup', this.onMouseUp, this);
 
49
            doc.on('mousemove', this.onMouseMove, this);
 
50
            doc.on('selectstart', this.stopSelect, this);
 
51
            if(this.autoStart){
 
52
                this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
 
53
            }
 
54
        }
 
55
    },
 
56
 
 
57
    onMouseMove: function(e, target){
 
58
        e.preventDefault();
 
59
        var xy = e.getXY(), s = this.startXY;
 
60
        this.lastXY = xy;
 
61
        if(!this.active){
 
62
            if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
 
63
                this.triggerStart();
 
64
            }else{
 
65
                return;
 
66
            }
 
67
        }
 
68
        this.fireEvent('mousemove', this, e);
 
69
        this.onDrag(e);
 
70
        this.fireEvent('drag', this, e);
 
71
    },
 
72
 
 
73
    onMouseUp: function(e){
 
74
        var doc = Ext.getDoc();
 
75
        doc.un('mousemove', this.onMouseMove, this);
 
76
        doc.un('mouseup', this.onMouseUp, this);
 
77
        doc.un('selectstart', this.stopSelect, this);
 
78
        e.preventDefault();
 
79
        this.clearStart();
 
80
        this.active = false;
 
81
        delete this.elRegion;
 
82
        this.fireEvent('mouseup', this, e);
 
83
        this.onEnd(e);
 
84
        this.fireEvent('dragend', this, e);
 
85
    },
 
86
 
 
87
    triggerStart: function(isTimer){
 
88
        this.clearStart();
 
89
        this.active = true;
 
90
        this.onStart(this.startXY);
 
91
        this.fireEvent('dragstart', this, this.startXY);
 
92
    },
 
93
 
 
94
    clearStart : function(){
 
95
        if(this.timer){
 
96
            clearTimeout(this.timer);
 
97
            delete this.timer;
 
98
        }
 
99
    },
 
100
 
 
101
    stopSelect : function(e){
 
102
        e.stopEvent();
 
103
        return false;
 
104
    },
 
105
 
 
106
    onBeforeStart : function(e){
 
107
 
 
108
    },
 
109
 
 
110
    onStart : function(xy){
 
111
 
 
112
    },
 
113
 
 
114
    onDrag : function(e){
 
115
 
 
116
    },
 
117
 
 
118
    onEnd : function(e){
 
119
 
 
120
    },
 
121
 
 
122
    getDragTarget : function(){
 
123
        return this.dragTarget;
 
124
    },
 
125
 
 
126
    getDragCt : function(){
 
127
        return this.el;
 
128
    },
 
129
 
 
130
    getXY : function(constrain){
 
131
        return constrain ?
 
132
               this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
 
133
    },
 
134
 
 
135
    getOffset : function(constrain){
 
136
        var xy = this.getXY(constrain);
 
137
        var s = this.startXY;
 
138
        return [s[0]-xy[0], s[1]-xy[1]];
 
139
    },
 
140
 
 
141
    constrainModes: {
 
142
        'point' : function(xy){
 
143
 
 
144
            if(!this.elRegion){
 
145
                this.elRegion = this.getDragCt().getRegion();
 
146
            }
 
147
 
 
148
            var dr = this.dragRegion;
 
149
 
 
150
            dr.left = xy[0];
 
151
            dr.top = xy[1];
 
152
            dr.right = xy[0];
 
153
            dr.bottom = xy[1];
 
154
 
 
155
            dr.constrainTo(this.elRegion);
 
156
 
 
157
            return [dr.left, dr.top];
 
158
        }
 
159
    }
 
160
});
 
 
b'\\ No newline at end of file'