]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/dnd/move.js
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
[tt-rss.git] / lib / dojo / dnd / move.js
CommitLineData
2f01fe57
AD
1/*
2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5*/
6
7
a089699c
AD
8if(!dojo._hasResource["dojo.dnd.move"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9dojo._hasResource["dojo.dnd.move"] = true;
2f01fe57 10dojo.provide("dojo.dnd.move");
a089699c 11
2f01fe57
AD
12dojo.require("dojo.dnd.Mover");
13dojo.require("dojo.dnd.Moveable");
a089699c
AD
14
15/*=====
16dojo.declare("dojo.dnd.move.__constrainedMoveableArgs", [dojo.dnd.__MoveableArgs], {
17 // constraints: Function
18 // Calculates a constraint box.
19 // It is called in a context of the moveable object.
20 constraints: function(){},
21
22 // within: Boolean
23 // restrict move within boundaries.
24 within: false
25});
26=====*/
27
28dojo.declare("dojo.dnd.move.constrainedMoveable", dojo.dnd.Moveable, {
29 // object attributes (for markup)
30 constraints: function(){},
31 within: false,
32
33 // markup methods
34 markupFactory: function(params, node){
35 return new dojo.dnd.move.constrainedMoveable(node, params);
36 },
37
38 constructor: function(node, params){
39 // summary:
40 // an object that makes a node moveable
41 // node: Node
42 // a node (or node's id) to be moved
43 // params: dojo.dnd.move.__constrainedMoveableArgs?
44 // an optional object with additional parameters;
45 // the rest is passed to the base class
46 if(!params){ params = {}; }
47 this.constraints = params.constraints;
48 this.within = params.within;
49 },
50 onFirstMove: function(/* dojo.dnd.Mover */ mover){
51 // summary:
52 // called during the very first move notification;
53 // can be used to initialize coordinates, can be overwritten.
54 var c = this.constraintBox = this.constraints.call(this, mover);
55 c.r = c.l + c.w;
56 c.b = c.t + c.h;
57 if(this.within){
58 var mb = dojo.marginBox(mover.node);
59 c.r -= mb.w;
60 c.b -= mb.h;
61 }
62 },
63 onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
64 // summary:
65 // called during every move notification;
66 // should actually move the node; can be overwritten.
67 var c = this.constraintBox, s = mover.node.style;
68 s.left = (leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l) + "px";
69 s.top = (leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t) + "px";
70 }
71});
72
73/*=====
74dojo.declare("dojo.dnd.move.__boxConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
75 // box: Object
76 // a constraint box
77 box: {}
78});
79=====*/
80
81dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
82 // box:
83 // object attributes (for markup)
84 box: {},
85
86 // markup methods
87 markupFactory: function(params, node){
88 return new dojo.dnd.move.boxConstrainedMoveable(node, params);
89 },
90
91 constructor: function(node, params){
92 // summary:
93 // an object, which makes a node moveable
94 // node: Node
95 // a node (or node's id) to be moved
96 // params: dojo.dnd.move.__boxConstrainedMoveableArgs?
97 // an optional object with parameters
98 var box = params && params.box;
99 this.constraints = function(){ return box; };
100 }
101});
102
103/*=====
104dojo.declare("dojo.dnd.move.__parentConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
105 // area: String
106 // A parent's area to restrict the move.
107 // Can be "margin", "border", "padding", or "content".
108 area: ""
109});
110=====*/
111
112dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
113 // area:
114 // object attributes (for markup)
115 area: "content",
116
117 // markup methods
118 markupFactory: function(params, node){
119 return new dojo.dnd.move.parentConstrainedMoveable(node, params);
120 },
121
122 constructor: function(node, params){
123 // summary:
124 // an object, which makes a node moveable
125 // node: Node
126 // a node (or node's id) to be moved
127 // params: dojo.dnd.move.__parentConstrainedMoveableArgs?
128 // an optional object with parameters
129 var area = params && params.area;
130 this.constraints = function(){
131 var n = this.node.parentNode,
132 s = dojo.getComputedStyle(n),
133 mb = dojo._getMarginBox(n, s);
134 if(area == "margin"){
135 return mb; // Object
136 }
137 var t = dojo._getMarginExtents(n, s);
138 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
139 if(area == "border"){
140 return mb; // Object
141 }
142 t = dojo._getBorderExtents(n, s);
143 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
144 if(area == "padding"){
145 return mb; // Object
146 }
147 t = dojo._getPadExtents(n, s);
148 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
149 return mb; // Object
150 };
151 }
152});
153
154// WARNING: below are obsolete objects, instead of custom movers use custom moveables (above)
155
156dojo.dnd.move.constrainedMover = function(fun, within){
157 // summary:
158 // returns a constrained version of dojo.dnd.Mover
159 // description:
160 // this function produces n object, which will put a constraint on
161 // the margin box of dragged object in absolute coordinates
162 // fun: Function
163 // called on drag, and returns a constraint box
164 // within: Boolean
165 // if true, constraints the whole dragged object withtin the rectangle,
166 // otherwise the constraint is applied to the left-top corner
167
168 dojo.deprecated("dojo.dnd.move.constrainedMover, use dojo.dnd.move.constrainedMoveable instead");
169 var mover = function(node, e, notifier){
170 dojo.dnd.Mover.call(this, node, e, notifier);
171 };
172 dojo.extend(mover, dojo.dnd.Mover.prototype);
173 dojo.extend(mover, {
174 onMouseMove: function(e){
175 // summary: event processor for onmousemove
176 // e: Event: mouse event
177 dojo.dnd.autoScroll(e);
178 var m = this.marginBox, c = this.constraintBox,
179 l = m.l + e.pageX, t = m.t + e.pageY;
180 l = l < c.l ? c.l : c.r < l ? c.r : l;
181 t = t < c.t ? c.t : c.b < t ? c.b : t;
182 this.host.onMove(this, {l: l, t: t});
183 },
184 onFirstMove: function(){
185 // summary: called once to initialize things; it is meant to be called only once
186 dojo.dnd.Mover.prototype.onFirstMove.call(this);
187 var c = this.constraintBox = fun.call(this);
188 c.r = c.l + c.w;
189 c.b = c.t + c.h;
190 if(within){
191 var mb = dojo.marginBox(this.node);
192 c.r -= mb.w;
193 c.b -= mb.h;
194 }
195 }
196 });
197 return mover; // Object
2f01fe57 198};
a089699c
AD
199
200dojo.dnd.move.boxConstrainedMover = function(box, within){
201 // summary:
202 // a specialization of dojo.dnd.constrainedMover, which constrains to the specified box
203 // box: Object
204 // a constraint box (l, t, w, h)
205 // within: Boolean
206 // if true, constraints the whole dragged object withtin the rectangle,
207 // otherwise the constraint is applied to the left-top corner
208
209 dojo.deprecated("dojo.dnd.move.boxConstrainedMover, use dojo.dnd.move.boxConstrainedMoveable instead");
210 return dojo.dnd.move.constrainedMover(function(){ return box; }, within); // Object
2f01fe57 211};
a089699c
AD
212
213dojo.dnd.move.parentConstrainedMover = function(area, within){
214 // summary:
215 // a specialization of dojo.dnd.constrainedMover, which constrains to the parent node
216 // area: String
217 // "margin" to constrain within the parent's margin box, "border" for the border box,
218 // "padding" for the padding box, and "content" for the content box; "content" is the default value.
219 // within: Boolean
220 // if true, constraints the whole dragged object within the rectangle,
221 // otherwise the constraint is applied to the left-top corner
222
223 dojo.deprecated("dojo.dnd.move.parentConstrainedMover, use dojo.dnd.move.parentConstrainedMoveable instead");
224 var fun = function(){
225 var n = this.node.parentNode,
226 s = dojo.getComputedStyle(n),
227 mb = dojo._getMarginBox(n, s);
228 if(area == "margin"){
229 return mb; // Object
230 }
231 var t = dojo._getMarginExtents(n, s);
232 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
233 if(area == "border"){
234 return mb; // Object
235 }
236 t = dojo._getBorderExtents(n, s);
237 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
238 if(area == "padding"){
239 return mb; // Object
240 }
241 t = dojo._getPadExtents(n, s);
242 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
243 return mb; // Object
244 };
245 return dojo.dnd.move.constrainedMover(fun, within); // Object
2f01fe57 246};
a089699c
AD
247
248// patching functions one level up for compatibility
249
250dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover;
251dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover;
252dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover;
253
2f01fe57 254}