]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/dnd/Manager.js
add dijit/dojo stuff; initial ui mockup
[tt-rss.git] / lib / dojo / dnd / Manager.js
CommitLineData
2f01fe57
AD
1/*
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
5*/
6
7
8if(!dojo._hasResource["dojo.dnd.Manager"]){
9dojo._hasResource["dojo.dnd.Manager"]=true;
10dojo.provide("dojo.dnd.Manager");
11dojo.require("dojo.dnd.common");
12dojo.require("dojo.dnd.autoscroll");
13dojo.require("dojo.dnd.Avatar");
14dojo.declare("dojo.dnd.Manager",null,{constructor:function(){
15this.avatar=null;
16this.source=null;
17this.nodes=[];
18this.copy=true;
19this.target=null;
20this.canDropFlag=false;
21this.events=[];
22},OFFSET_X:16,OFFSET_Y:16,overSource:function(_1){
23if(this.avatar){
24this.target=(_1&&_1.targetState!="Disabled")?_1:null;
25this.canDropFlag=Boolean(this.target);
26this.avatar.update();
27}
28dojo.publish("/dnd/source/over",[_1]);
29},outSource:function(_2){
30if(this.avatar){
31if(this.target==_2){
32this.target=null;
33this.canDropFlag=false;
34this.avatar.update();
35dojo.publish("/dnd/source/over",[null]);
36}
37}else{
38dojo.publish("/dnd/source/over",[null]);
39}
40},startDrag:function(_3,_4,_5){
41this.source=_3;
42this.nodes=_4;
43this.copy=Boolean(_5);
44this.avatar=this.makeAvatar();
45dojo.body().appendChild(this.avatar.node);
46dojo.publish("/dnd/start",[_3,_4,this.copy]);
47this.events=[dojo.connect(dojo.doc,"onmousemove",this,"onMouseMove"),dojo.connect(dojo.doc,"onmouseup",this,"onMouseUp"),dojo.connect(dojo.doc,"onkeydown",this,"onKeyDown"),dojo.connect(dojo.doc,"onkeyup",this,"onKeyUp"),dojo.connect(dojo.doc,"ondragstart",dojo.stopEvent),dojo.connect(dojo.body(),"onselectstart",dojo.stopEvent)];
48var c="dojoDnd"+(_5?"Copy":"Move");
49dojo.addClass(dojo.body(),c);
50},canDrop:function(_6){
51var _7=Boolean(this.target&&_6);
52if(this.canDropFlag!=_7){
53this.canDropFlag=_7;
54this.avatar.update();
55}
56},stopDrag:function(){
57dojo.removeClass(dojo.body(),"dojoDndCopy");
58dojo.removeClass(dojo.body(),"dojoDndMove");
59dojo.forEach(this.events,dojo.disconnect);
60this.events=[];
61this.avatar.destroy();
62this.avatar=null;
63this.source=this.target=null;
64this.nodes=[];
65},makeAvatar:function(){
66return new dojo.dnd.Avatar(this);
67},updateAvatar:function(){
68this.avatar.update();
69},onMouseMove:function(e){
70var a=this.avatar;
71if(a){
72dojo.dnd.autoScrollNodes(e);
73var s=a.node.style;
74s.left=(e.pageX+this.OFFSET_X)+"px";
75s.top=(e.pageY+this.OFFSET_Y)+"px";
76var _8=Boolean(this.source.copyState(dojo.isCopyKey(e)));
77if(this.copy!=_8){
78this._setCopyStatus(_8);
79}
80}
81},onMouseUp:function(e){
82if(this.avatar){
83if(this.target&&this.canDropFlag){
84var _9=Boolean(this.source.copyState(dojo.isCopyKey(e))),_a=[this.source,this.nodes,_9,this.target,e];
85dojo.publish("/dnd/drop/before",_a);
86dojo.publish("/dnd/drop",_a);
87}else{
88dojo.publish("/dnd/cancel");
89}
90this.stopDrag();
91}
92},onKeyDown:function(e){
93if(this.avatar){
94switch(e.keyCode){
95case dojo.keys.CTRL:
96var _b=Boolean(this.source.copyState(true));
97if(this.copy!=_b){
98this._setCopyStatus(_b);
99}
100break;
101case dojo.keys.ESCAPE:
102dojo.publish("/dnd/cancel");
103this.stopDrag();
104break;
105}
106}
107},onKeyUp:function(e){
108if(this.avatar&&e.keyCode==dojo.keys.CTRL){
109var _c=Boolean(this.source.copyState(false));
110if(this.copy!=_c){
111this._setCopyStatus(_c);
112}
113}
114},_setCopyStatus:function(_d){
115this.copy=_d;
116this.source._markDndStatus(this.copy);
117this.updateAvatar();
118dojo.removeClass(dojo.body(),"dojoDnd"+(this.copy?"Move":"Copy"));
119dojo.addClass(dojo.body(),"dojoDnd"+(this.copy?"Copy":"Move"));
120}});
121dojo.dnd._manager=null;
122dojo.dnd.manager=function(){
123if(!dojo.dnd._manager){
124dojo.dnd._manager=new dojo.dnd.Manager();
125}
126return dojo.dnd._manager;
127};
128}