]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dnd/Container.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.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
);
18 this.creator
=_2
.creator
||null;
19 this.skipForm
=_2
.skipForm
;
20 this.parent
=_2
.dropParent
&&dojo
.byId(_2
.dropParent
);
23 this.containerState
="";
24 dojo
.addClass(this.node
,"dojoDndContainer");
25 if(!(_2
&&_2
._skipStartup
)){
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")];
30 },getItem:function(_3
){
32 },setItem:function(_4
,_5
){
34 },delItem:function(_6
){
36 },forInItems:function(f
,o
){
38 var m
=this.map
,e
=dojo
.dnd
._empty
;
43 f
.call(o
,m
[i
],i
,this);
46 },clearItems:function(){
48 },getAllNodes:function(){
49 return dojo
.query("> .dojoDndItem",this.parent
);
52 this.getAllNodes().forEach(function(_8
){
54 var _9
=this.getItem(_8
.id
);
60 _8
.id
=dojo
.dnd
.getUniqueId();
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"]};
67 },insertNodes:function(_c
,_d
,_e
){
68 if(!this.parent
.firstChild
){
73 _e
=this.parent
.firstChild
;
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
);
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
);
96 dojo
.forEach(this.events
,dojo
.disconnect
);
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(){
104 this.parent
=this.node
;
105 if(this.parent
.tagName
.toLowerCase()=="table"){
106 var c
=this.parent
.getElementsByTagName("tbody");
112 this.defaultCreator
=dojo
.dnd
._defaultCreator(this.parent
);
114 },onMouseOver:function(e
){
115 var n
=e
.relatedTarget
;
128 this._changeState("Container","Over");
131 n
=this._getChildByEvent(e
);
136 this._removeItemClass(this.current
,"Over");
139 this._addItemClass(n
,"Over");
142 },onMouseOut:function(e
){
143 for(var n
=e
.relatedTarget
;n
;){
155 this._removeItemClass(this.current
,"Over");
158 this._changeState("Container","");
160 },onSelectStart:function(e
){
161 if(!this.skipForm
||!dojo
.dnd
.isFormElement(e
)){
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
);
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
){
179 for(var _1a
=_19
.parentNode
;_1a
;_19
=_1a
,_1a
=_19
.parentNode
){
180 if(_1a
==this.parent
&&dojo
.hasClass(_19
,"dojoDndItem")){
186 },_normalizedCreator:function(_1b
,_1c
){
187 var t
=(this.creator
||this.defaultCreator
).call(this,_1b
,_1c
);
188 if(!dojo
.isArray(t
.type
)){
192 t
.node
.id
=dojo
.dnd
.getUniqueId();
194 dojo
.addClass(t
.node
,"dojoDndItem");
197 dojo
.dnd
._createNode=function(tag
){
199 return dojo
.dnd
._createSpan
;
201 return function(_1d
){
202 return dojo
.create(tag
,{innerHTML
:_1d
});
205 dojo
.dnd
._createTrTd=function(_1e
){
206 var tr
=dojo
.create("tr");
207 dojo
.create("td",{innerHTML
:_1e
},tr
);
210 dojo
.dnd
._createSpan=function(_1f
){
211 return dojo
.create("span",{innerHTML
:_1f
});
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"];
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
));
230 n
.id
=dojo
.dnd
.getUniqueId();
232 return {node
:n
,data
:_24
,type
:_25
};