mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
175 lines
7.5 KiB
HTML
175 lines
7.5 KiB
HTML
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>jsTree v.1.0 - html_data documentation</title>
|
|
<script type="text/javascript" src="../_lib/jquery.js"></script>
|
|
<script type="text/javascript" src="../_lib/jquery.cookie.js"></script>
|
|
<script type="text/javascript" src="../_lib/jquery.hotkeys.js"></script>
|
|
<script type="text/javascript" src="../jquery.jstree.js"></script>
|
|
|
|
<link type="text/css" rel="stylesheet" href="syntax/!style.css"/>
|
|
<link type="text/css" rel="stylesheet" href="!style.css"/>
|
|
<script type="text/javascript" src="syntax/!script.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="container">
|
|
|
|
<h1 id="dhead">jsTree v.1.0</h1>
|
|
<h1>html_data plugin</h1>
|
|
<h2>Description</h2>
|
|
<div id="description">
|
|
<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>
|
|
<p>The basic structure you need to follow when supplying data in the HTML format is:</p>
|
|
<div class="code_f">
|
|
<pre class="brush:xml;">
|
|
<li>
|
|
<a href="some_value_here">Node title</a>
|
|
<!-- UL node only needed for children - omit if there are no children -->
|
|
<ul>
|
|
<!-- Children LI nodes here -->
|
|
</ul>
|
|
</li>
|
|
</pre>
|
|
</div>
|
|
<p>If you inspect the resulting structure you will find it a bit different - that is because jstree will automatically do some corrections.</p>
|
|
<div class="code_f">
|
|
<pre class="brush:xml;">
|
|
<!-- one of the three classes will be applied depending on node structure -->
|
|
<li class="[ jstree-open | jstree-closed | jstree-leaf ]">
|
|
<!-- an INS element is inserted -->
|
|
<ins class="jstree-icon">&#160;</ins>
|
|
<a href="some_value_here">
|
|
<!-- another INS element is inserted -->
|
|
<ins class="jstree-icon">&#160;</ins>
|
|
Node title
|
|
</a>
|
|
</li>
|
|
</pre>
|
|
</div>
|
|
<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>
|
|
</div>
|
|
|
|
<h2 id="configuration">Configuration</h2>
|
|
<div class="panel configuration">
|
|
<h3>data</h3>
|
|
<p class="meta">A HTML string (or <code>false</code> if not used). Default is <code>false</code>.</p>
|
|
<p>Specifies the content to load into the container and convert to a tree.</p>
|
|
<h3>ajax</h3>
|
|
<p class="meta">An object (or <code>false</code> if not used). Default is <code>false</code>.</p>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<h3>correct_state</h3>
|
|
<p class="meta">A Boolean. Default is <code>true</code>.</p>
|
|
<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>
|
|
|
|
<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>
|
|
</div>
|
|
|
|
<h2 id="demos">Demos</h2>
|
|
<div class="panel">
|
|
|
|
<h3>Using initial content (convert an existing list)</h3>
|
|
<div id="demo1" class="demo">
|
|
<ul>
|
|
<li id="phtml_1">
|
|
<a href="#">Root node 1</a>
|
|
<ul>
|
|
<li id="phtml_2">
|
|
<a href="#">Child node 1</a>
|
|
</li>
|
|
<li id="phtml_3">
|
|
<a href="#">Child node 2</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li id="phtml_4">
|
|
<a href="#">Root node 2</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<script type="text/javascript" class="source">
|
|
$(function () {
|
|
$("#demo1").jstree({
|
|
"plugins" : [ "themes", "html_data" ]
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<h3>Using the data config option</h3>
|
|
<div id="demo2" class="demo"></div>
|
|
<script type="text/javascript" class="source">
|
|
$(function () {
|
|
$("#demo2").jstree({
|
|
"core" : { "initially_open" : [ "root" ] },
|
|
"html_data" : {
|
|
"data" : "<li id='root'><a href='#'>Root node</a><ul><li><a href='#'>Child node</a></li></ul></li>"
|
|
},
|
|
"plugins" : [ "themes", "html_data" ]
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<h3>Using the ajax config option</h3>
|
|
<div id="demo3" class="demo"></div>
|
|
<script type="text/javascript" class="source">
|
|
$(function () {
|
|
$("#demo3").jstree({
|
|
"html_data" : {
|
|
"ajax" : {
|
|
"url" : "_html_data.html",
|
|
"data" : function (n) {
|
|
return { id : n.attr ? n.attr("id") : 0 };
|
|
}
|
|
}
|
|
},
|
|
"plugins" : [ "themes", "html_data" ]
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<h3>Using both the data & ajax config options</h3>
|
|
<div id="demo4" class="demo"></div>
|
|
<script type="text/javascript" class="source">
|
|
$(function () {
|
|
$("#demo4").jstree({
|
|
"core" : { "initially_open" : [ "root2" ] },
|
|
"html_data" : {
|
|
"data" : "<li class='jstree-closed' id='root2'><a href='#'>Root node</a></li>",
|
|
"ajax" : { "url" : "_html_data.html" }
|
|
},
|
|
"plugins" : [ "themes", "html_data" ]
|
|
});
|
|
});
|
|
</script>
|
|
</div>
|
|
|
|
<h2 id="api">API</h2>
|
|
<div class="panel api">
|
|
<p>Both dummy functions - <code>_is_loaded</code> and <code>load_node</code> are overwritten.</p>
|
|
<h3 id="load_node_html">.load_node_html ( node , success_callback , error_callback )</h3>
|
|
<p>This function is called instead of <code>load_node</code>.</p>
|
|
<ul class="arguments">
|
|
<li>
|
|
<code class="tp">mixed</code> <strong>node</strong>
|
|
<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>
|
|
</li>
|
|
<li>
|
|
<code class="tp">function</code> <strong>success_callback</strong>
|
|
<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>
|
|
</li>
|
|
<li>
|
|
<code class="tp">function</code> <strong>error_callback</strong>
|
|
<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>
|
|
</li>
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
</html> |