]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | define("dijit/tree/_dndContainer", [ |
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.mixin lang.hitch | |
7 | "dojo/on", | |
8 | "dojo/touch" | |
9 | ], function(aspect, declare,domClass, event, lang, on, touch){ | |
10 | ||
11 | // module: | |
12 | // dijit/tree/_dndContainer | |
13 | ||
14 | /*===== | |
15 | var __Args = { | |
16 | // summary: | |
17 | // A dict of parameters for Tree source configuration. | |
18 | // isSource: Boolean? | |
19 | // Can be used as a DnD source. Defaults to true. | |
20 | // accept: String[] | |
21 | // List of accepted types (text strings) for a target; defaults to | |
22 | // ["text", "treeNode"] | |
23 | // copyOnly: Boolean? | |
24 | // Copy items, if true, use a state of Ctrl key otherwise, | |
25 | // dragThreshold: Number | |
26 | // The move delay in pixels before detecting a drag; 0 by default | |
27 | // betweenThreshold: Integer | |
28 | // Distance from upper/lower edge of node to allow drop to reorder nodes | |
29 | }; | |
30 | =====*/ | |
31 | ||
32 | return declare("dijit.tree._dndContainer", null, { | |
33 | ||
34 | // summary: | |
35 | // This is a base class for `dijit/tree/_dndSelector`, and isn't meant to be used directly. | |
36 | // It's modeled after `dojo/dnd/Container`. | |
37 | // tags: | |
38 | // protected | |
39 | ||
40 | /*===== | |
41 | // current: DomNode | |
42 | // The currently hovered TreeNode.rowNode (which is the DOM node | |
43 | // associated w/a given node in the tree, excluding it's descendants) | |
44 | current: null, | |
45 | =====*/ | |
46 | ||
47 | constructor: function(tree, params){ | |
48 | // summary: | |
49 | // A constructor of the Container | |
50 | // tree: Node | |
51 | // Node or node's id to build the container on | |
52 | // params: __Args | |
53 | // A dict of parameters, which gets mixed into the object | |
54 | // tags: | |
55 | // private | |
56 | this.tree = tree; | |
57 | this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree | |
58 | lang.mixin(this, params); | |
59 | ||
60 | // class-specific variables | |
61 | this.current = null; // current TreeNode's DOM node | |
62 | ||
63 | // states | |
64 | this.containerState = ""; | |
65 | domClass.add(this.node, "dojoDndContainer"); | |
66 | ||
67 | // set up events | |
68 | this.events = [ | |
69 | // Mouse (or touch) enter/leave on Tree itself | |
70 | on(this.node, touch.enter, lang.hitch(this, "onOverEvent")), | |
71 | on(this.node, touch.leave, lang.hitch(this, "onOutEvent")), | |
72 | ||
73 | // switching between TreeNodes | |
74 | aspect.after(this.tree, "_onNodeMouseEnter", lang.hitch(this, "onMouseOver"), true), | |
75 | aspect.after(this.tree, "_onNodeMouseLeave", lang.hitch(this, "onMouseOut"), true), | |
76 | ||
77 | // cancel text selection and text dragging | |
78 | on(this.node, "dragstart", lang.hitch(event, "stop")), | |
79 | on(this.node, "selectstart", lang.hitch(event, "stop")) | |
80 | ]; | |
81 | }, | |
82 | ||
83 | destroy: function(){ | |
84 | // summary: | |
85 | // Prepares this object to be garbage-collected | |
86 | ||
87 | var h; | |
88 | while(h = this.events.pop()){ h.remove(); } | |
89 | ||
90 | // this.clearItems(); | |
91 | this.node = this.parent = null; | |
92 | }, | |
93 | ||
94 | // mouse events | |
95 | onMouseOver: function(widget /*===== , evt =====*/){ | |
96 | // summary: | |
97 | // Called when mouse is moved over a TreeNode | |
98 | // widget: TreeNode | |
99 | // evt: Event | |
100 | // tags: | |
101 | // protected | |
102 | this.current = widget; | |
103 | }, | |
104 | ||
105 | onMouseOut: function(/*===== widget, evt =====*/){ | |
106 | // summary: | |
107 | // Called when mouse is moved away from a TreeNode | |
108 | // widget: TreeNode | |
109 | // evt: Event | |
110 | // tags: | |
111 | // protected | |
112 | this.current = null; | |
113 | }, | |
114 | ||
115 | _changeState: function(type, newState){ | |
116 | // summary: | |
117 | // Changes a named state to new state value | |
118 | // type: String | |
119 | // A name of the state to change | |
120 | // newState: String | |
121 | // new state | |
122 | var prefix = "dojoDnd" + type; | |
123 | var state = type.toLowerCase() + "State"; | |
124 | //domClass.replace(this.node, prefix + newState, prefix + this[state]); | |
125 | domClass.replace(this.node, prefix + newState, prefix + this[state]); | |
126 | this[state] = newState; | |
127 | }, | |
128 | ||
129 | _addItemClass: function(node, type){ | |
130 | // summary: | |
131 | // Adds a class with prefix "dojoDndItem" | |
132 | // node: Node | |
133 | // A node | |
134 | // type: String | |
135 | // A variable suffix for a class name | |
136 | domClass.add(node, "dojoDndItem" + type); | |
137 | }, | |
138 | ||
139 | _removeItemClass: function(node, type){ | |
140 | // summary: | |
141 | // Removes a class with prefix "dojoDndItem" | |
142 | // node: Node | |
143 | // A node | |
144 | // type: String | |
145 | // A variable suffix for a class name | |
146 | domClass.remove(node, "dojoDndItem" + type); | |
147 | }, | |
148 | ||
149 | onOverEvent: function(){ | |
150 | // summary: | |
151 | // This function is called once, when mouse is over our container | |
152 | // tags: | |
153 | // protected | |
154 | this._changeState("Container", "Over"); | |
155 | }, | |
156 | ||
157 | onOutEvent: function(){ | |
158 | // summary: | |
159 | // This function is called once, when mouse is out of our container | |
160 | // tags: | |
161 | // protected | |
162 | this._changeState("Container", ""); | |
163 | } | |
164 | }); | |
165 | }); |