source: Dev/branches/rest-dojo-ui/client/dijit/tree/_dndContainer.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 4.1 KB
Line 
1define([
2        "dojo/aspect",  // aspect.after
3        "dojo/_base/declare", // declare
4        "dojo/dom-class", // domClass.add domClass.remove domClass.replace
5        "dojo/_base/event",     // event.stop
6        "dojo/_base/lang", // lang.getObject lang.mixin lang.hitch
7        "dojo/mouse",   // mouse.enter, mouse.leave
8        "dojo/on"
9], function(aspect, declare, domClass, event, lang, mouse, on){
10
11        // module:
12        //              dijit/tree/_dndContainer
13        // summary:
14        //              This is a base class for `dijit.tree._dndSelector`, and isn't meant to be used directly.
15        //              It's modeled after `dojo.dnd.Container`.
16
17        return declare("dijit.tree._dndContainer", null, {
18
19                // summary:
20                //              This is a base class for `dijit.tree._dndSelector`, and isn't meant to be used directly.
21                //              It's modeled after `dojo.dnd.Container`.
22                // tags:
23                //              protected
24
25                /*=====
26                // current: DomNode
27                //              The currently hovered TreeNode.rowNode (which is the DOM node
28                //              associated w/a given node in the tree, excluding it's descendants)
29                current: null,
30                =====*/
31
32                constructor: function(tree, params){
33                        // summary:
34                        //              A constructor of the Container
35                        // tree: Node
36                        //              Node or node's id to build the container on
37                        // params: dijit.tree.__SourceArgs
38                        //              A dict of parameters, which gets mixed into the object
39                        // tags:
40                        //              private
41                        this.tree = tree;
42                        this.node = tree.domNode;       // TODO: rename; it's not a TreeNode but the whole Tree
43                        lang.mixin(this, params);
44
45                        // class-specific variables
46                        this.current = null;    // current TreeNode's DOM node
47
48                        // states
49                        this.containerState = "";
50                        domClass.add(this.node, "dojoDndContainer");
51
52                        // set up events
53                        this.events = [
54                                // container level events
55                                on(this.node, mouse.enter, lang.hitch(this, "onOverEvent")),
56                                on(this.node, mouse.leave,      lang.hitch(this, "onOutEvent")),
57
58                                // switching between TreeNodes
59                                aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true),
60                                aspect.after(this.tree, "_onNodeMouseLeave", lang.hitch(this, "onMouseOut"), true),
61
62                                // cancel text selection and text dragging
63                                on(this.node, "dragstart", lang.hitch(event, "stop")),
64                                on(this.node, "selectstart", lang.hitch(event, "stop"))
65                        ];
66                },
67
68                destroy: function(){
69                        // summary:
70                        //              Prepares this object to be garbage-collected
71
72                        var h;
73                        while(h = this.events.pop()){ h.remove(); }
74
75                        // this.clearItems();
76                        this.node = this.parent = null;
77                },
78
79                // mouse events
80                onMouseOver: function(widget /*===== , evt =====*/){
81                        // summary:
82                        //              Called when mouse is moved over a TreeNode
83                        // widget: TreeNode
84                        // evt: Event
85                        // tags:
86                        //              protected
87                        this.current = widget;
88                },
89
90                onMouseOut: function(/*===== widget, evt =====*/){
91                        // summary:
92                        //              Called when mouse is moved away from a TreeNode
93                        // widget: TreeNode
94                        // evt: Event
95                        // tags:
96                        //              protected
97                        this.current = null;
98                },
99
100                _changeState: function(type, newState){
101                        // summary:
102                        //              Changes a named state to new state value
103                        // type: String
104                        //              A name of the state to change
105                        // newState: String
106                        //              new state
107                        var prefix = "dojoDnd" + type;
108                        var state = type.toLowerCase() + "State";
109                        //domClass.replace(this.node, prefix + newState, prefix + this[state]);
110                        domClass.replace(this.node, prefix + newState, prefix + this[state]);
111                        this[state] = newState;
112                },
113
114                _addItemClass: function(node, type){
115                        // summary:
116                        //              Adds a class with prefix "dojoDndItem"
117                        // node: Node
118                        //              A node
119                        // type: String
120                        //              A variable suffix for a class name
121                        domClass.add(node, "dojoDndItem" + type);
122                },
123
124                _removeItemClass: function(node, type){
125                        // summary:
126                        //              Removes a class with prefix "dojoDndItem"
127                        // node: Node
128                        //              A node
129                        // type: String
130                        //              A variable suffix for a class name
131                        domClass.remove(node, "dojoDndItem" + type);
132                },
133
134                onOverEvent: function(){
135                        // summary:
136                        //              This function is called once, when mouse is over our container
137                        // tags:
138                        //              protected
139                        this._changeState("Container", "Over");
140                },
141
142                onOutEvent: function(){
143                        // summary:
144                        //              This function is called once, when mouse is out of our container
145                        // tags:
146                        //              protected
147                        this._changeState("Container", "");
148                }
149        });
150});
Note: See TracBrowser for help on using the repository browser.