2150 |
mathias |
1 |
if(!dojo._hasResource["dojo.dnd.move"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojo.dnd.move"] = true;
|
|
|
3 |
dojo.provide("dojo.dnd.move");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojo.dnd.Mover");
|
|
|
6 |
dojo.require("dojo.dnd.Moveable");
|
|
|
7 |
|
|
|
8 |
dojo.declare("dojo.dnd.move.constrainedMoveable", dojo.dnd.Moveable, {
|
|
|
9 |
// object attributes (for markup)
|
|
|
10 |
constraints: function(){},
|
|
|
11 |
within: false,
|
|
|
12 |
|
|
|
13 |
// markup methods
|
|
|
14 |
markupFactory: function(params, node){
|
|
|
15 |
return new dojo.dnd.move.constrainedMoveable(node, params);
|
|
|
16 |
},
|
|
|
17 |
|
|
|
18 |
constructor: function(node, params){
|
|
|
19 |
// summary: an object, which makes a node moveable
|
|
|
20 |
// node: Node: a node (or node's id) to be moved
|
|
|
21 |
// params: Object: an optional object with additional parameters;
|
|
|
22 |
// following parameters are recognized:
|
|
|
23 |
// constraints: Function: a function, which calculates a constraint box,
|
|
|
24 |
// it is called in a context of the moveable object.
|
|
|
25 |
// within: Boolean: restrict move within boundaries.
|
|
|
26 |
// the rest is passed to the base class
|
|
|
27 |
if(!params){ params = {}; }
|
|
|
28 |
this.constraints = params.constraints;
|
|
|
29 |
this.within = params.within;
|
|
|
30 |
},
|
|
|
31 |
onFirstMove: function(/* dojo.dnd.Mover */ mover){
|
|
|
32 |
// summary: called during the very first move notification,
|
|
|
33 |
// can be used to initialize coordinates, can be overwritten.
|
|
|
34 |
var c = this.constraintBox = this.constraints.call(this, mover), m = mover.marginBox;
|
|
|
35 |
c.r = c.l + c.w - (this.within ? m.w : 0);
|
|
|
36 |
c.b = c.t + c.h - (this.within ? m.h : 0);
|
|
|
37 |
},
|
|
|
38 |
onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
|
|
|
39 |
// summary: called during every move notification,
|
|
|
40 |
// should actually move the node, can be overwritten.
|
|
|
41 |
var c = this.constraintBox;
|
|
|
42 |
leftTop.l = leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l;
|
|
|
43 |
leftTop.t = leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t;
|
|
|
44 |
dojo.marginBox(mover.node, leftTop);
|
|
|
45 |
}
|
|
|
46 |
});
|
|
|
47 |
|
|
|
48 |
dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
|
|
|
49 |
// object attributes (for markup)
|
|
|
50 |
box: {},
|
|
|
51 |
|
|
|
52 |
// markup methods
|
|
|
53 |
markupFactory: function(params, node){
|
|
|
54 |
return new dojo.dnd.move.boxConstrainedMoveable(node, params);
|
|
|
55 |
},
|
|
|
56 |
|
|
|
57 |
constructor: function(node, params){
|
|
|
58 |
// summary: an object, which makes a node moveable
|
|
|
59 |
// node: Node: a node (or node's id) to be moved
|
|
|
60 |
// params: Object: an optional object with additional parameters;
|
|
|
61 |
// following parameters are recognized:
|
|
|
62 |
// box: Object: a constraint box
|
|
|
63 |
// the rest is passed to the base class
|
|
|
64 |
var box = params && params.box;
|
|
|
65 |
this.constraints = function(){ return box; };
|
|
|
66 |
}
|
|
|
67 |
});
|
|
|
68 |
|
|
|
69 |
dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
|
|
|
70 |
// object attributes (for markup)
|
|
|
71 |
area: "content",
|
|
|
72 |
|
|
|
73 |
// markup methods
|
|
|
74 |
markupFactory: function(params, node){
|
|
|
75 |
return new dojo.dnd.move.parentConstrainedMoveable(node, params);
|
|
|
76 |
},
|
|
|
77 |
|
|
|
78 |
constructor: function(node, params){
|
|
|
79 |
// summary: an object, which makes a node moveable
|
|
|
80 |
// node: Node: a node (or node's id) to be moved
|
|
|
81 |
// params: Object: an optional object with additional parameters;
|
|
|
82 |
// following parameters are recognized:
|
|
|
83 |
// area: String: a parent's area to restrict the move,
|
|
|
84 |
// can be "margin", "border", "padding", or "content".
|
|
|
85 |
// the rest is passed to the base class
|
|
|
86 |
var area = params && params.area;
|
|
|
87 |
this.constraints = function(){
|
|
|
88 |
var n = this.node.parentNode,
|
|
|
89 |
s = dojo.getComputedStyle(n),
|
|
|
90 |
mb = dojo._getMarginBox(n, s);
|
|
|
91 |
if(area == "margin"){
|
|
|
92 |
return mb; // Object
|
|
|
93 |
}
|
|
|
94 |
var t = dojo._getMarginExtents(n, s);
|
|
|
95 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
96 |
if(area == "border"){
|
|
|
97 |
return mb; // Object
|
|
|
98 |
}
|
|
|
99 |
t = dojo._getBorderExtents(n, s);
|
|
|
100 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
101 |
if(area == "padding"){
|
|
|
102 |
return mb; // Object
|
|
|
103 |
}
|
|
|
104 |
t = dojo._getPadExtents(n, s);
|
|
|
105 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
106 |
return mb; // Object
|
|
|
107 |
};
|
|
|
108 |
}
|
|
|
109 |
});
|
|
|
110 |
|
|
|
111 |
// WARNING: below are obsolete objects, instead of custom movers use custom moveables (above)
|
|
|
112 |
|
|
|
113 |
dojo.dnd.move.constrainedMover = function(fun, within){
|
|
|
114 |
// summary: returns a constrained version of dojo.dnd.Mover
|
|
|
115 |
// description: this function produces n object, which will put a constraint on
|
|
|
116 |
// the margin box of dragged object in absolute coordinates
|
|
|
117 |
// fun: Function: called on drag, and returns a constraint box
|
|
|
118 |
// within: Boolean: if true, constraints the whole dragged object withtin the rectangle,
|
|
|
119 |
// otherwise the constraint is applied to the left-top corner
|
|
|
120 |
var mover = function(node, e, notifier){
|
|
|
121 |
dojo.dnd.Mover.call(this, node, e, notifier);
|
|
|
122 |
};
|
|
|
123 |
dojo.extend(mover, dojo.dnd.Mover.prototype);
|
|
|
124 |
dojo.extend(mover, {
|
|
|
125 |
onMouseMove: function(e){
|
|
|
126 |
// summary: event processor for onmousemove
|
|
|
127 |
// e: Event: mouse event
|
|
|
128 |
dojo.dnd.autoScroll(e);
|
|
|
129 |
var m = this.marginBox, c = this.constraintBox,
|
|
|
130 |
l = m.l + e.pageX, t = m.t + e.pageY;
|
|
|
131 |
l = l < c.l ? c.l : c.r < l ? c.r : l;
|
|
|
132 |
t = t < c.t ? c.t : c.b < t ? c.b : t;
|
|
|
133 |
this.host.onMove(this, {l: l, t: t});
|
|
|
134 |
},
|
|
|
135 |
onFirstMove: function(){
|
|
|
136 |
// summary: called once to initialize things; it is meant to be called only once
|
|
|
137 |
dojo.dnd.Mover.prototype.onFirstMove.call(this);
|
|
|
138 |
var c = this.constraintBox = fun.call(this), m = this.marginBox;
|
|
|
139 |
c.r = c.l + c.w - (within ? m.w : 0);
|
|
|
140 |
c.b = c.t + c.h - (within ? m.h : 0);
|
|
|
141 |
}
|
|
|
142 |
});
|
|
|
143 |
return mover; // Object
|
|
|
144 |
};
|
|
|
145 |
|
|
|
146 |
dojo.dnd.move.boxConstrainedMover = function(box, within){
|
|
|
147 |
// summary: a specialization of dojo.dnd.constrainedMover, which constrains to the specified box
|
|
|
148 |
// box: Object: a constraint box (l, t, w, h)
|
|
|
149 |
// within: Boolean: if true, constraints the whole dragged object withtin the rectangle,
|
|
|
150 |
// otherwise the constraint is applied to the left-top corner
|
|
|
151 |
return dojo.dnd.move.constrainedMover(function(){ return box; }, within); // Object
|
|
|
152 |
};
|
|
|
153 |
|
|
|
154 |
dojo.dnd.move.parentConstrainedMover = function(area, within){
|
|
|
155 |
// summary: a specialization of dojo.dnd.constrainedMover, which constrains to the parent node
|
|
|
156 |
// area: String: "margin" to constrain within the parent's margin box, "border" for the border box,
|
|
|
157 |
// "padding" for the padding box, and "content" for the content box; "content" is the default value.
|
|
|
158 |
// within: Boolean: if true, constraints the whole dragged object withtin the rectangle,
|
|
|
159 |
// otherwise the constraint is applied to the left-top corner
|
|
|
160 |
var fun = function(){
|
|
|
161 |
var n = this.node.parentNode,
|
|
|
162 |
s = dojo.getComputedStyle(n),
|
|
|
163 |
mb = dojo._getMarginBox(n, s);
|
|
|
164 |
if(area == "margin"){
|
|
|
165 |
return mb; // Object
|
|
|
166 |
}
|
|
|
167 |
var t = dojo._getMarginExtents(n, s);
|
|
|
168 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
169 |
if(area == "border"){
|
|
|
170 |
return mb; // Object
|
|
|
171 |
}
|
|
|
172 |
t = dojo._getBorderExtents(n, s);
|
|
|
173 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
174 |
if(area == "padding"){
|
|
|
175 |
return mb; // Object
|
|
|
176 |
}
|
|
|
177 |
t = dojo._getPadExtents(n, s);
|
|
|
178 |
mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
|
|
|
179 |
return mb; // Object
|
|
|
180 |
};
|
|
|
181 |
return dojo.dnd.move.constrainedMover(fun, within); // Object
|
|
|
182 |
};
|
|
|
183 |
|
|
|
184 |
// patching functions one level up for compatibility
|
|
|
185 |
|
|
|
186 |
dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover;
|
|
|
187 |
dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover;
|
|
|
188 |
dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover;
|
|
|
189 |
|
|
|
190 |
}
|