summaryrefslogtreecommitdiff
path: root/includes/js/dojo/dnd/Avatar.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojo/dnd/Avatar.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojo/dnd/Avatar.js')
-rw-r--r--includes/js/dojo/dnd/Avatar.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/includes/js/dojo/dnd/Avatar.js b/includes/js/dojo/dnd/Avatar.js
new file mode 100644
index 0000000..33ccb07
--- /dev/null
+++ b/includes/js/dojo/dnd/Avatar.js
@@ -0,0 +1,82 @@
+if(!dojo._hasResource["dojo.dnd.Avatar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojo.dnd.Avatar"] = true;
+dojo.provide("dojo.dnd.Avatar");
+
+dojo.require("dojo.dnd.common");
+
+dojo.declare("dojo.dnd.Avatar", null, {
+ // summary: an object, which represents transferred DnD items visually
+ // manager: Object: a DnD manager object
+
+ constructor: function(manager){
+ this.manager = manager;
+ this.construct();
+ },
+
+ // methods
+ construct: function(){
+ // summary: a constructor function;
+ // it is separate so it can be (dynamically) overwritten in case of need
+ var a = dojo.doc.createElement("table");
+ a.className = "dojoDndAvatar";
+ a.style.position = "absolute";
+ a.style.zIndex = 1999;
+ a.style.margin = "0px"; // to avoid dojo.marginBox() problems with table's margins
+ var b = dojo.doc.createElement("tbody");
+ var tr = dojo.doc.createElement("tr");
+ tr.className = "dojoDndAvatarHeader";
+ var td = dojo.doc.createElement("td");
+ td.innerHTML = this._generateText();
+ tr.appendChild(td);
+ dojo.style(tr, "opacity", 0.9);
+ b.appendChild(tr);
+ var k = Math.min(5, this.manager.nodes.length);
+ var source = this.manager.source;
+ for(var i = 0; i < k; ++i){
+ tr = dojo.doc.createElement("tr");
+ tr.className = "dojoDndAvatarItem";
+ td = dojo.doc.createElement("td");
+ if(source.creator){
+ // create an avatar representation of the node
+ node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node;
+ }else{
+ // or just clone the node and hope it works
+ node = this.manager.nodes[i].cloneNode(true);
+ if(node.tagName.toLowerCase() == "tr"){
+ // insert extra table nodes
+ var table = dojo.doc.createElement("table"),
+ tbody = dojo.doc.createElement("tbody");
+ tbody.appendChild(node);
+ table.appendChild(tbody);
+ node = table;
+ }
+ }
+ node.id = "";
+ td.appendChild(node);
+ tr.appendChild(td);
+ dojo.style(tr, "opacity", (9 - i) / 10);
+ b.appendChild(tr);
+ }
+ a.appendChild(b);
+ this.node = a;
+ },
+ destroy: function(){
+ // summary: a desctructor for the avatar, called to remove all references so it can be garbage-collected
+ dojo._destroyElement(this.node);
+ this.node = false;
+ },
+ update: function(){
+ // summary: updates the avatar to reflect the current DnD state
+ dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop");
+ // replace text
+ dojo.query("tr.dojoDndAvatarHeader td").forEach(function(node){
+ node.innerHTML = this._generateText();
+ }, this);
+ },
+ _generateText: function(){
+ // summary: generates a proper text to reflect copying or moving of items
+ return this.manager.nodes.length.toString();
+ }
+});
+
+}