]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/Container.js
add dijit/dojo stuff; initial ui mockup
[tt-rss.git] / lib / dojo / dnd / Container.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.Container"]){
9 dojo._hasResource["dojo.dnd.Container"]=true;
10 dojo.provide("dojo.dnd.Container");
11 dojo.require("dojo.dnd.common");
12 dojo.require("dojo.parser");
13 dojo.declare("dojo.dnd.Container",null,{skipForm:false,constructor:function(_1,_2){
14 this.node=dojo.byId(_1);
15 if(!_2){
16 _2={};
17 }
18 this.creator=_2.creator||null;
19 this.skipForm=_2.skipForm;
20 this.parent=_2.dropParent&&dojo.byId(_2.dropParent);
21 this.map={};
22 this.current=null;
23 this.containerState="";
24 dojo.addClass(this.node,"dojoDndContainer");
25 if(!(_2&&_2._skipStartup)){
26 this.startup();
27 }
28 this.events=[dojo.connect(this.node,"onmouseover",this,"onMouseOver"),dojo.connect(this.node,"onmouseout",this,"onMouseOut"),dojo.connect(this.node,"ondragstart",this,"onSelectStart"),dojo.connect(this.node,"onselectstart",this,"onSelectStart")];
29 },creator:function(){
30 },getItem:function(_3){
31 return this.map[_3];
32 },setItem:function(_4,_5){
33 this.map[_4]=_5;
34 },delItem:function(_6){
35 delete this.map[_6];
36 },forInItems:function(f,o){
37 o=o||dojo.global;
38 var m=this.map,e=dojo.dnd._empty;
39 for(var i in m){
40 if(i in e){
41 continue;
42 }
43 f.call(o,m[i],i,this);
44 }
45 return o;
46 },clearItems:function(){
47 this.map={};
48 },getAllNodes:function(){
49 return dojo.query("> .dojoDndItem",this.parent);
50 },sync:function(){
51 var _7={};
52 this.getAllNodes().forEach(function(_8){
53 if(_8.id){
54 var _9=this.getItem(_8.id);
55 if(_9){
56 _7[_8.id]=_9;
57 return;
58 }
59 }else{
60 _8.id=dojo.dnd.getUniqueId();
61 }
62 var _a=_8.getAttribute("dndType"),_b=_8.getAttribute("dndData");
63 _7[_8.id]={data:_b||_8.innerHTML,type:_a?_a.split(/\s*,\s*/):["text"]};
64 },this);
65 this.map=_7;
66 return this;
67 },insertNodes:function(_c,_d,_e){
68 if(!this.parent.firstChild){
69 _e=null;
70 }else{
71 if(_d){
72 if(!_e){
73 _e=this.parent.firstChild;
74 }
75 }else{
76 if(_e){
77 _e=_e.nextSibling;
78 }
79 }
80 }
81 if(_e){
82 for(var i=0;i<_c.length;++i){
83 var t=this._normalizedCreator(_c[i]);
84 this.setItem(t.node.id,{data:t.data,type:t.type});
85 this.parent.insertBefore(t.node,_e);
86 }
87 }else{
88 for(var i=0;i<_c.length;++i){
89 var t=this._normalizedCreator(_c[i]);
90 this.setItem(t.node.id,{data:t.data,type:t.type});
91 this.parent.appendChild(t.node);
92 }
93 }
94 return this;
95 },destroy:function(){
96 dojo.forEach(this.events,dojo.disconnect);
97 this.clearItems();
98 this.node=this.parent=this.current=null;
99 },markupFactory:function(_f,_10){
100 _f._skipStartup=true;
101 return new dojo.dnd.Container(_10,_f);
102 },startup:function(){
103 if(!this.parent){
104 this.parent=this.node;
105 if(this.parent.tagName.toLowerCase()=="table"){
106 var c=this.parent.getElementsByTagName("tbody");
107 if(c&&c.length){
108 this.parent=c[0];
109 }
110 }
111 }
112 this.defaultCreator=dojo.dnd._defaultCreator(this.parent);
113 this.sync();
114 },onMouseOver:function(e){
115 var n=e.relatedTarget;
116 while(n){
117 if(n==this.node){
118 break;
119 }
120 try{
121 n=n.parentNode;
122 }
123 catch(x){
124 n=null;
125 }
126 }
127 if(!n){
128 this._changeState("Container","Over");
129 this.onOverEvent();
130 }
131 n=this._getChildByEvent(e);
132 if(this.current==n){
133 return;
134 }
135 if(this.current){
136 this._removeItemClass(this.current,"Over");
137 }
138 if(n){
139 this._addItemClass(n,"Over");
140 }
141 this.current=n;
142 },onMouseOut:function(e){
143 for(var n=e.relatedTarget;n;){
144 if(n==this.node){
145 return;
146 }
147 try{
148 n=n.parentNode;
149 }
150 catch(x){
151 n=null;
152 }
153 }
154 if(this.current){
155 this._removeItemClass(this.current,"Over");
156 this.current=null;
157 }
158 this._changeState("Container","");
159 this.onOutEvent();
160 },onSelectStart:function(e){
161 if(!this.skipForm||!dojo.dnd.isFormElement(e)){
162 dojo.stopEvent(e);
163 }
164 },onOverEvent:function(){
165 },onOutEvent:function(){
166 },_changeState:function(_11,_12){
167 var _13="dojoDnd"+_11;
168 var _14=_11.toLowerCase()+"State";
169 dojo.removeClass(this.node,_13+this[_14]);
170 dojo.addClass(this.node,_13+_12);
171 this[_14]=_12;
172 },_addItemClass:function(_15,_16){
173 dojo.addClass(_15,"dojoDndItem"+_16);
174 },_removeItemClass:function(_17,_18){
175 dojo.removeClass(_17,"dojoDndItem"+_18);
176 },_getChildByEvent:function(e){
177 var _19=e.target;
178 if(_19){
179 for(var _1a=_19.parentNode;_1a;_19=_1a,_1a=_19.parentNode){
180 if(_1a==this.parent&&dojo.hasClass(_19,"dojoDndItem")){
181 return _19;
182 }
183 }
184 }
185 return null;
186 },_normalizedCreator:function(_1b,_1c){
187 var t=(this.creator||this.defaultCreator).call(this,_1b,_1c);
188 if(!dojo.isArray(t.type)){
189 t.type=["text"];
190 }
191 if(!t.node.id){
192 t.node.id=dojo.dnd.getUniqueId();
193 }
194 dojo.addClass(t.node,"dojoDndItem");
195 return t;
196 }});
197 dojo.dnd._createNode=function(tag){
198 if(!tag){
199 return dojo.dnd._createSpan;
200 }
201 return function(_1d){
202 return dojo.create(tag,{innerHTML:_1d});
203 };
204 };
205 dojo.dnd._createTrTd=function(_1e){
206 var tr=dojo.create("tr");
207 dojo.create("td",{innerHTML:_1e},tr);
208 return tr;
209 };
210 dojo.dnd._createSpan=function(_1f){
211 return dojo.create("span",{innerHTML:_1f});
212 };
213 dojo.dnd._defaultCreatorNodes={ul:"li",ol:"li",div:"div",p:"div"};
214 dojo.dnd._defaultCreator=function(_20){
215 var tag=_20.tagName.toLowerCase();
216 var c=tag=="tbody"||tag=="thead"?dojo.dnd._createTrTd:dojo.dnd._createNode(dojo.dnd._defaultCreatorNodes[tag]);
217 return function(_21,_22){
218 var _23=_21&&dojo.isObject(_21),_24,_25,n;
219 if(_23&&_21.tagName&&_21.nodeType&&_21.getAttribute){
220 _24=_21.getAttribute("dndData")||_21.innerHTML;
221 _25=_21.getAttribute("dndType");
222 _25=_25?_25.split(/\s*,\s*/):["text"];
223 n=_21;
224 }else{
225 _24=(_23&&_21.data)?_21.data:_21;
226 _25=(_23&&_21.type)?_21.type:["text"];
227 n=(_22=="avatar"?dojo.dnd._createSpan:c)(String(_24));
228 }
229 if(!n.id){
230 n.id=dojo.dnd.getUniqueId();
231 }
232 return {node:n,data:_24,type:_25};
233 };
234 };
235 }