yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
define([
    "../_base/declare",
    "../_base/window",
    "../dom",
    "../dom-attr",
    "../dom-class",
    "../dom-construct",
    "../hccss",
    "../query"
], function(declare, win, dom, domAttr, domClass, domConstruct, has, query){
 
// module:
//      dojo/dnd/Avatar
 
return declare("dojo.dnd.Avatar", null, {
    // summary:
    //      Object that represents transferred DnD items visually
    // manager: Object
    //      a DnD manager object
 
    constructor: function(manager){
        this.manager = manager;
        this.construct();
    },
 
    // methods
    construct: function(){
        // summary:
        //      constructor function;
        //      it is separate so it can be (dynamically) overwritten in case of need
 
        var a = domConstruct.create("table", {
                "class": "dojoDndAvatar",
                style: {
                    position: "absolute",
                    zIndex:   "1999",
                    margin:   "0px"
                }
            }),
            source = this.manager.source, node,
            b = domConstruct.create("tbody", null, a),
            tr = domConstruct.create("tr", null, b),
            td = domConstruct.create("td", null, tr),
            k = Math.min(5, this.manager.nodes.length), i = 0;
 
        if(has("highcontrast")){
            domConstruct.create("span", {
                id : "a11yIcon",
                innerHTML : this.manager.copy ? '+' : "<"
            }, td)
        }
        domConstruct.create("span", {
            innerHTML: source.generateText ? this._generateText() : ""
        }, td);
 
        // we have to set the opacity on IE only after the node is live
        domAttr.set(tr, {
            "class": "dojoDndAvatarHeader",
            style: {opacity: 0.9}
        });
        for(; i < k; ++i){
            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 = domConstruct.create("table"),
                        tbody = domConstruct.create("tbody", null, table);
                    tbody.appendChild(node);
                    node = table;
                }
            }
            node.id = "";
            tr = domConstruct.create("tr", null, b);
            td = domConstruct.create("td", null, tr);
            td.appendChild(node);
            domAttr.set(tr, {
                "class": "dojoDndAvatarItem",
                style: {opacity: (9 - i) / 10}
            });
        }
        this.node = a;
    },
    destroy: function(){
        // summary:
        //      destructor for the avatar; called to remove all references so it can be garbage-collected
        domConstruct.destroy(this.node);
        this.node = false;
    },
    update: function(){
        // summary:
        //      updates the avatar to reflect the current DnD state
        domClass.toggle(this.node, "dojoDndAvatarCanDrop", this.manager.canDropFlag);
        if(has("highcontrast")){
            var icon = dom.byId("a11yIcon");
            var text = '+';   // assume canDrop && copy
            if (this.manager.canDropFlag && !this.manager.copy){
                text = '< '; // canDrop && move
            }else if (!this.manager.canDropFlag && !this.manager.copy){
                text = "o"; //!canDrop && move
            }else if(!this.manager.canDropFlag){
                text = 'x';  // !canDrop && copy
            }
            icon.innerHTML=text;
        }
        // replace text
        query(("tr.dojoDndAvatarHeader td span" +(has("highcontrast") ? " span" : "")), this.node).forEach(
            function(node){
                node.innerHTML = this.manager.source.generateText ? this._generateText() : "";
            }, this);
    },
    _generateText: function(){
        // summary:
        //      generates a proper text to reflect copying or moving of items
        return this.manager.nodes.length.toString();
    }
});
 
});