]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/move.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dojo / dnd / move.js
1 /*
2 Copyright (c) 2004-2011, 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
8 if(!dojo._hasResource["dojo.dnd.move"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo.dnd.move"] = true;
10 dojo.provide("dojo.dnd.move");
11 dojo.require("dojo.dnd.Mover");
12 dojo.require("dojo.dnd.Moveable");
13
14
15 /*=====
16 dojo.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
28 dojo.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._getMarginSize(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 this.onMoving(mover, leftTop);
69 leftTop.l = leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l;
70 leftTop.t = leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t;
71 s.left = leftTop.l + "px";
72 s.top = leftTop.t + "px";
73 this.onMoved(mover, leftTop);
74 }
75 });
76
77 /*=====
78 dojo.declare("dojo.dnd.move.__boxConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
79 // box: Object
80 // a constraint box
81 box: {}
82 });
83 =====*/
84
85 dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
86 // box:
87 // object attributes (for markup)
88 box: {},
89
90 // markup methods
91 markupFactory: function(params, node){
92 return new dojo.dnd.move.boxConstrainedMoveable(node, params);
93 },
94
95 constructor: function(node, params){
96 // summary:
97 // an object, which makes a node moveable
98 // node: Node
99 // a node (or node's id) to be moved
100 // params: dojo.dnd.move.__boxConstrainedMoveableArgs?
101 // an optional object with parameters
102 var box = params && params.box;
103 this.constraints = function(){ return box; };
104 }
105 });
106
107 /*=====
108 dojo.declare("dojo.dnd.move.__parentConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
109 // area: String
110 // A parent's area to restrict the move.
111 // Can be "margin", "border", "padding", or "content".
112 area: ""
113 });
114 =====*/
115
116 dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
117 // area:
118 // object attributes (for markup)
119 area: "content",
120
121 // markup methods
122 markupFactory: function(params, node){
123 return new dojo.dnd.move.parentConstrainedMoveable(node, params);
124 },
125
126 constructor: function(node, params){
127 // summary:
128 // an object, which makes a node moveable
129 // node: Node
130 // a node (or node's id) to be moved
131 // params: dojo.dnd.move.__parentConstrainedMoveableArgs?
132 // an optional object with parameters
133 var area = params && params.area;
134 this.constraints = function(){
135 var n = this.node.parentNode,
136 s = dojo.getComputedStyle(n),
137 mb = dojo._getMarginBox(n, s);
138 if(area == "margin"){
139 return mb; // Object
140 }
141 var t = dojo._getMarginExtents(n, s);
142 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
143 if(area == "border"){
144 return mb; // Object
145 }
146 t = dojo._getBorderExtents(n, s);
147 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
148 if(area == "padding"){
149 return mb; // Object
150 }
151 t = dojo._getPadExtents(n, s);
152 mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
153 return mb; // Object
154 };
155 }
156 });
157
158 // patching functions one level up for compatibility
159
160 dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover;
161 dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover;
162 dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover;
163
164 }