]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/Manager.js.uncompressed.js
1 define("dojo/dnd/Manager", ["../main", "../Evented", "./common", "./autoscroll", "./Avatar"], function(dojo
, Evented
) {
8 var Manager
= dojo
.declare("dojo.dnd.Manager", [Evented
], {
10 // the manager of DnD operations (usually a singleton)
11 constructor: function(){
17 this.canDropFlag
= false;
21 // avatar's offset from the mouse
26 overSource: function(source
){
28 // called when a source detected a mouse-over condition
32 this.target
= (source
&& source
.targetState
!= "Disabled") ? source
: null;
33 this.canDropFlag
= Boolean(this.target
);
36 dojo
.publish("/dnd/source/over", [source
]);
38 outSource: function(source
){
40 // called when a source detected a mouse-out condition
44 if(this.target
== source
){
46 this.canDropFlag
= false;
48 dojo
.publish("/dnd/source/over", [null]);
51 dojo
.publish("/dnd/source/over", [null]);
54 startDrag: function(source
, nodes
, copy
){
56 // called to initiate the DnD operation
58 // the source which provides items
60 // the list of transferred items
62 // copy items, if true, move items otherwise
65 this.copy
= Boolean(copy
); // normalizing to true boolean
66 this.avatar
= this.makeAvatar();
67 dojo
.body().appendChild(this.avatar
.node
);
68 dojo
.publish("/dnd/start", [source
, nodes
, this.copy
]);
70 dojo
.connect(dojo
.doc
, "onmousemove", this, "onMouseMove"),
71 dojo
.connect(dojo
.doc
, "onmouseup", this, "onMouseUp"),
72 dojo
.connect(dojo
.doc
, "onkeydown", this, "onKeyDown"),
73 dojo
.connect(dojo
.doc
, "onkeyup", this, "onKeyUp"),
74 // cancel text selection and text dragging
75 dojo
.connect(dojo
.doc
, "ondragstart", dojo
.stopEvent
),
76 dojo
.connect(dojo
.body(), "onselectstart", dojo
.stopEvent
)
78 var c
= "dojoDnd" + (copy
? "Copy" : "Move");
79 dojo
.addClass(dojo
.body(), c
);
81 canDrop: function(flag
){
83 // called to notify if the current target can accept items
84 var canDropFlag
= Boolean(this.target
&& flag
);
85 if(this.canDropFlag
!= canDropFlag
){
86 this.canDropFlag
= canDropFlag
;
92 // stop the DnD in progress
93 dojo
.removeClass(dojo
.body(), ["dojoDndCopy", "dojoDndMove"]);
94 dojo
.forEach(this.events
, dojo
.disconnect
);
96 this.avatar
.destroy();
98 this.source
= this.target
= null;
101 makeAvatar: function(){
103 // makes the avatar; it is separate to be overwritten dynamically, if needed
104 return new dojo
.dnd
.Avatar(this);
106 updateAvatar: function(){
108 // updates the avatar; it is separate to be overwritten dynamically, if needed
109 this.avatar
.update();
112 // mouse event processors
113 onMouseMove: function(e
){
115 // event processor for onmousemove
120 dojo
.dnd
.autoScrollNodes(e
);
121 //dojo.dnd.autoScroll(e);
122 var s
= a
.node
.style
;
123 s
.left
= (e
.pageX
+ this.OFFSET_X
) + "px";
124 s
.top
= (e
.pageY
+ this.OFFSET_Y
) + "px";
125 var copy
= Boolean(this.source
.copyState(dojo
.isCopyKey(e
)));
126 if(this.copy
!= copy
){
127 this._setCopyStatus(copy
);
131 onMouseUp: function(e
){
133 // event processor for onmouseup
137 if(this.target
&& this.canDropFlag
){
138 var copy
= Boolean(this.source
.copyState(dojo
.isCopyKey(e
))),
139 params
= [this.source
, this.nodes
, copy
, this.target
, e
];
140 dojo
.publish("/dnd/drop/before", params
);
141 dojo
.publish("/dnd/drop", params
);
143 dojo
.publish("/dnd/cancel");
149 // keyboard event processors
150 onKeyDown: function(e
){
152 // event processor for onkeydown:
153 // watching for CTRL for copy/move status, watching for ESCAPE to cancel the drag
159 var copy
= Boolean(this.source
.copyState(true));
160 if(this.copy
!= copy
){
161 this._setCopyStatus(copy
);
164 case dojo
.keys
.ESCAPE
:
165 dojo
.publish("/dnd/cancel");
171 onKeyUp: function(e
){
173 // event processor for onkeyup, watching for CTRL for copy/move status
176 if(this.avatar
&& e
.keyCode
== dojo
.keys
.CTRL
){
177 var copy
= Boolean(this.source
.copyState(false));
178 if(this.copy
!= copy
){
179 this._setCopyStatus(copy
);
185 _setCopyStatus: function(copy
){
187 // changes the copy status
191 this.source
._markDndStatus(this.copy
);
193 dojo
.replaceClass(dojo
.body(),
194 "dojoDnd" + (this.copy
? "Copy" : "Move"),
195 "dojoDnd" + (this.copy
? "Move" : "Copy"));
199 // dojo.dnd._manager:
200 // The manager singleton variable. Can be overwritten if needed.
201 dojo
.dnd
._manager
= null;
203 Manager
.manager
= dojo
.dnd
.manager = function(){
205 // Returns the current DnD manager. Creates one if it is not created yet.
206 if(!dojo
.dnd
._manager
){
207 dojo
.dnd
._manager
= new dojo
.dnd
.Manager();
209 return dojo
.dnd
._manager
; // Object