2150 |
mathias |
1 |
if(!dojo._hasResource["dojo.dnd.Avatar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojo.dnd.Avatar"] = true;
|
|
|
3 |
dojo.provide("dojo.dnd.Avatar");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojo.dnd.common");
|
|
|
6 |
|
|
|
7 |
dojo.dnd.Avatar = function(manager){
|
|
|
8 |
// summary: an object, which represents transferred DnD items visually
|
|
|
9 |
// manager: Object: a DnD manager object
|
|
|
10 |
this.manager = manager;
|
|
|
11 |
this.construct();
|
|
|
12 |
};
|
|
|
13 |
|
|
|
14 |
dojo.extend(dojo.dnd.Avatar, {
|
|
|
15 |
construct: function(){
|
|
|
16 |
// summary: a constructor function;
|
|
|
17 |
// it is separate so it can be (dynamically) overwritten in case of need
|
|
|
18 |
var a = dojo.doc.createElement("table");
|
|
|
19 |
a.className = "dojoDndAvatar";
|
|
|
20 |
a.style.position = "absolute";
|
|
|
21 |
a.style.zIndex = 1999;
|
|
|
22 |
a.style.margin = "0px"; // to avoid dojo.marginBox() problems with table's margins
|
|
|
23 |
var b = dojo.doc.createElement("tbody");
|
|
|
24 |
var tr = dojo.doc.createElement("tr");
|
|
|
25 |
tr.className = "dojoDndAvatarHeader";
|
|
|
26 |
var td = dojo.doc.createElement("td");
|
|
|
27 |
td.innerHTML = this._generateText();
|
|
|
28 |
tr.appendChild(td);
|
|
|
29 |
dojo.style(tr, "opacity", 0.9);
|
|
|
30 |
b.appendChild(tr);
|
|
|
31 |
var k = Math.min(5, this.manager.nodes.length);
|
|
|
32 |
var source = this.manager.source;
|
|
|
33 |
for(var i = 0; i < k; ++i){
|
|
|
34 |
tr = dojo.doc.createElement("tr");
|
|
|
35 |
tr.className = "dojoDndAvatarItem";
|
|
|
36 |
td = dojo.doc.createElement("td");
|
|
|
37 |
var node = source.creator ?
|
|
|
38 |
// create an avatar representation of the node
|
|
|
39 |
node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node :
|
|
|
40 |
// or just clone the node and hope it works
|
|
|
41 |
node = this.manager.nodes[i].cloneNode(true);
|
|
|
42 |
node.id = "";
|
|
|
43 |
td.appendChild(node);
|
|
|
44 |
tr.appendChild(td);
|
|
|
45 |
dojo.style(tr, "opacity", (9 - i) / 10);
|
|
|
46 |
b.appendChild(tr);
|
|
|
47 |
}
|
|
|
48 |
a.appendChild(b);
|
|
|
49 |
this.node = a;
|
|
|
50 |
},
|
|
|
51 |
destroy: function(){
|
|
|
52 |
// summary: a desctructor for the avatar, called to remove all references so it can be garbage-collected
|
|
|
53 |
dojo._destroyElement(this.node);
|
|
|
54 |
this.node = false;
|
|
|
55 |
},
|
|
|
56 |
update: function(){
|
|
|
57 |
// summary: updates the avatar to reflect the current DnD state
|
|
|
58 |
dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop");
|
|
|
59 |
// replace text
|
|
|
60 |
var t = this.node.getElementsByTagName("td");
|
|
|
61 |
for(var i = 0; i < t.length; ++i){
|
|
|
62 |
var n = t[i];
|
|
|
63 |
if(dojo.hasClass(n.parentNode, "dojoDndAvatarHeader")){
|
|
|
64 |
n.innerHTML = this._generateText();
|
|
|
65 |
break;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
},
|
|
|
69 |
_generateText: function(){
|
|
|
70 |
// summary: generates a proper text to reflect copying or moving of items
|
|
|
71 |
return this.manager.nodes.length.toString();
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
}
|