2
* Makes a DOM object draggable
4
* If you just want to move objects around, use drag.attach. For full
5
* customization, drag can be used as a javascript prototype, it is
9
* @link http://nofunc.org/Drag_Drop/
14
oX: 0, // object X position
15
oY: 0, // object Y position
16
eX: 0, // event X delta
17
eY: 0, // event Y delta
20
* Attaches the needed handlers to the given object
22
* This can be called for multiple objects, the right one is later
23
* determined from the event itself. The handle is optional
25
* @param DOMObject obj The object that should be draggable
26
* @param DOMObject handle A handle on which the obj can be dragged
28
attach: function (obj,handle) {
29
DEPRECATED('Use jQuery.draggable() instead.');
31
handle.dragobject = obj;
36
addEvent($(handle),'mousedown',function (e) {return _this.start(e); });
40
* Starts the dragging operation
43
this.handle = e.target;
44
if(this.handle.dragobject){
45
this.obj = this.handle.dragobject;
47
this.obj = this.handle;
50
this.handle.className += ' ondrag';
51
this.obj.className += ' ondrag';
53
this.oX = parseInt(this.obj.style.left);
54
this.oY = parseInt(this.obj.style.top);
59
this.mousehandlers = [function (e) {return _this.drag(e);}, function (e) {return _this.stop(e);}];
60
addEvent(document,'mousemove', this.mousehandlers[0]);
61
addEvent(document,'mouseup', this.mousehandlers[1]);
67
* Ends the dragging operation
70
this.handle.className = this.handle.className.replace(/ ?ondrag/,'');
71
this.obj.className = this.obj.className.replace(/ ?ondrag/,'');
72
removeEvent(document,'mousemove', this.mousehandlers[0]);
73
removeEvent(document,'mouseup', this.mousehandlers[1]);
79
* Moves the object during the dragging operation
83
this.obj.style.top = (e.pageY+this.oY-this.eY+'px');
84
this.obj.style.left = (e.pageX+this.oX-this.eX+'px');