]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/move.js
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
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");
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(){},
23 // restrict move within boundaries.
28 dojo
.declare("dojo.dnd.move.constrainedMoveable", dojo
.dnd
.Moveable
, {
29 // object attributes (for markup)
30 constraints: function(){},
34 markupFactory: function(params
, node
){
35 return new dojo
.dnd
.move.constrainedMoveable(node
, params
);
38 constructor: function(node
, params
){
40 // an object that makes a node moveable
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
;
50 onFirstMove: function(/* dojo.dnd.Mover */ mover
){
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
);
58 var mb
= dojo
._getMarginSize(mover
.node
);
63 onMove: function(/* dojo.dnd.Mover */ mover
, /* Object */ leftTop
){
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
);
78 dojo.declare("dojo.dnd.move.__boxConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
85 dojo
.declare("dojo.dnd.move.boxConstrainedMoveable", dojo
.dnd
.move.constrainedMoveable
, {
87 // object attributes (for markup)
91 markupFactory: function(params
, node
){
92 return new dojo
.dnd
.move.boxConstrainedMoveable(node
, params
);
95 constructor: function(node
, params
){
97 // an object, which makes a node moveable
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
; };
108 dojo.declare("dojo.dnd.move.__parentConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], {
110 // A parent's area to restrict the move.
111 // Can be "margin", "border", "padding", or "content".
116 dojo
.declare("dojo.dnd.move.parentConstrainedMoveable", dojo
.dnd
.move.constrainedMoveable
, {
118 // object attributes (for markup)
122 markupFactory: function(params
, node
){
123 return new dojo
.dnd
.move.parentConstrainedMoveable(node
, params
);
126 constructor: function(node
, params
){
128 // an object, which makes a node moveable
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"){
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"){
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"){
151 t
= dojo
._getPadExtents(n
, s
);
152 mb
.l
+= t
.l
, mb
.t
+= t
.t
, mb
.w
-= t
.w
, mb
.h
-= t
.h
;
158 // patching functions one level up for compatibility
160 dojo
.dnd
.constrainedMover
= dojo
.dnd
.move.constrainedMover
;
161 dojo
.dnd
.boxConstrainedMover
= dojo
.dnd
.move.boxConstrainedMover
;
162 dojo
.dnd
.parentConstrainedMover
= dojo
.dnd
.move.parentConstrainedMover
;