Skip to content

Commit

Permalink
added the json_data plugin, not complete yet
Browse files Browse the repository at this point in the history
  • Loading branch information
vakata committed May 25, 2011
1 parent 9c4ff97 commit 197a043
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
36 changes: 34 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script type="text/javascript" src="jstree.themes.js"></script>
<script type="text/javascript" src="jstree.ui.js"></script>
<script type="text/javascript" src="jstree.state.js"></script>
<script type="text/javascript" src="jstree.json.js"></script>
<style type="text/css">
html, body { margin:0; padding:0; font-family:Verdana; font-size:10px; }
#container { width:800px; margin:0 auto; }
Expand All @@ -30,12 +31,43 @@
.bind("create_node.jstree", function (e, data) {
alert("Created `" + data.inst.get_text(data.rslt.obj) + "` inside `" + (data.rslt.parent === -1 ? 'the main container' : data.inst.get_text(data.rslt.parent)) + "` at index " + data.rslt.position);
});
$("#jstree-json")
.jstree({
'json' : {
// data function:
// 'data' : function (o, c) { c.call(this, ['node 1', 'node 2']
// data static:
'data' : [
{
'title' : 'Root 1',
'data' : { 'jstree' : { 'closed' : true } }
},
'Root 2',
{
'title' : 'Root 3',
'data' : { 'jstree' : { 'children' : [ 'Child 1', 'Child 2' ] } }
}
],
// mixed with ajax
'ajax' : {
// static url
'url' : 'test.json'
// url with function
// 'url' : function (o) { return 'test.json'; },
// with some data
// 'data' : function () { return { 'foo' : 'bar' }; }
}
},
'plugins' : [ 'core', 'themes', 'ui', 'json' ]
});
});
</script>
</head>
<body>

<div id="jstree">
<div id="jstree-json" style="float:left; width:45%; margin-left:1%;"></div>

<div id="jstree" style="float:right; width:45%; margin-right:1%;">
<ul>
<li id="some-node-id">Root node
<ul>
Expand All @@ -59,7 +91,7 @@
</li>
</ul>
</div>
<hr />
<hr style="clear:both;" />
<input type="button" value="$.jstree._focused().create_node();" onclick="$.jstree._focused().create_node();" />
<input type="button" value="$.jstree._focused().create_node(-1, 'New root node');" onclick="$.jstree._focused().create_node(-1, 'New root node');" />
<input type="button" value="$.jstree._focused().create_node(null, { title : 'New root node', children : [ 'Created child 1', 'Created child 2' ] });" onclick="$.jstree._focused().create_node(null, { title : 'New root node', children : [ 'Created child 1', 'Created child 2' ] });" />
Expand Down
10 changes: 9 additions & 1 deletion jstree.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ Some static functions and variables, unless you know exactly what you are doing
load_node : function (obj, callback) {
obj = this.get_node(obj);
if(!obj) { callback.call(this, obj, false); return false; }
// if(this.is_loading(obj)) { return true; }
if(obj !== -1) { obj.addClass("jstree-loading"); }
this._load_node(obj, $.proxy(function (status) {
if(obj !== -1) { obj.removeClass("jstree-loading"); }
Expand Down Expand Up @@ -1361,14 +1362,21 @@ Some static functions and variables, unless you know exactly what you are doing
if(typeof node === "undefined") { node = {}; }
if(typeof node === "string") { node = { "title" : node }; }
if(!node.li_attr) { node.li_attr = {}; }
if(!node.a_attr) { node.a_attr = { }; }
if(!node.a_attr) { node.a_attr = {}; }
if(!node.a_attr.href) { node.a_attr.href = '#'; }
if(!node.title) { node.title = this._get_string("New node"); }

li = $("<li />").attr(node.li_attr);
a = $("<a />").attr(node.a_attr).html(node.title);
ul = $("<ul />");
if(node.data) { li.data(node.data); }
if(
node.children === true ||
$.isArray(node.children) ||
(li.data('jstree') && $.isArray(li.data('jstree').children))
) {
li.data('jstree').closed = true;
}
li.append(a);
if($.isArray(node.children)) {
$.each(node.children, $.proxy(function (i, n) {
Expand Down

0 comments on commit 197a043

Please sign in to comment.