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 - html_data 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 - html_data plugin</h1>
21
<h2>Description</h2>
22
<div id="description">
23
<p>The <code>html_data</code> plugin enables jsTree to convert nested unordered lists to interactive trees. jsTree can also get HTML from the server insert it into the DOM and convert that to a tree.</p>
24
<p>The basic structure you need to follow when supplying data in the HTML format is:</p>
25
<div class="code_f">
26
<pre class="brush:xml;">
27
&lt;li&gt;
28
	&lt;a href="some_value_here"&gt;Node title&lt;/a&gt;
29
	&lt;!-- UL node only needed for children - omit if there are no children --&gt;
30
	&lt;ul&gt;
31
		&lt;!-- Children LI nodes here --&gt;
32
	&lt;/ul&gt;
33
&lt;/li&gt;
34
</pre>
35
</div>
36
<p>If you inspect the resulting structure you will find it a bit different - that is because jstree will automatically do some corrections.</p>
37
<div class="code_f">
38
<pre class="brush:xml;">
39
&lt;!-- one of the three classes will be applied depending on node structure --&gt;
40
&lt;li class="[ jstree-open | jstree-closed | jstree-leaf ]"&gt;
41
	&lt;!-- an INS element is inserted --&gt;
42
	&lt;ins class="jstree-icon"&gt;&amp;#160;&lt;/ins&gt;
43
	&lt;a href="some_value_here"&gt;
44
		&lt;!-- another INS element is inserted --&gt;
45
		&lt;ins class="jstree-icon"&gt;&amp;#160;&lt;/ins&gt;
46
		Node title
47
	&lt;/a&gt;
48
&lt;/li&gt;
49
</pre>
50
</div>
51
<p>Both <code>ins</code> elements are inserted for visualization purposes. As for the class (<code>jstree-open</code>, <code>jstree-closed</code>) - you can specify that yourself to force the node to appear either closed or opened. Making a node with no children appear closed is often used - if you use ajax, opening a closed node with no children will result in jstree making a server call for the children (see the <a href="#demo3">demo below</a>).</p>
52
</div>
53

    
54
<h2 id="configuration">Configuration</h2>
55
<div class="panel configuration">
56
<h3>data</h3>
57
<p class="meta">A HTML string (or <code>false</code> if not used). Default is <code>false</code>.</p>
58
<p>Specifies the content to load into the container and convert to a tree.</p>
59
<h3>ajax</h3>
60
<p class="meta">An object (or <code>false</code> if not used). Default is <code>false</code>.</p>
61
<p>The ajax config object is pretty much the same as the <a href="http://api.jquery.com/jQuery.ajax/">jQuery ajax settings object</a>.</p>
62
<p>You can set the <code>data</code> option to a function, that will be executed in the current tree's scope (<code>this</code> will be the tree instance) and gets the node about to be open as a paramater (or <code>-1</code> for initial load). Whatever you return in the function will be sent to the server as data (so for example you can send the node's ID).</p>
63
<p>You can set the <code>url</code> option to a function, that will be executed in the current tree's scope (<code>this</code> will be the tree instance) and gets the node about to be open as a paramater (or <code>-1</code> for initial load). Whatever you return in the <code>url</code> function will be used as the ajax URL (so that you can accomodate pretty paths such as /get_children/node_2).</p>
64
<p>The <code>error</code> and <code>success</code> functions (if present) also fire in the context of the tree, and if you return a value in the <code>success</code> function it will be used to populate the tree - this can be useful if you want to somehow change what the server returned on the client side before it is displayed in the tree.</p>
65
<h3>correct_state</h3>
66
<p class="meta">A Boolean. Default is <code>true</code>.</p>
67
<p>If this option is set to <code>true</code> if an AJAX request returns an empty result, the node that was about to be opened will be converted to a leaf node (the open icon will no longer be displayed).</p>
68

    
69
<p class="note"><strong>NOTE:</strong><br />If both <code>data</code> and <code>ajax</code> are not set, the current container's HTML is used to build the tree.<br />If both <code>data</code> and <code>ajax</code> are set the initial tree is rendered from the <code>data</code> string. When opening a closed node (that has no loaded children) an AJAX request is made.</p>
70
</div>
71

    
72
<h2 id="demos">Demos</h2>
73
<div class="panel">
74

    
75
<h3>Using initial content (convert an existing list)</h3>
76
<div id="demo1" class="demo">
77
	<ul>
78
		<li id="phtml_1">
79
			<a href="#">Root node 1</a>
80
			<ul>
81
				<li id="phtml_2">
82
					<a href="#">Child node 1</a>
83
				</li>
84
				<li id="phtml_3">
85
					<a href="#">Child node 2</a>
86
				</li>
87
			</ul>
88
		</li>
89
		<li id="phtml_4">
90
			<a href="#">Root node 2</a>
91
		</li>
92
	</ul>
93
</div>
94
<script type="text/javascript" class="source">
95
$(function () {
96
	$("#demo1").jstree({ 
97
		"plugins" : [ "themes", "html_data" ]
98
	});
99
});
100
</script>
101

    
102
<h3>Using the data config option</h3>
103
<div id="demo2" class="demo"></div>
104
<script type="text/javascript" class="source">
105
$(function () {
106
	$("#demo2").jstree({ 
107
		"core" : { "initially_open" : [ "root" ] },
108
		"html_data" : {
109
			"data" : "<li id='root'><a href='#'>Root node</a><ul><li><a href='#'>Child node</a></li></ul></li>"
110
		},
111
		"plugins" : [ "themes", "html_data" ]
112
	});
113
});
114
</script>
115

    
116
<h3>Using the ajax config option</h3>
117
<div id="demo3" class="demo"></div>
118
<script type="text/javascript" class="source">
119
$(function () {
120
	$("#demo3").jstree({ 
121
		"html_data" : {
122
			"ajax" : {
123
				"url" : "_html_data.html",
124
				"data" : function (n) { 
125
					return { id : n.attr ? n.attr("id") : 0 }; 
126
				}
127
			}
128
		},
129
		"plugins" : [ "themes", "html_data" ]
130
	});
131
});
132
</script>
133

    
134
<h3>Using both the data &amp; ajax config options</h3>
135
<div id="demo4" class="demo"></div>
136
<script type="text/javascript" class="source">
137
$(function () {
138
	$("#demo4").jstree({ 
139
		"core" : { "initially_open" : [ "root2" ] },
140
		"html_data" : {
141
			"data" : "<li class='jstree-closed' id='root2'><a href='#'>Root node</a></li>",
142
			"ajax" : { "url" : "_html_data.html" }
143
		},
144
		"plugins" : [ "themes", "html_data" ]
145
	});
146
});
147
</script>
148
</div>
149

    
150
<h2 id="api">API</h2>
151
<div class="panel api">
152
<p>Both dummy functions - <code>_is_loaded</code> and <code>load_node</code> are overwritten.</p>
153
<h3 id="load_node_html">.load_node_html ( node , success_callback , error_callback )</h3>
154
<p>This function is called instead of <code>load_node</code>.</p>
155
<ul class="arguments">
156
	<li>
157
		<code class="tp">mixed</code> <strong>node</strong>
158
		<p>This can be a DOM node, jQuery node or selector pointing to an element you want loaded. Use <code>-1</code> for root nodes.</p>
159
	</li>
160
	<li>
161
		<code class="tp">function</code> <strong>success_callback</strong>
162
		<p>A function to be executed once the node is loaded successfully - used internally. You should wait for the <code>load_node</code> event.</p>
163
	</li>
164
	<li>
165
		<code class="tp">function</code> <strong>error_callback</strong>
166
		<p>A function to be executed if the node is not loaded due to an error - used internally. You should wait for the <code>load_node</code> event.</p>
167
	</li>
168
</ul>
169

    
170
</div>
171

    
172
</div>
173
</body>
174
</html>
(16-16/27)