1 |
5703
|
leinfelder
|
<!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 - xml_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 - xml_data plugin</h1>
|
21 |
|
|
<h2>Description</h2>
|
22 |
|
|
<div id="description">
|
23 |
|
|
<p>The <code>xml_data</code> plugin enables jsTree to convert XML objects to interactive trees (using XSL). The data (XML) can be set up in the config (as a string) or retrieved from a server (also ondemand).</p>
|
24 |
|
|
<p>Two types of XML structures are supported - flat and nested:</p>
|
25 |
|
|
<div class="code_f">
|
26 |
|
|
<pre class="brush:xml;">
|
27 |
|
|
<!-- FLAT -->
|
28 |
|
|
<root>
|
29 |
|
|
<item id="root_1" parent_id="0" state="closed">
|
30 |
|
|
<content>
|
31 |
|
|
<name><![CDATA[Node 1]]></name>
|
32 |
|
|
</content>
|
33 |
|
|
</item>
|
34 |
|
|
<item id="node_2" parent_id="root_1">
|
35 |
|
|
<content>
|
36 |
|
|
<name><![CDATA[Node 2]]></name>
|
37 |
|
|
</content>
|
38 |
|
|
</item>
|
39 |
|
|
</root>
|
40 |
|
|
|
41 |
|
|
<!-- NESTED -->
|
42 |
|
|
<root>
|
43 |
|
|
<item id="xml_1">
|
44 |
|
|
<content><name><![CDATA[Root node 1]]></name></content>
|
45 |
|
|
<item id="xml_2">
|
46 |
|
|
<content><name><![CDATA[Child node 1]]></name></content>
|
47 |
|
|
</item>
|
48 |
|
|
</item>
|
49 |
|
|
</root>
|
50 |
|
|
</pre>
|
51 |
|
|
</div>
|
52 |
|
|
<p>Aside from nesting the only difference is the <code>parent_id</code> attribute used in <code>xml_flat</code>.</p>
|
53 |
|
|
<p><code>parent_id</code> defines the parent of the node in XML flat, use <code>0</code> for root nodes. Also when using async - use <code>0</code> for the first level.</p>
|
54 |
|
|
<p><code>state</code> defines the state of the node (<code>open</code> or <code>closed</code>). You can omit it too - jstree will handle the data automatically - nodes with no children will be leaf nodes, nodes with children will be closed.</p>
|
55 |
|
|
<p>All attributes you set on the <code>item</code> node will be transfered to the resulting <code>li</code> node. All attributes you set on the <code>name</code> node will be transfered to the resulting <code>a</code> node.</p>
|
56 |
|
|
<p>If you are using the <a href="languages.html">languages plugin</a> you can have multiple <code>name</code> nodes in a every <code>item</code> node, just set a <code>language</code> attribute on each one (<code><name language="en" ...</code>).</p>
|
57 |
|
|
<p class="note">Remember to always set the XML header on your XML files.</p>
|
58 |
|
|
</div>
|
59 |
|
|
|
60 |
|
|
<h2 id="configuration">Configuration</h2>
|
61 |
|
|
<div class="panel configuration">
|
62 |
|
|
<h3>data</h3>
|
63 |
|
|
<p class="meta">A XML string (or <code>false</code> if not used). Default is <code>false</code>.</p>
|
64 |
|
|
<p>Specifies the content to load into the container and convert to a tree.</p>
|
65 |
|
|
<h3>ajax</h3>
|
66 |
|
|
<p class="meta">An object (or <code>false</code> if not used). Default is <code>false</code>.</p>
|
67 |
|
|
<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>
|
68 |
|
|
<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>
|
69 |
|
|
<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>
|
70 |
|
|
<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>
|
71 |
|
|
<h3>correct_state</h3>
|
72 |
|
|
<p class="meta">A Boolean. Default is <code>true</code>.</p>
|
73 |
|
|
<p>If this option is set to <code>true</code> if an AJAX 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>
|
74 |
|
|
<h3>clean_node</h3>
|
75 |
|
|
<p class="meta">A Boolean. Default is <code>false</code>.</p>
|
76 |
|
|
<p>Set to true if node needs to be cleaned - usually you should leave this to <code>false</code>.</p>
|
77 |
|
|
<h3>xsl</h3>
|
78 |
|
|
<p class="meta">A string. Default is <code>"flat"</code>.</p>
|
79 |
|
|
<p>The type of structure you wiil be using - set either to <code>"flat"</code> or <code>"nest"</code>.</p>
|
80 |
|
|
|
81 |
|
|
<p class="note"><strong>NOTE:</strong><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>
|
82 |
|
|
</div>
|
83 |
|
|
|
84 |
|
|
<h2 id="demos">Demos</h2>
|
85 |
|
|
<div class="panel">
|
86 |
|
|
|
87 |
|
|
<h3>Using the data config option (flat)</h3>
|
88 |
|
|
<div id="demo1" class="demo"></div>
|
89 |
|
|
<script type="text/javascript" class="source">
|
90 |
|
|
$(function () {
|
91 |
|
|
$("#demo1").jstree({
|
92 |
|
|
"xml_data" : {
|
93 |
|
|
"data" : "" +
|
94 |
|
|
"<root>" +
|
95 |
|
|
"<item id='node_1'>" +
|
96 |
|
|
"<content><name>Root node 1</name></content>" +
|
97 |
|
|
"</item>" +
|
98 |
|
|
"<item>" +
|
99 |
|
|
"<content><name>Root node 2</name></content>" +
|
100 |
|
|
"</item>" +
|
101 |
|
|
"<item parent_id='node_1'>" +
|
102 |
|
|
"<content><name>Child node</name></content>" +
|
103 |
|
|
"</item>" +
|
104 |
|
|
"</root>"
|
105 |
|
|
},
|
106 |
|
|
"plugins" : [ "themes", "xml_data" ]
|
107 |
|
|
});
|
108 |
|
|
});
|
109 |
|
|
</script>
|
110 |
|
|
|
111 |
|
|
<h3>Using the ajax config option (nested)</h3>
|
112 |
|
|
<div id="demo2" class="demo"></div>
|
113 |
|
|
<script type="text/javascript" class="source">
|
114 |
|
|
$(function () {
|
115 |
|
|
$("#demo2").jstree({
|
116 |
|
|
"xml_data" : {
|
117 |
|
|
"ajax" : {
|
118 |
|
|
"url" : "_xml_nest.xml"
|
119 |
|
|
},
|
120 |
|
|
"xsl" : "nest"
|
121 |
|
|
},
|
122 |
|
|
"plugins" : [ "themes", "xml_data" ]
|
123 |
|
|
});
|
124 |
|
|
});
|
125 |
|
|
</script>
|
126 |
|
|
|
127 |
|
|
<h3>Using both the data & ajax config options (flat)</h3>
|
128 |
|
|
<div id="demo4" class="demo"></div>
|
129 |
|
|
<script type="text/javascript" class="source">
|
130 |
|
|
$(function () {
|
131 |
|
|
$("#demo4").jstree({
|
132 |
|
|
"xml_data" : {
|
133 |
|
|
"data" : "" +
|
134 |
|
|
"<root>" +
|
135 |
|
|
"<item id='node_1' state='closed'>" +
|
136 |
|
|
"<content><name>Root node 1</name></content>" +
|
137 |
|
|
"</item>" +
|
138 |
|
|
"<item>" +
|
139 |
|
|
"<content><name>Root node 2</name></content>" +
|
140 |
|
|
"</item>" +
|
141 |
|
|
"</root>",
|
142 |
|
|
"ajax" : {
|
143 |
|
|
"url" : "_xml_flat.xml",
|
144 |
|
|
"data" : function (n) {
|
145 |
|
|
return {
|
146 |
|
|
id : n.attr ? n.attr("id") : 0,
|
147 |
|
|
rand : new Date().getTime()
|
148 |
|
|
};
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
},
|
152 |
|
|
"plugins" : [ "themes", "xml_data" ]
|
153 |
|
|
});
|
154 |
|
|
});
|
155 |
|
|
</script>
|
156 |
|
|
</div>
|
157 |
|
|
|
158 |
|
|
<h2 id="api">API</h2>
|
159 |
|
|
<div class="panel api">
|
160 |
|
|
<p>Both dummy functions - <code>_is_loaded</code> and <code>load_node</code> are overwritten.</p>
|
161 |
|
|
<h3 id="load_node_xml">.load_node_xml ( node , success_callback , error_callback )</h3>
|
162 |
|
|
<p>This function is called instead of <code>load_node</code>.</p>
|
163 |
|
|
<ul class="arguments">
|
164 |
|
|
<li>
|
165 |
|
|
<code class="tp">mixed</code> <strong>node</strong>
|
166 |
|
|
<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>
|
167 |
|
|
</li>
|
168 |
|
|
<li>
|
169 |
|
|
<code class="tp">function</code> <strong>success_callback</strong>
|
170 |
|
|
<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>
|
171 |
|
|
</li>
|
172 |
|
|
<li>
|
173 |
|
|
<code class="tp">function</code> <strong>error_callback</strong>
|
174 |
|
|
<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>
|
175 |
|
|
</li>
|
176 |
|
|
</ul>
|
177 |
|
|
<h3 id="parse_xml">.parse_xml ( data )</h3>
|
178 |
|
|
<p>This function converts XML strings or objects to the DOM structure required by jstree. Returns a jQuery object.</p>
|
179 |
|
|
<ul class="arguments">
|
180 |
|
|
<li>
|
181 |
|
|
<code class="tp">mixed</code> <strong>data</strong>
|
182 |
|
|
<p>The XML string/object.</p>
|
183 |
|
|
</li>
|
184 |
|
|
</ul>
|
185 |
|
|
<h3 id="get_xml">.get_xml ( type , node , li_attr , a_attr , is_callback )</h3>
|
186 |
|
|
<p>This function returns an array of tree nodes converted back to XML.</p>
|
187 |
|
|
<ul class="arguments">
|
188 |
|
|
<li>
|
189 |
|
|
<code class="tp">string</code> <strong>type</strong>
|
190 |
|
|
<p>Either <code>"flat"</code> or <code>"nest"</code>. Default is <code>"flat"</code>.</p>
|
191 |
|
|
</li>
|
192 |
|
|
<li>
|
193 |
|
|
<code class="tp">mixed</code> <strong>node</strong>
|
194 |
|
|
<p>This can be a DOM node, jQuery node or selector pointing to an element you want returned. Use <code>-1</code> or omit to get the whole tree.</p>
|
195 |
|
|
</li>
|
196 |
|
|
<li>
|
197 |
|
|
<code class="tp">array</code> <strong>li_attr</strong>
|
198 |
|
|
<p>The attributes to collect from the <code>LI</code> node. Defaults to <code>[ "id" , "class" ]</p>
|
199 |
|
|
</li>
|
200 |
|
|
<li>
|
201 |
|
|
<code class="tp">array</code> <strong>a_attr</strong>
|
202 |
|
|
<p>The attributes to collect from the <code>A</code> node. Defaults to <code>[ ]</p>
|
203 |
|
|
</li>
|
204 |
|
|
<li>
|
205 |
|
|
<code class="tp">string</code> <strong>is_callback</strong>
|
206 |
|
|
<p>Used internally.</p>
|
207 |
|
|
</li>
|
208 |
|
|
</ul>
|
209 |
|
|
|
210 |
|
|
</div>
|
211 |
|
|
|
212 |
|
|
</div>
|
213 |
|
|
</body>
|
214 |
|
|
</html>
|