3 Drag: A Really Simple Drag Handler
13 // We need to remember what we're dragging.
14 Drag
._target
= e
.target();
17 There's no cross-browser way to get offsetX and offsetY, so we
18 have to do it ourselves. For performance, we do this once and
21 Drag
._offset
= Drag
._diff(
23 getElementPosition(Drag
._target
));
25 Drag
._move
= connect(document
, 'onmousemove', Drag
._drag
);
26 Drag
._down
= connect(document
, 'onmouseup', Drag
._stop
);
32 _diff
: function(lhs
, rhs
) {
33 return new MochiKit
.Style
.Coordinates(lhs
.x
- rhs
.x
, lhs
.y
- rhs
.y
);
40 Drag
._diff(e
.mouse().page
, Drag
._offset
));
44 disconnect(Drag
._move
);
45 disconnect(Drag
._down
);
49 connect(window
, 'onload',
52 Find all DIVs tagged with the draggable class, and connect them to
55 var d
= getElementsByTagAndClassName('DIV', 'draggable');
58 connect(elem
, 'onmousedown', Drag
.start
);
63 connect(window
, 'onload',
65 var elems
= getElementsByTagAndClassName("A", "view-source");
66 var page
= "draggable/";
67 for (var i
= 0; i
< elems
.length
; i
++) {
69 var href
= elem
.href
.split(/\//).pop();
70 elem
.target
= "_blank";
71 elem
.href
= "../view-source/view-source.html#" + page
+ href
;