Debian Codegraph @

dijit/tree/_dndContainer.js

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