var agt=navigator.userAgent.toLowerCase(); var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); function DragArea(){ this.pressed = 0; this.resizing = 0; this.initEvent; this.endEvent; this.currentEvent; } DragArea.prototype.loadMouseDown = function(e) { var _event = is_ie ? window.event : e; var _target = is_ie ? window.event.srcElement : e.target; var _button = is_ie ? _event.button : _event.which; if (typeof _event.preventDefault != 'undefined') { _event.preventDefault(); } this.pressed = 1; if(_button != 2 && _button != 3) { if(_target.id && _target.id.length == 12){ if (parseInt(_target.id) > 0) this.initEvent = _target.id; } } }; DragArea.prototype.loadMouseMove = function(e) { if(!this.pressed) { return true; } var id = is_ie ? window.event.srcElement.id : e.target.id; var continues = true; var colorCell = function (id,style){ try { document.getElementById(id).style.background = style; } catch(e) { continues = false; }; }; var incHour = function (hour,op){ if (op == '+') (hour%100 >= 30)?hour+=70:hour+=30; else (hour%100 == 30)?hour-=30:hour-=70; return hour; }; if((parseInt(id) > 0) && (id.length == 12)){ if (this.endEvent < this.initEvent) if (id <= this.endEvent) for (var hour = parseInt(this.initEvent); hour >= parseInt(id) && continues;hour=incHour(hour,'-')) colorCell(hour,"#EEE"); else for (var hour = parseInt(id); hour >= parseInt(this.endEvent) && continues;hour=incHour(hour,'-')) colorCell(hour,""); else if (id < this.endEvent) for (var hour = parseInt(id); hour <= parseInt(this.endEvent) && continues;hour=incHour(hour,'+')) colorCell(hour,""); else for (var hour = parseInt(this.initEvent); hour <= parseInt(id) && continues;hour=incHour(hour,'+')) colorCell(hour,"#EEE"); this.endEvent=id; return true; } }; document.onmousemove = function(event) {_dragArea.loadMouseMove(event);}; document.onmousedown = function(event) {_dragArea.loadMouseDown(event);}; document.onmouseup = function(event) {_dragArea.loadMouseUp(event);}; DragArea.prototype.loadMouseUp = function(e) { this.pressed = 0; var _event = is_ie ? window.event : e; var id = is_ie ? window.event.srcElement.id : e.target.id; var _button = is_ie ? _event.button : _event.which; if(_button != 2 && _button != 3) { if((parseInt(id) > 0) && (id.length == 12)) if (this.resizing == 0){ calendar.dialog(); }else{ if (confirm(get_lang('Change the end of this event to %1',calendar.parseDate(id2timeStamp(id)))+' ('+id.substr(8,2)+':'+id.substr(10,2)+') ?')){ changeEvent(this.currentEvent,'edatetime',parseInt((id2timeStamp(id)+1800000)/1000)); } for (var hour = parseInt(_dragArea.initEvent); hour <= parseInt(_dragArea.endEvent);(hour%100 == 30)?hour+=70:hour+=30) document.getElementById(hour).style.background = ""; this.resizing = 0; } } } counter = 0; DragArea.prototype.moveWindow = function(e,elem) { if (this.pressed){ var _event = is_ie ? window.event : e; elem.style.left = (_event.clientX - 80) + "px"; elem.style.top = (_event.clientY - 80) + "px"; } } var _dragArea = new DragArea();