]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/Mover.js.uncompressed.js
6e9934a3ac41ff5173aeeeb9c9d2d13145767316
1 define("dojo/dnd/Mover", [
2 "../_base/array", "../_base/declare", "../_base/event", "../_base/lang", "../sniff", "../_base/window",
3 "../dom", "../dom-geometry", "../dom-style", "../Evented", "../on", "../touch", "./common", "./autoscroll"
4 ], function(array
, declare
, event
, lang
, has
, win
, dom
, domGeom
, domStyle
, Evented
, on
, touch
, dnd
, autoscroll
){
9 return declare("dojo.dnd.Mover", [Evented
], {
11 // an object which makes a node follow the mouse, or touch-drag on touch devices.
12 // Used as a default mover, and as a base class for custom movers.
14 constructor: function(node
, e
, host
){
16 // a node (or node's id) to be moved
18 // a mouse event, which started the move;
19 // only pageX and pageY properties are used
21 // object which implements the functionality of the move,
22 // and defines proper events (onMoveStart and onMoveStop)
23 this.node
= dom
.byId(node
);
24 this.marginBox
= {l
: e
.pageX
, t
: e
.pageY
};
25 this.mouseButton
= e
.button
;
26 var h
= (this.host
= host
), d
= node
.ownerDocument
;
28 // At the start of a drag, onFirstMove is called, and then the following
29 // listener is disconnected.
30 on(d
, touch
.move, lang
.hitch(this, "onFirstMove")),
32 // These are called continually during the drag
33 on(d
, touch
.move, lang
.hitch(this, "onMouseMove")),
35 // And these are called at the end of the drag
36 on(d
, touch
.release
, lang
.hitch(this, "onMouseUp")),
38 // cancel text selection and text dragging
39 on(d
, "dragstart", event
.stop
),
40 on(d
.body
, "selectstart", event
.stop
)
43 // Tell autoscroll that a drag is starting
44 autoscroll
.autoScrollStart(d
);
46 // notify that the move has started
47 if(h
&& h
.onMoveStart
){
51 // mouse event processors
52 onMouseMove: function(e
){
54 // event processor for onmousemove/ontouchmove
57 autoscroll
.autoScroll(e
);
58 var m
= this.marginBox
;
59 this.host
.onMove(this, {l
: m
.l
+ e
.pageX
, t
: m
.t
+ e
.pageY
}, e
);
62 onMouseUp: function(e
){
63 if(has("webkit") && has("mac") && this.mouseButton
== 2 ?
64 e
.button
== 0 : this.mouseButton
== e
.button
){ // TODO Should condition be met for touch devices, too?
70 onFirstMove: function(e
){
72 // makes the node absolute; it is meant to be called only once.
73 // relative and absolutely positioned nodes are assumed to use pixel units
74 var s
= this.node
.style
, l
, t
, h
= this.host
;
78 // assume that left and top values are in pixels already
79 l
= Math
.round(parseFloat(s
.left
)) || 0;
80 t
= Math
.round(parseFloat(s
.top
)) || 0;
83 s
.position
= "absolute"; // enforcing the absolute mode
84 var m
= domGeom
.getMarginBox(this.node
);
85 // event.pageX/pageY (which we used to generate the initial
86 // margin box) includes padding and margin set on the body.
87 // However, setting the node's position to absolute and then
88 // doing domGeom.marginBox on it *doesn't* take that additional
89 // space into account - so we need to subtract the combined
90 // padding and margin. We use getComputedStyle and
91 // _getMarginBox/_getContentBox to avoid the extra lookup of
92 // the computed style.
94 var bs
= domStyle
.getComputedStyle(b
);
95 var bm
= domGeom
.getMarginBox(b
, bs
);
96 var bc
= domGeom
.getContentBox(b
, bs
);
97 l
= m
.l
- (bc
.l
- bm
.l
);
98 t
= m
.t
- (bc
.t
- bm
.t
);
101 this.marginBox
.l
= l
- this.marginBox
.l
;
102 this.marginBox
.t
= t
- this.marginBox
.t
;
103 if(h
&& h
.onFirstMove
){
104 h
.onFirstMove(this, e
);
107 // Disconnect touch.move that call this function
108 this.events
.shift().remove();
112 // stops the move, deletes all references, so the object can be garbage-collected
113 array
.forEach(this.events
, function(handle
){ handle
.remove(); });
114 // undo global settings
116 if(h
&& h
.onMoveStop
){
120 this.events
= this.node
= this.host
= null;