1 if(!dojo._hasResource["dijit._tree.dndContainer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._tree.dndContainer"] = true;
3 dojo.provide("dijit._tree.dndContainer");
4 dojo.require("dojo.dnd.common");
5 dojo.require("dojo.dnd.Container");
7 dojo.declare("dijit._tree.dndContainer",
10 constructor: function(tree, params){
11 // summary: a constructor of the Container
12 // tree: Node: node or node's id to build the container on
13 // params: Object: a dict of parameters, which gets mixed into the object
15 this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree
16 dojo.mixin(this, params);
18 // class-specific variables
20 this.current = null; // current TreeNode
23 this.containerState = "";
24 dojo.addClass(this.node, "dojoDndContainer");
27 if(!(params && params._skipStartup)){
33 dojo.connect(this.node, "onmouseover", this, "onMouseOver"),
34 dojo.connect(this.node, "onmouseout", this, "onMouseOut"),
36 // cancel text selection and text dragging
37 dojo.connect(this.node, "ondragstart", dojo, "stopEvent"),
38 dojo.connect(this.node, "onselectstart", dojo, "stopEvent")
43 // abstract access to the map
44 getItem: function(/*String*/ key){
45 // summary: returns a data item by its key (id)
46 //console.log("Container getItem()", arguments,this.map, this.map[key], this.selection[key]);
47 return this.selection[key];
48 //return this.map[key]; // Object
52 onMouseOver: function(e){
53 // summary: event processor for onmouseover
54 // e: Event: mouse event
56 // handle when mouse has just moved over the Tree itself (not a TreeNode, but the Tree)
57 var rt = e.relatedTarget; // the previous location
59 if(rt == this.node){ break; }
67 this._changeState("Container", "Over");
71 // code below is for handling depending on which TreeNode we are over
72 var n = this._getChildByEvent(e); // the TreeNode
73 if(this.current == n){ return; }
74 if(this.current){ this._removeItemClass(this.current, "Over"); }
75 if(n){ this._addItemClass(n, "Over"); }
79 onMouseOut: function(e){
80 // summary: event processor for onmouseout
81 // e: Event: mouse event
82 for(var n = e.relatedTarget; n;){
83 if(n == this.node){ return; }
91 this._removeItemClass(this.current, "Over");
94 this._changeState("Container", "");
98 _changeState: function(type, newState){
99 // summary: changes a named state to new state value
100 // type: String: a name of the state to change
101 // newState: String: new state
102 var prefix = "dojoDnd" + type;
103 var state = type.toLowerCase() + "State";
104 //dojo.replaceClass(this.node, prefix + newState, prefix + this[state]);
105 dojo.removeClass(this.node, prefix + this[state]);
106 dojo.addClass(this.node, prefix + newState);
107 this[state] = newState;
110 _getChildByEvent: function(e){
111 // summary: gets a child, which is under the mouse at the moment, or null
112 // e: Event: a mouse event
115 for(var parent = node.parentNode; parent; node = parent, parent = node.parentNode){
116 if(dojo.hasClass(node, "dijitTreeContent")){ return node; }
122 markupFactory: function(tree, params){
123 params._skipStartup = true;
124 return new dijit._tree.dndContainer(tree, params);
127 _addItemClass: function(node, type){
128 // summary: adds a class with prefix "dojoDndItem"
129 // node: Node: a node
130 // type: String: a variable suffix for a class name
131 dojo.addClass(node, "dojoDndItem" + type);
134 _removeItemClass: function(node, type){
135 // summary: removes a class with prefix "dojoDndItem"
136 // node: Node: a node
137 // type: String: a variable suffix for a class name
138 dojo.removeClass(node, "dojoDndItem" + type);
141 onOverEvent: function(){
142 // summary: this function is called once, when mouse is over our container
145 onOutEvent: function(){
146 // summary: this function is called once, when mouse is out of our container