]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/dnd/move.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / dnd / move.js
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);
35                 c.r = c.l + c.w;
36                 c.b = c.t + c.h;
37                 if(this.within){
38                         var mb = dojo.marginBox(mover.node);
39                         c.r -= mb.w;
40                         c.b -= mb.h;
41                 }
42         },
43         onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
44                 // summary: called during every move notification,
45                 //      should actually move the node, can be overwritten.
46                 var c = this.constraintBox, s = mover.node.style;
47                 s.left = (leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l) + "px";
48                 s.top  = (leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t) + "px";
49         }
50 });
51
52 dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
53         // object attributes (for markup)
54         box: {},
55         
56         // markup methods
57         markupFactory: function(params, node){
58                 return new dojo.dnd.move.boxConstrainedMoveable(node, params);
59         },
60
61         constructor: function(node, params){
62                 // summary: an object, which makes a node moveable
63                 // node: Node: a node (or node's id) to be moved
64                 // params: Object: an optional object with additional parameters;
65                 //      following parameters are recognized:
66                 //              box: Object: a constraint box
67                 //      the rest is passed to the base class
68                 var box = params && params.box;
69                 this.constraints = function(){ return box; };
70         }
71 });
72
73 dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
74         // object attributes (for markup)
75         area: "content",
76
77         // markup methods
78         markupFactory: function(params, node){
79                 return new dojo.dnd.move.parentConstrainedMoveable(node, params);
80         },
81
82         constructor: function(node, params){
83                 // summary: an object, which makes a node moveable
84                 // node: Node: a node (or node's id) to be moved
85                 // params: Object: an optional object with additional parameters;
86                 //      following parameters are recognized:
87                 //              area: String: a parent's area to restrict the move,
88                 //                      can be "margin", "border", "padding", or "content".
89                 //      the rest is passed to the base class
90                 var area = params && params.area;
91                 this.constraints = function(){
92                         var n = this.node.parentNode, 
93                                 s = dojo.getComputedStyle(n), 
94                                 mb = dojo._getMarginBox(n, s);
95                         if(area == "margin"){
96                                 return mb;      // Object
97                         }
98                         var t = dojo._getMarginExtents(n, s);
99                         mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
100                         if(area == "border"){
101                                 return mb;      // Object
102                         }
103                         t = dojo._getBorderExtents(n, s);
104                         mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
105                         if(area == "padding"){
106                                 return mb;      // Object
107                         }
108                         t = dojo._getPadExtents(n, s);
109                         mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
110                         return mb;      // Object
111                 };
112         }
113 });
114
115 // WARNING: below are obsolete objects, instead of custom movers use custom moveables (above)
116
117 dojo.dnd.move.constrainedMover = function(fun, within){
118         // summary: returns a constrained version of dojo.dnd.Mover
119         // description: this function produces n object, which will put a constraint on 
120         //      the margin box of dragged object in absolute coordinates
121         // fun: Function: called on drag, and returns a constraint box
122         // within: Boolean: if true, constraints the whole dragged object withtin the rectangle, 
123         //      otherwise the constraint is applied to the left-top corner
124         dojo.deprecated("dojo.dnd.move.constrainedMover, use dojo.dnd.move.constrainedMoveable instead");
125         var mover = function(node, e, notifier){
126                 dojo.dnd.Mover.call(this, node, e, notifier);
127         };
128         dojo.extend(mover, dojo.dnd.Mover.prototype);
129         dojo.extend(mover, {
130                 onMouseMove: function(e){
131                         // summary: event processor for onmousemove
132                         // e: Event: mouse event
133                         dojo.dnd.autoScroll(e);
134                         var m = this.marginBox, c = this.constraintBox,
135                                 l = m.l + e.pageX, t = m.t + e.pageY;
136                         l = l < c.l ? c.l : c.r < l ? c.r : l;
137                         t = t < c.t ? c.t : c.b < t ? c.b : t;
138                         this.host.onMove(this, {l: l, t: t});
139                 },
140                 onFirstMove: function(){
141                         // summary: called once to initialize things; it is meant to be called only once
142                         dojo.dnd.Mover.prototype.onFirstMove.call(this);
143                         var c = this.constraintBox = fun.call(this);
144                         c.r = c.l + c.w;
145                         c.b = c.t + c.h;
146                         if(within){
147                                 var mb = dojo.marginBox(this.node);
148                                 c.r -= mb.w;
149                                 c.b -= mb.h;
150                         }
151                 }
152         });
153         return mover;   // Object
154 };
155
156 dojo.dnd.move.boxConstrainedMover = function(box, within){
157         // summary: a specialization of dojo.dnd.constrainedMover, which constrains to the specified box
158         // box: Object: a constraint box (l, t, w, h)
159         // within: Boolean: if true, constraints the whole dragged object withtin the rectangle, 
160         //      otherwise the constraint is applied to the left-top corner
161         dojo.deprecated("dojo.dnd.move.boxConstrainedMover, use dojo.dnd.move.boxConstrainedMoveable instead");
162         return dojo.dnd.move.constrainedMover(function(){ return box; }, within);       // Object
163 };
164
165 dojo.dnd.move.parentConstrainedMover = function(area, within){
166         // summary: a specialization of dojo.dnd.constrainedMover, which constrains to the parent node
167         // area: String: "margin" to constrain within the parent's margin box, "border" for the border box,
168         //      "padding" for the padding box, and "content" for the content box; "content" is the default value.
169         // within: Boolean: if true, constraints the whole dragged object withtin the rectangle, 
170         //      otherwise the constraint is applied to the left-top corner
171         dojo.deprecated("dojo.dnd.move.parentConstrainedMover, use dojo.dnd.move.parentConstrainedMoveable instead");
172         var fun = function(){
173                 var n = this.node.parentNode, 
174                         s = dojo.getComputedStyle(n), 
175                         mb = dojo._getMarginBox(n, s);
176                 if(area == "margin"){
177                         return mb;      // Object
178                 }
179                 var t = dojo._getMarginExtents(n, s);
180                 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
181                 if(area == "border"){
182                         return mb;      // Object
183                 }
184                 t = dojo._getBorderExtents(n, s);
185                 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
186                 if(area == "padding"){
187                         return mb;      // Object
188                 }
189                 t = dojo._getPadExtents(n, s);
190                 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
191                 return mb;      // Object
192         };
193         return dojo.dnd.move.constrainedMover(fun, within);     // Object
194 };
195
196 // patching functions one level up for compatibility
197
198 dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover;
199 dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover;
200 dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover;
201
202 }