2 * Async Treeview 0.1 - Lazy-loading extension for Treeview
4 * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
6 * Copyright (c) 2007 Jörn Zaefferer
8 * Dual licensed under the MIT and GPL licenses:
9 * http://www.opensource.org/licenses/mit-license.php
10 * http://www.gnu.org/licenses/gpl.html
18 function load(settings, root, child, container) {
19 function createNode(parent) {
20 var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
22 current.children("span").addClass(this.classes);
25 current.addClass("open");
27 if (this.hasChildren || this.children && this.children.length) {
28 var branch = $("<ul/>").appendTo(current);
29 if (this.hasChildren) {
30 current.addClass("hasChildren");
32 classes: "placeholder",
37 if (this.children && this.children.length) {
38 $.each(this.children, createNode, [branch])
42 $.ajax($.extend(true, {
48 success: function(response) {
50 $.each(response, createNode, [child]);
51 $(container).treeview({add: child});
55 $.getJSON(settings.url, {root: root}, function(response) {
56 function createNode(parent) {
57 var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
59 current.children("span").addClass(this.classes);
62 current.addClass("open");
64 if (this.hasChildren || this.children && this.children.length) {
65 var branch = $("<ul/>").appendTo(current);
66 if (this.hasChildren) {
67 current.addClass("hasChildren");
69 classes: "placeholder",
74 if (this.children && this.children.length) {
75 $.each(this.children, createNode, [branch])
80 $.each(response, createNode, [child]);
81 $(container).treeview({add: child});
86 var proxied = $.fn.treeview;
87 $.fn.treeview = function(settings) {
89 return proxied.apply(this, arguments);
92 if (!container.children().size())
93 load(settings, "source", this, container);
94 var userToggle = settings.toggle;
95 return proxied.call(this, $.extend({}, settings, {
99 if ($this.hasClass("hasChildren")) {
100 var childList = $this.removeClass("hasChildren").find("ul");
101 load(settings, this.id, childList, container);
104 userToggle.apply(this, arguments);