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
9 ], function(aspect, declare,domClass, event, lang, on, touch){
12 // dijit/tree/_dndContainer
17 // A dict of parameters for Tree source configuration.
19 // Can be used as a DnD source. Defaults to true.
21 // List of accepted types (text strings) for a target; defaults to
22 // ["text", "treeNode"]
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
32 return declare("dijit.tree._dndContainer", null, {
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`.
42 // The currently hovered TreeNode.rowNode (which is the DOM node
43 // associated w/a given node in the tree, excluding it's descendants)
47 constructor: function(tree, params){
49 // A constructor of the Container
51 // Node or node's id to build the container on
53 // A dict of parameters, which gets mixed into the object
57 this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree
58 lang.mixin(this, params);
60 // class-specific variables
61 this.current = null; // current TreeNode's DOM node
64 this.containerState = "";
65 domClass.add(this.node, "dojoDndContainer");
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")),
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),
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"))
85 // Prepares this object to be garbage-collected
88 while(h = this.events.pop()){ h.remove(); }
91 this.node = this.parent = null;
95 onMouseOver: function(widget /*===== , evt =====*/){
97 // Called when mouse is moved over a TreeNode
102 this.current = widget;
105 onMouseOut: function(/*===== widget, evt =====*/){
107 // Called when mouse is moved away from a TreeNode
115 _changeState: function(type, newState){
117 // Changes a named state to new state value
119 // A name of the state to change
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;
129 _addItemClass: function(node, type){
131 // Adds a class with prefix "dojoDndItem"
135 // A variable suffix for a class name
136 domClass.add(node, "dojoDndItem" + type);
139 _removeItemClass: function(node, type){
141 // Removes a class with prefix "dojoDndItem"
145 // A variable suffix for a class name
146 domClass.remove(node, "dojoDndItem" + type);
149 onOverEvent: function(){
151 // This function is called once, when mouse is over our container
154 this._changeState("Container", "Over");
157 onOutEvent: function(){
159 // This function is called once, when mouse is out of our container
162 this._changeState("Container", "");