]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_tree/dndContainer.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / _tree / dndContainer.js
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");
6
7 dojo.declare("dijit._tree.dndContainer",
8         null, 
9         {
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
14                         this.tree = tree;
15                         this.node = tree.domNode;       // TODO: rename; it's not a TreeNode but the whole Tree
16                         dojo.mixin(this, params);
17         
18                         // class-specific variables
19                         this.map = {};
20                         this.current = null;    // current TreeNode
21         
22                         // states
23                         this.containerState = "";
24                         dojo.addClass(this.node, "dojoDndContainer");
25                         
26                         // mark up children
27                         if(!(params && params._skipStartup)){
28                                 this.startup();
29                         }
30
31                         // set up events
32                         this.events = [
33                                 dojo.connect(this.node, "onmouseover", this, "onMouseOver"),
34                                 dojo.connect(this.node, "onmouseout",  this, "onMouseOut"),
35
36                                 // cancel text selection and text dragging
37                                 dojo.connect(this.node, "ondragstart",   dojo, "stopEvent"),
38                                 dojo.connect(this.node, "onselectstart", dojo, "stopEvent")
39                         ];
40                 },
41
42
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
49                 },
50
51                 // mouse events
52                 onMouseOver: function(e){
53                         // summary: event processor for onmouseover
54                         // e: Event: mouse event
55
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
58                         while(rt){
59                                 if(rt == this.node){ break; }
60                                 try{
61                                         rt = rt.parentNode;
62                                 }catch(x){
63                                         rt = null;
64                                 }
65                         }
66                         if(!rt){
67                                 this._changeState("Container", "Over");
68                                 this.onOverEvent();
69                         }
70
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"); }
76                         this.current = n;
77                 },
78
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; }
84                                 try{
85                                         n = n.parentNode;
86                                 }catch(x){
87                                         n = null;
88                                 }
89                         }
90                         if(this.current){
91                                 this._removeItemClass(this.current, "Over");
92                                 this.current = null;
93                         }
94                         this._changeState("Container", "");
95                         this.onOutEvent();
96                 },
97
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;
108                 },
109
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
113                         var node = e.target;
114                         if(node){
115                                 for(var parent = node.parentNode; parent; node = parent, parent = node.parentNode){
116                                         if(dojo.hasClass(node, "dijitTreeContent")){ return node; }
117                                 }
118                         }
119                         return null;
120                 },
121
122                 markupFactory: function(tree, params){
123                         params._skipStartup = true;
124                         return new dijit._tree.dndContainer(tree, params);
125                 },
126
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);
132                 },
133
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);
139                 },
140
141                 onOverEvent: function(){
142                         // summary: this function is called once, when mouse is over our container
143                 },
144
145                 onOutEvent: function(){
146                         // summary: this function is called once, when mouse is out of our container
147                 }
148 });
149
150 }