web/data/jquery-treeview/jquery.treeview.async.js
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 18 May 2015 16:36:26 +0200
changeset 10438 f27a489994e8
parent 10100 6718c03f8938
permissions -rw-r--r--
[devtools] make test db name for postgresql process-specific In case we run two tests concurrently on the same cluster, better not use the same db name for both.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10100
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     1
/*
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     2
 * Async Treeview 0.1 - Lazy-loading extension for Treeview
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     3
 *
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     4
 * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     5
 *
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     6
 * Copyright 2010 Jörn Zaefferer
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     7
 * Released under the MIT license:
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     8
 *   http://www.opensource.org/licenses/mit-license.php
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     9
 */
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    10
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    11
;(function($) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    12
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    13
function load(settings, root, child, container) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    14
	function createNode(parent) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    15
		var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    16
		if (this.classes) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    17
			current.children("span").addClass(this.classes);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    18
		}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    19
		if (this.expanded) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    20
			current.addClass("open");
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    21
		}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    22
		if (this.hasChildren || this.children && this.children.length) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    23
			var branch = $("<ul/>").appendTo(current);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    24
			if (this.hasChildren) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    25
				current.addClass("hasChildren");
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    26
				createNode.call({
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    27
					classes: "placeholder",
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    28
					text: "&nbsp;",
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    29
					children:[]
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    30
				}, branch);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    31
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    32
			if (this.children && this.children.length) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    33
				$.each(this.children, createNode, [branch])
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    34
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    35
		}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    36
	}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    37
	$.ajax($.extend(true, {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    38
		url: settings.url,
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    39
		dataType: "json",
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    40
		data: {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    41
			root: root
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    42
		},
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    43
		success: function(response) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    44
			child.empty();
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    45
			$.each(response, createNode, [child]);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    46
	        $(container).treeview({add: child});
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    47
	    }
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    48
	}, settings.ajax));
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    49
	/*
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    50
	$.getJSON(settings.url, {root: root}, function(response) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    51
		function createNode(parent) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    52
			var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    53
			if (this.classes) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    54
				current.children("span").addClass(this.classes);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    55
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    56
			if (this.expanded) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    57
				current.addClass("open");
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    58
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    59
			if (this.hasChildren || this.children && this.children.length) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    60
				var branch = $("<ul/>").appendTo(current);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    61
				if (this.hasChildren) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    62
					current.addClass("hasChildren");
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    63
					createNode.call({
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    64
						classes: "placeholder",
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    65
						text: "&nbsp;",
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    66
						children:[]
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    67
					}, branch);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    68
				}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    69
				if (this.children && this.children.length) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    70
					$.each(this.children, createNode, [branch])
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    71
				}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    72
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    73
		}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    74
		child.empty();
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    75
		$.each(response, createNode, [child]);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    76
        $(container).treeview({add: child});
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    77
    });
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    78
    */
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    79
}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    80
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    81
var proxied = $.fn.treeview;
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    82
$.fn.treeview = function(settings) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    83
	if (!settings.url) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    84
		return proxied.apply(this, arguments);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    85
	}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    86
	if (!settings.root) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    87
		settings.root = "source";
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    88
	}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    89
	var container = this;
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    90
	if (!container.children().size())
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    91
		load(settings, settings.root, this, container);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    92
	var userToggle = settings.toggle;
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    93
	return proxied.call(this, $.extend({}, settings, {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    94
		collapsed: true,
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    95
		toggle: function() {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    96
			var $this = $(this);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    97
			if ($this.hasClass("hasChildren")) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    98
				var childList = $this.removeClass("hasChildren").find("ul");
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    99
				load(settings, this.id, childList, container);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   100
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   101
			if (userToggle) {
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   102
				userToggle.apply(this, arguments);
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   103
			}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   104
		}
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   105
	}));
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   106
};
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   107
6718c03f8938 [web] Update jquery-treeview to the latest version
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   108
})(jQuery);