]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/Manager.js
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
8 if(!dojo
._hasResource
["dojo.dnd.Manager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dojo.dnd.Manager"] = true;
10 dojo
.provide("dojo.dnd.Manager");
12 dojo
.require("dojo.dnd.common");
13 dojo
.require("dojo.dnd.autoscroll");
14 dojo
.require("dojo.dnd.Avatar");
16 dojo
.declare("dojo.dnd.Manager", null, {
18 // the manager of DnD operations (usually a singleton)
19 constructor: function(){
25 this.canDropFlag
= false;
29 // avatar's offset from the mouse
34 overSource: function(source
){
36 // called when a source detected a mouse-over condition
40 this.target
= (source
&& source
.targetState
!= "Disabled") ? source
: null;
41 this.canDropFlag
= Boolean(this.target
);
44 dojo
.publish("/dnd/source/over", [source
]);
46 outSource: function(source
){
48 // called when a source detected a mouse-out condition
52 if(this.target
== source
){
54 this.canDropFlag
= false;
56 dojo
.publish("/dnd/source/over", [null]);
59 dojo
.publish("/dnd/source/over", [null]);
62 startDrag: function(source
, nodes
, copy
){
64 // called to initiate the DnD operation
66 // the source which provides items
68 // the list of transferred items
70 // copy items, if true, move items otherwise
73 this.copy
= Boolean(copy
); // normalizing to true boolean
74 this.avatar
= this.makeAvatar();
75 dojo
.body().appendChild(this.avatar
.node
);
76 dojo
.publish("/dnd/start", [source
, nodes
, this.copy
]);
78 dojo
.connect(dojo
.doc
, "onmousemove", this, "onMouseMove"),
79 dojo
.connect(dojo
.doc
, "onmouseup", this, "onMouseUp"),
80 dojo
.connect(dojo
.doc
, "onkeydown", this, "onKeyDown"),
81 dojo
.connect(dojo
.doc
, "onkeyup", this, "onKeyUp"),
82 // cancel text selection and text dragging
83 dojo
.connect(dojo
.doc
, "ondragstart", dojo
.stopEvent
),
84 dojo
.connect(dojo
.body(), "onselectstart", dojo
.stopEvent
)
86 var c
= "dojoDnd" + (copy
? "Copy" : "Move");
87 dojo
.addClass(dojo
.body(), c
);
89 canDrop: function(flag
){
91 // called to notify if the current target can accept items
92 var canDropFlag
= Boolean(this.target
&& flag
);
93 if(this.canDropFlag
!= canDropFlag
){
94 this.canDropFlag
= canDropFlag
;
100 // stop the DnD in progress
101 dojo
.removeClass(dojo
.body(), "dojoDndCopy");
102 dojo
.removeClass(dojo
.body(), "dojoDndMove");
103 dojo
.forEach(this.events
, dojo
.disconnect
);
105 this.avatar
.destroy();
107 this.source
= this.target
= null;
110 makeAvatar: function(){
112 // makes the avatar; it is separate to be overwritten dynamically, if needed
113 return new dojo
.dnd
.Avatar(this);
115 updateAvatar: function(){
117 // updates the avatar; it is separate to be overwritten dynamically, if needed
118 this.avatar
.update();
121 // mouse event processors
122 onMouseMove: function(e
){
124 // event processor for onmousemove
129 dojo
.dnd
.autoScrollNodes(e
);
130 //dojo.dnd.autoScroll(e);
131 var s
= a
.node
.style
;
132 s
.left
= (e
.pageX
+ this.OFFSET_X
) + "px";
133 s
.top
= (e
.pageY
+ this.OFFSET_Y
) + "px";
134 var copy
= Boolean(this.source
.copyState(dojo
.isCopyKey(e
)));
135 if(this.copy
!= copy
){
136 this._setCopyStatus(copy
);
140 onMouseUp: function(e
){
142 // event processor for onmouseup
146 if(this.target
&& this.canDropFlag
){
147 var copy
= Boolean(this.source
.copyState(dojo
.isCopyKey(e
))),
148 params
= [this.source
, this.nodes
, copy
, this.target
, e
];
149 dojo
.publish("/dnd/drop/before", params
);
150 dojo
.publish("/dnd/drop", params
);
152 dojo
.publish("/dnd/cancel");
158 // keyboard event processors
159 onKeyDown: function(e
){
161 // event processor for onkeydown:
162 // watching for CTRL for copy/move status, watching for ESCAPE to cancel the drag
168 var copy
= Boolean(this.source
.copyState(true));
169 if(this.copy
!= copy
){
170 this._setCopyStatus(copy
);
173 case dojo
.keys
.ESCAPE
:
174 dojo
.publish("/dnd/cancel");
180 onKeyUp: function(e
){
182 // event processor for onkeyup, watching for CTRL for copy/move status
185 if(this.avatar
&& e
.keyCode
== dojo
.keys
.CTRL
){
186 var copy
= Boolean(this.source
.copyState(false));
187 if(this.copy
!= copy
){
188 this._setCopyStatus(copy
);
194 _setCopyStatus: function(copy
){
196 // changes the copy status
200 this.source
._markDndStatus(this.copy
);
202 dojo
.removeClass(dojo
.body(), "dojoDnd" + (this.copy
? "Move" : "Copy"));
203 dojo
.addClass(dojo
.body(), "dojoDnd" + (this.copy
? "Copy" : "Move"));
207 // dojo.dnd._manager:
208 // The manager singleton variable. Can be overwritten if needed.
209 dojo
.dnd
._manager
= null;
211 dojo
.dnd
.manager = function(){
213 // Returns the current DnD manager. Creates one if it is not created yet.
214 if(!dojo
.dnd
._manager
){
215 dojo
.dnd
._manager
= new dojo
.dnd
.Manager();
217 return dojo
.dnd
._manager
; // Object