source: trunk/expressoCalendar/js/drag_area.js @ 632

Revision 632, 3.1 KB checked in by niltonneto, 15 years ago (diff)

Modulo calendar_new renomeado para expressoCalendar

  • Property svn:executable set to *
Line 
1var agt=navigator.userAgent.toLowerCase();
2var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
3
4function DragArea(){
5        this.pressed = 0;
6        this.resizing = 0;
7        this.initEvent;
8        this.endEvent;
9        this.currentEvent;
10}
11
12DragArea.prototype.loadMouseDown = function(e) {
13        var     _event  = is_ie ? window.event : e;
14        var     _target = is_ie ? window.event.srcElement : e.target;
15        var _button = is_ie ? _event.button : _event.which;
16       
17        if (typeof _event.preventDefault != 'undefined') {
18                _event.preventDefault();
19        }
20
21        this.pressed = 1;       
22
23        if(_button != 2 && _button != 3) {
24                if(_target.id && _target.id.length == 12){
25                        if (parseInt(_target.id) > 0)
26                                this.initEvent = _target.id;
27                }       
28        }       
29};
30
31DragArea.prototype.loadMouseMove = function(e) {
32        if(!this.pressed) {
33                return true;
34        }
35        var id = is_ie ? window.event.srcElement.id : e.target.id;
36        var continues = true;
37        var colorCell = function (id,style){
38                try {
39                        document.getElementById(id).style.background = style;
40                }
41                catch(e)
42                { continues = false; };
43        };
44
45        var incHour = function (hour,op){
46        if (op == '+')
47                (hour%100 >= 30)?hour+=70:hour+=30;
48        else
49                (hour%100 == 30)?hour-=30:hour-=70;
50        return hour;
51        };
52
53        if((parseInt(id) > 0) && (id.length == 12)){
54                if (this.endEvent < this.initEvent)
55                        if (id <= this.endEvent)
56                                for (var hour = parseInt(this.initEvent); hour >= parseInt(id) && continues;hour=incHour(hour,'-'))
57                                        colorCell(hour,"#EEE");
58                        else
59                                for (var hour = parseInt(id); hour >= parseInt(this.endEvent) && continues;hour=incHour(hour,'-'))
60                                        colorCell(hour,"");
61                else
62                        if (id < this.endEvent)
63                                for (var hour = parseInt(id); hour <= parseInt(this.endEvent) && continues;hour=incHour(hour,'+'))
64                                        colorCell(hour,"");
65                        else
66                                for (var hour = parseInt(this.initEvent); hour <= parseInt(id) && continues;hour=incHour(hour,'+'))
67                                        colorCell(hour,"#EEE");
68                this.endEvent=id;
69                return true;
70        }
71};
72
73document.onmousemove = function(event) {_dragArea.loadMouseMove(event);};
74document.onmousedown = function(event) {_dragArea.loadMouseDown(event);};
75document.onmouseup = function(event) {_dragArea.loadMouseUp(event);};
76
77DragArea.prototype.loadMouseUp = function(e) {
78        this.pressed = 0;
79        var _event  = is_ie ? window.event : e;
80        var id = is_ie ? window.event.srcElement.id : e.target.id;
81        var _button = is_ie ? _event.button : _event.which;
82       
83        if(_button != 2 && _button != 3) {
84                if((parseInt(id) > 0) && (id.length == 12))
85                        if (this.resizing == 0){
86                                calendar.dialog();
87                }else{
88                        if (confirm(get_lang('Change the end of this event to %1',calendar.parseDate(id2timeStamp(id)))+' ('+id.substr(8,2)+':'+id.substr(10,2)+') ?')){
89                                changeEvent(this.currentEvent,'edatetime',parseInt((id2timeStamp(id)+1800000)/1000));
90                        }
91                        for (var hour = parseInt(_dragArea.initEvent); hour <= parseInt(_dragArea.endEvent);(hour%100 == 30)?hour+=70:hour+=30)
92                                document.getElementById(hour).style.background = "";
93                        this.resizing = 0;
94                }
95        }
96}
97
98counter = 0;
99DragArea.prototype.moveWindow = function(e,elem) {
100        if (this.pressed){
101                var _event  = is_ie ? window.event : e;
102                elem.style.left = (_event.clientX - 80) + "px";
103                elem.style.top = (_event.clientY - 80) + "px";
104        }
105}
106var _dragArea = new DragArea();
Note: See TracBrowser for help on using the repository browser.