2 * Async Treeview 0.1 - Lazy-loading extension for Treeview
\r
4 * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
\r
6 * Copyright (c) 2007 Jörn Zaefferer
\r
8 * Dual licensed under the MIT and GPL licenses:
\r
9 * http://www.opensource.org/licenses/mit-license.php
\r
10 * http://www.gnu.org/licenses/gpl.html
\r
18 function load(settings, root, child, container) {
\r
19 $.getJSON(settings.url, {root: root}, function(response) {
\r
20 function createNode(parent) {
\r
21 var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
\r
23 current.children("span").addClass(this.classes);
\r
25 if (this.expanded) {
\r
26 current.addClass("open");
\r
28 if (this.hasChildren || this.children && this.children.length) {
\r
29 var branch = $("<ul/>").appendTo(current);
\r
30 if (this.hasChildren) {
\r
31 current.addClass("hasChildren");
\r
38 if (this.children && this.children.length) {
\r
39 $.each(this.children, createNode, [branch])
\r
43 $.each(response, createNode, [child]);
\r
44 $(container).treeview({add: child});
\r
48 var proxied = $.fn.treeview;
\r
49 $.fn.treeview = function(settings) {
\r
50 if (!settings.url) {
\r
51 return proxied.apply(this, arguments);
\r
53 var container = this;
\r
54 load(settings, "source", this, container);
\r
55 var userToggle = settings.toggle;
\r
56 return proxied.call(this, $.extend({}, settings, {
\r
58 toggle: function() {
\r
59 var $this = $(this);
\r
60 if ($this.hasClass("hasChildren")) {
\r
61 var childList = $this.removeClass("hasChildren").find("ul");
\r
63 load(settings, this.id, childList, container);
\r
66 userToggle.apply(this, arguments);
\r