]>
Commit | Line | Data |
---|---|---|
2f01fe57 | 1 | /* |
81bea17a | 2 | Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. |
2f01fe57 AD |
3 | Available via Academic Free License >= 2.1 OR the modified BSD license. |
4 | see: http://dojotoolkit.org/license for details | |
5 | */ | |
6 | ||
7 | ||
a089699c AD |
8 | if(!dojo._hasResource["dojo.dnd.Avatar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
9 | dojo._hasResource["dojo.dnd.Avatar"] = true; | |
2f01fe57 AD |
10 | dojo.provide("dojo.dnd.Avatar"); |
11 | dojo.require("dojo.dnd.common"); | |
a089699c | 12 | |
81bea17a | 13 | |
a089699c AD |
14 | dojo.declare("dojo.dnd.Avatar", null, { |
15 | // summary: | |
16 | // Object that represents transferred DnD items visually | |
17 | // manager: Object | |
18 | // a DnD manager object | |
19 | ||
20 | constructor: function(manager){ | |
21 | this.manager = manager; | |
22 | this.construct(); | |
23 | }, | |
24 | ||
25 | // methods | |
26 | construct: function(){ | |
27 | // summary: | |
28 | // constructor function; | |
29 | // it is separate so it can be (dynamically) overwritten in case of need | |
30 | this.isA11y = dojo.hasClass(dojo.body(),"dijit_a11y"); | |
31 | var a = dojo.create("table", { | |
32 | "class": "dojoDndAvatar", | |
33 | style: { | |
34 | position: "absolute", | |
35 | zIndex: "1999", | |
36 | margin: "0px" | |
37 | } | |
38 | }), | |
39 | source = this.manager.source, node, | |
40 | b = dojo.create("tbody", null, a), | |
41 | tr = dojo.create("tr", null, b), | |
42 | td = dojo.create("td", null, tr), | |
43 | icon = this.isA11y ? dojo.create("span", { | |
44 | id : "a11yIcon", | |
45 | innerHTML : this.manager.copy ? '+' : "<" | |
46 | }, td) : null, | |
47 | span = dojo.create("span", { | |
48 | innerHTML: source.generateText ? this._generateText() : "" | |
49 | }, td), | |
50 | k = Math.min(5, this.manager.nodes.length), i = 0; | |
51 | // we have to set the opacity on IE only after the node is live | |
52 | dojo.attr(tr, { | |
53 | "class": "dojoDndAvatarHeader", | |
54 | style: {opacity: 0.9} | |
55 | }); | |
56 | for(; i < k; ++i){ | |
57 | if(source.creator){ | |
58 | // create an avatar representation of the node | |
59 | node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node; | |
60 | }else{ | |
61 | // or just clone the node and hope it works | |
62 | node = this.manager.nodes[i].cloneNode(true); | |
63 | if(node.tagName.toLowerCase() == "tr"){ | |
64 | // insert extra table nodes | |
65 | var table = dojo.create("table"), | |
66 | tbody = dojo.create("tbody", null, table); | |
67 | tbody.appendChild(node); | |
68 | node = table; | |
69 | } | |
70 | } | |
71 | node.id = ""; | |
72 | tr = dojo.create("tr", null, b); | |
73 | td = dojo.create("td", null, tr); | |
74 | td.appendChild(node); | |
75 | dojo.attr(tr, { | |
76 | "class": "dojoDndAvatarItem", | |
77 | style: {opacity: (9 - i) / 10} | |
78 | }); | |
79 | } | |
80 | this.node = a; | |
81 | }, | |
82 | destroy: function(){ | |
83 | // summary: | |
84 | // destructor for the avatar; called to remove all references so it can be garbage-collected | |
85 | dojo.destroy(this.node); | |
86 | this.node = false; | |
87 | }, | |
88 | update: function(){ | |
89 | // summary: | |
90 | // updates the avatar to reflect the current DnD state | |
91 | dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop"); | |
92 | if (this.isA11y){ | |
93 | var icon = dojo.byId("a11yIcon"); | |
94 | var text = '+'; // assume canDrop && copy | |
95 | if (this.manager.canDropFlag && !this.manager.copy) { | |
81bea17a | 96 | text = '< '; // canDrop && move |
a089699c AD |
97 | }else if (!this.manager.canDropFlag && !this.manager.copy) { |
98 | text = "o"; //!canDrop && move | |
99 | }else if(!this.manager.canDropFlag){ | |
100 | text = 'x'; // !canDrop && copy | |
101 | } | |
102 | icon.innerHTML=text; | |
103 | } | |
104 | // replace text | |
105 | dojo.query(("tr.dojoDndAvatarHeader td span" +(this.isA11y ? " span" : "")), this.node).forEach( | |
106 | function(node){ | |
107 | node.innerHTML = this._generateText(); | |
108 | }, this); | |
109 | }, | |
110 | _generateText: function(){ | |
111 | // summary: generates a proper text to reflect copying or moving of items | |
112 | return this.manager.nodes.length.toString(); | |
113 | } | |
114 | }); | |
115 | ||
2f01fe57 | 116 | } |