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