source: Dev/branches/rest-dojo-ui/client/dojo/dnd/move.js @ 263

Last change on this file since 263 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 4.1 KB
Line 
1define(["../main", "./Mover", "./Moveable"], function(dojo) {
2        // module:
3        //              dojo/dnd/move
4        // summary:
5        //              TODOC
6
7
8/*=====
9dojo.declare("dojo.dnd.move.__constrainedMoveableArgs", [dojo.dnd.__MoveableArgs], {
10        // constraints: Function
11        //              Calculates a constraint box.
12        //              It is called in a context of the moveable object.
13        constraints: function(){},
14
15        // within: Boolean
16        //              restrict move within boundaries.
17        within: false
18});
19=====*/
20
21dojo.declare("dojo.dnd.move.constrainedMoveable", dojo.dnd.Moveable, {
22        // object attributes (for markup)
23        constraints: function(){},
24        within: false,
25
26        constructor: function(node, params){
27                // summary:
28                //              an object that makes a node moveable
29                // node: Node
30                //              a node (or node's id) to be moved
31                // params: dojo.dnd.move.__constrainedMoveableArgs?
32                //              an optional object with additional parameters;
33                //              the rest is passed to the base class
34                if(!params){ params = {}; }
35                this.constraints = params.constraints;
36                this.within = params.within;
37        },
38        onFirstMove: function(/* dojo.dnd.Mover */ mover){
39                // summary:
40                //              called during the very first move notification;
41                //              can be used to initialize coordinates, can be overwritten.
42                var c = this.constraintBox = this.constraints.call(this, mover);
43                c.r = c.l + c.w;
44                c.b = c.t + c.h;
45                if(this.within){
46                        var mb = dojo._getMarginSize(mover.node);
47                        c.r -= mb.w;
48                        c.b -= mb.h;
49                }
50        },
51        onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
52                // summary:
53                //              called during every move notification;
54                //              should actually move the node; can be overwritten.
55                var c = this.constraintBox, s = mover.node.style;
56                this.onMoving(mover, leftTop);
57                leftTop.l = leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l;
58                leftTop.t = leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t;
59                s.left = leftTop.l + "px";
60                s.top  = leftTop.t + "px";
61                this.onMoved(mover, leftTop);
62        }
63});
64
65/*=====
66dojo.declare("dojo.dnd.move.__boxConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
67        // box: Object
68        //              a constraint box
69        box: {}
70});
71=====*/
72
73dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
74        // box:
75        //              object attributes (for markup)
76        box: {},
77
78        constructor: function(node, params){
79                // summary:
80                //              an object, which makes a node moveable
81                // node: Node
82                //              a node (or node's id) to be moved
83                // params: dojo.dnd.move.__boxConstrainedMoveableArgs?
84                //              an optional object with parameters
85                var box = params && params.box;
86                this.constraints = function(){ return box; };
87        }
88});
89
90/*=====
91dojo.declare("dojo.dnd.move.__parentConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
92        // area: String
93        //              A parent's area to restrict the move.
94        //              Can be "margin", "border", "padding", or "content".
95        area: ""
96});
97=====*/
98
99dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, {
100        // area:
101        //              object attributes (for markup)
102        area: "content",
103
104        constructor: function(node, params){
105                // summary:
106                //              an object, which makes a node moveable
107                // node: Node
108                //              a node (or node's id) to be moved
109                // params: dojo.dnd.move.__parentConstrainedMoveableArgs?
110                //              an optional object with parameters
111                var area = params && params.area;
112                this.constraints = function(){
113                        var n = this.node.parentNode,
114                                s = dojo.getComputedStyle(n),
115                                mb = dojo._getMarginBox(n, s);
116                        if(area == "margin"){
117                                return mb;      // Object
118                        }
119                        var t = dojo._getMarginExtents(n, s);
120                        mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
121                        if(area == "border"){
122                                return mb;      // Object
123                        }
124                        t = dojo._getBorderExtents(n, s);
125                        mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
126                        if(area == "padding"){
127                                return mb;      // Object
128                        }
129                        t = dojo._getPadExtents(n, s);
130                        mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h;
131                        return mb;      // Object
132                };
133        }
134});
135
136// patching functions one level up for compatibility
137
138dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover;
139dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover;
140dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover;
141
142return dojo.dnd.move;
143});
Note: See TracBrowser for help on using the repository browser.