]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/dnd/Avatar.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojo / dnd / Avatar.js
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.declare("dojo.dnd.Avatar", null, {
8         // summary: an object, which represents transferred DnD items visually
9         // manager: Object: a DnD manager object
10
11         constructor: function(manager){
12                 this.manager = manager;
13                 this.construct();
14         },
15
16         // methods
17         construct: function(){
18                 // summary: a constructor function;
19                 //      it is separate so it can be (dynamically) overwritten in case of need
20                 var a = dojo.doc.createElement("table");
21                 a.className = "dojoDndAvatar";
22                 a.style.position = "absolute";
23                 a.style.zIndex = 1999;
24                 a.style.margin = "0px"; // to avoid dojo.marginBox() problems with table's margins
25                 var b = dojo.doc.createElement("tbody");
26                 var tr = dojo.doc.createElement("tr");
27                 tr.className = "dojoDndAvatarHeader";
28                 var td = dojo.doc.createElement("td");
29                 td.innerHTML = this._generateText();
30                 tr.appendChild(td);
31                 dojo.style(tr, "opacity", 0.9);
32                 b.appendChild(tr);
33                 var k = Math.min(5, this.manager.nodes.length);
34                 var source = this.manager.source;
35                 for(var i = 0; i < k; ++i){
36                         tr = dojo.doc.createElement("tr");
37                         tr.className = "dojoDndAvatarItem";
38                         td = dojo.doc.createElement("td");
39                         if(source.creator){
40                                 // create an avatar representation of the node
41                                 node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node;
42                         }else{
43                                 // or just clone the node and hope it works
44                                 node = this.manager.nodes[i].cloneNode(true);
45                                 if(node.tagName.toLowerCase() == "tr"){
46                                         // insert extra table nodes
47                                         var table = dojo.doc.createElement("table"),
48                                                 tbody = dojo.doc.createElement("tbody");
49                                         tbody.appendChild(node);
50                                         table.appendChild(tbody);
51                                         node = table;
52                                 }
53                         }
54                         node.id = "";
55                         td.appendChild(node);
56                         tr.appendChild(td);
57                         dojo.style(tr, "opacity", (9 - i) / 10);
58                         b.appendChild(tr);
59                 }
60                 a.appendChild(b);
61                 this.node = a;
62         },
63         destroy: function(){
64                 // summary: a desctructor for the avatar, called to remove all references so it can be garbage-collected
65                 dojo._destroyElement(this.node);
66                 this.node = false;
67         },
68         update: function(){
69                 // summary: updates the avatar to reflect the current DnD state
70                 dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop");
71                 // replace text
72                 dojo.query("tr.dojoDndAvatarHeader td").forEach(function(node){
73                         node.innerHTML = this._generateText();
74                 }, this);
75         },
76         _generateText: function(){
77                 // summary: generates a proper text to reflect copying or moving of items
78                 return this.manager.nodes.length.toString();
79         }
80 });
81
82 }