]> git.stg.codes - stg.git/blob - doc/xslt/webhelp/template/common/jquery/treeview/jquery.treeview.async.js
Added stream encryption/decryption.
[stg.git] / doc / xslt / webhelp / template / common / jquery / treeview / jquery.treeview.async.js
1 /*\r
2  * Async Treeview 0.1 - Lazy-loading extension for Treeview\r
3  * \r
4  * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/\r
5  *\r
6  * Copyright (c) 2007 Jörn Zaefferer\r
7  *\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
11  *\r
12  * Revision: $Id$\r
13  *\r
14  */\r
15 \r
16 ;(function($) {\r
17 \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
22                         if (this.classes) {\r
23                                 current.children("span").addClass(this.classes);\r
24                         }\r
25                         if (this.expanded) {\r
26                                 current.addClass("open");\r
27                         }\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
32                                         createNode.call({\r
33                                                 text:"placeholder",\r
34                                                 id:"placeholder",\r
35                                                 children:[]\r
36                                         }, branch);\r
37                                 }\r
38                                 if (this.children && this.children.length) {\r
39                                         $.each(this.children, createNode, [branch])\r
40                                 }\r
41                         }\r
42                 }\r
43                 $.each(response, createNode, [child]);\r
44         $(container).treeview({add: child});\r
45     });\r
46 }\r
47 \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
52         }\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
57                 collapsed: true,\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
62                                 childList.empty();\r
63                                 load(settings, this.id, childList, container);\r
64                         }\r
65                         if (userToggle) {\r
66                                 userToggle.apply(this, arguments);\r
67                         }\r
68                 }\r
69         }));\r
70 };\r
71 \r
72 })(jQuery);