Project

General

Profile

1
<!DOCTYPE html
2
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
<head>
6
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
	<title>jsTree v.1.0 - dnd documentation</title>
8
	<script type="text/javascript" src="../_lib/jquery.js"></script>
9
	<script type="text/javascript" src="../_lib/jquery.cookie.js"></script>
10
	<script type="text/javascript" src="../_lib/jquery.hotkeys.js"></script>
11
	<script type="text/javascript" src="../jquery.jstree.js"></script>
12

    
13
	<link type="text/css" rel="stylesheet" href="syntax/!style.css"/>
14
	<link type="text/css" rel="stylesheet" href="!style.css"/>
15
	<script type="text/javascript" src="syntax/!script.js"></script>
16
</head>
17
<body>
18
<div id="container">
19

    
20
<h1>jsTree v.1.0 - drag'n'drop plugin</h1>
21
<h2>Description</h2>
22
<div id="description">
23
<p>The <code>dnd</code> plugin enables drag'n'drop support for jstree, also using foreign nodes and drop targets.</p>
24
</div>
25

    
26
<h2 id="configuration">Configuration</h2>
27
<div class="panel configuration">
28

    
29
<h3>copy_modifier</h3>
30
<p class="meta">A string. Default is <code>"ctrl"</code>.</p>
31
<p>The special key used to make a drag copy instead of move (<code>"ctrl"</code>, <code>"shift"</code>, <code>"alt"</code>, <code>"meta"</code>).</p>
32

    
33
<h3>check_timeout</h3>
34
<p class="meta">A number. Default is <code>200</code>.</p>
35
<p>The number of milliseconds to wait before checking if a move is valid upon hovering a node (while dragging). <code>200</code> is a reasonable value - a higher number means better performance but slow feedback to the user, a lower number means lower performance (possibly) but the user will get feedback faster.</p>
36

    
37
<h3>open_timeout</h3>
38
<p class="meta">A number. Default is <code>500</code>.</p>
39
<p>The number of milliseconds to wait before opening a hovered if it has children (while dragging). This means that the user has to stop over the node for half a second in order to trigger the open operation. Keep in mind that a low value in combination with async data could mean a lot of unneeded traffic, so <code>500</code> is quite reasonable.</p>
40

    
41
<h3>drop_target</h3>
42
<p class="meta">A string (jQuery selector) (or <code>false</code>). Default is <code>".jstree-drop"</code>.</p>
43
<p>A jquery selector matching all drop targets (you can also use the comma <code>,</code> in the string to specify multiple valid targets). If set to <code>false</code> drop targets are disabled.</p>
44

    
45
<h3>drop_check</h3>
46
<p class="meta">A function. Default is <code>function (data) { return true; }</code>.</p>
47
<p>Return <code>false</code> to mark the move as invalid, otherwise return <code>true</code>. The <code>data</code> parameter is as follows:</p>
48
<p style="margin-left:2em;"><code>data.o</code> - the object being dragged</p>
49
<p style="margin-left:2em;"><code>data.r</code> - the drop target</p>
50

    
51
<h3>drop_finish</h3>
52
<p class="meta">A function. Default is <code>$.noop</code>.</p>
53
<p>Gets executed after a valid drop, you get one parameter, which is as follows:</p>
54
<p style="margin-left:2em;"><code>data.o</code> - the object being dragged</p>
55
<p style="margin-left:2em;"><code>data.r</code> - the drop target</p>
56

    
57
<h3>drag_target</h3>
58
<p class="meta">A string (jQuery selector) (or <code>false</code>). Default is <code>".jstree-draggable"</code>.</p>
59
<p>A jquery selector matching all foreign nodes that can be dropped on the tree (you can also use the comma <code>,</code> in the string to specify multiple valid foreign nodes). If set to <code>false</code> dragging foreign nodes is disabled.</p>
60

    
61
<h3>drag_check</h3>
62
<p class="meta">A function. Default is <code>function (data) { return { after : false, before : false, inside : true }; }</code>.</p>
63
<p>Return a boolean for each position. The <code>data</code> parameter is as follows:</p>
64
<p style="margin-left:2em;"><code>data.o</code> - the foreign object being dragged</p>
65
<p style="margin-left:2em;"><code>data.r</code> - the hovered node</p>
66

    
67
<h3>drag_finish</h3>
68
<p class="meta">A function. Default is <code>$.noop</code>.</p>
69
<p>Gets executed after a dropping a foreign element on a tree item, you get one parameter, which is as follows:</p>
70
<p style="margin-left:2em;"><code>data.o</code> - the foreign object being dragged</p>
71
<p style="margin-left:2em;"><code>data.r</code> - the target node</p>
72

    
73

    
74
</div>
75

    
76
<h2 id="demos">Demos</h2>
77
<div class="panel">
78
<h3>Using the dnd plugin</h3>
79
<p>Drag stuff around!</p>
80
<div class="jstree-drop" style="clear:both; border:5px solid green; background:lime; color:green; height:40px; line-height:40px; text-align:center; font-size:20px;">I have the jstree-drop class</div>
81
<div class="jstree-draggable" style="margin:10px 0; clear:both; border:5px solid navy; background:aqua; color:navy; height:40px; line-height:40px; text-align:center; font-size:20px;">I have the jstree-draggable class</div>
82
<div id="demo1" class="demo">
83
	<ul>
84
		<li id="phtml_1">
85
			<a href="#">Root node 1</a>
86
			<ul>
87
				<li id="phtml_2">
88
					<a href="#">Child node 1</a>
89
				</li>
90
				<li id="phtml_3">
91
					<a href="#">Child node 2</a>
92
				</li>
93
			</ul>
94
		</li>
95
		<li id="phtml_4">
96
			<a href="#">Root node 2</a>
97
		</li>
98
	</ul>
99
</div>
100
<script type="text/javascript" class="source">
101
$(function () {
102
	$("#demo1").jstree({ 
103
		"dnd" : {
104
			"drop_finish" : function () { 
105
				alert("DROP"); 
106
			},
107
			"drag_check" : function (data) {
108
				if(data.r.attr("id") == "phtml_1") {
109
					return false;
110
				}
111
				return { 
112
					after : false, 
113
					before : false, 
114
					inside : true 
115
				};
116
			},
117
			"drag_finish" : function () { 
118
				alert("DRAG OK"); 
119
			}
120
		},
121
		"plugins" : [ "themes", "html_data", "dnd" ]
122
	});
123
});
124
</script>
125

    
126
<h3>Reorder only demo</h3>
127
<div id="demo2" class="demo">
128
	<ul>
129
		<li id="rhtml_1">
130
			<a href="#">Root node 1</a>
131
			<ul>
132
				<li id="rhtml_2">
133
					<a href="#">Child node 1</a>
134
				</li>
135
				<li id="rhtml_3">
136
					<a href="#">Child node 2</a>
137
				</li>
138
				<li id="rhtml_4">
139
					<a href="#">Child node 3</a>
140
				</li>
141
				<li id="rhtml_5">
142
					<a href="#">Child node 4</a>
143
				</li>
144
			</ul>
145
		</li>
146
		<li id="rhtml_6">
147
			<a href="#">Root node 2</a>
148
		</li>
149
		<li id="rhtml_7">
150
			<a href="#">Root node 3</a>
151
		</li>
152
	</ul>
153
</div>
154
<script type="text/javascript" class="source">
155
$(function () {
156
	$("#demo2").jstree({ 
157
		"crrm" : { 
158
			"move" : {
159
				"check_move" : function (m) { 
160
					var p = this._get_parent(m.o);
161
					if(!p) return false;
162
					p = p == -1 ? this.get_container() : p;
163
					if(p === m.np) return true;
164
					if(p[0] && m.np[0] && p[0] === m.np[0]) return true;
165
					return false;
166
				}
167
			}
168
		},
169
		"dnd" : {
170
			"drop_target" : false,
171
			"drag_target" : false
172
		},
173
		"plugins" : [ "themes", "html_data", "crrm", "dnd" ]
174
	});
175
});
176
</script>
177

    
178
</div>
179

    
180
<h2 id="api">API</h2>
181
<div class="panel api">
182

    
183
<div style="height:1px; visibility:hidden;">
184
	<span id="dnd_show">&nbsp;</span>
185
	<span id="dnd_open">&nbsp;</span>
186
	<span id="dnd_finish">&nbsp;</span>
187
	<span id="dnd_enter">&nbsp;</span>
188
	<span id="start_drag">&nbsp;</span>
189
</div>
190
<h3 id="dnd_prepare">.dnd_prepare ( ), .dnd_show ( ), .dnd_open ( ), .dnd_finish ( ), .dnd_enter ( ), .start_drag ( )</h3>
191
<p>All those functions are used internally only. If you want more information - examine the source code.</p>
192

    
193
</div>
194

    
195
</div>
196
</body>
197
</html>
(14-14/27)