]> git.stg.codes - stg.git/blobdiff - doc/help/xslt/webhelp/docs/common/jquery/treeview/jquery.treeview.async.js
DocBook documentation stub added
[stg.git] / doc / help / xslt / webhelp / docs / common / jquery / treeview / jquery.treeview.async.js
diff --git a/doc/help/xslt/webhelp/docs/common/jquery/treeview/jquery.treeview.async.js b/doc/help/xslt/webhelp/docs/common/jquery/treeview/jquery.treeview.async.js
new file mode 100644 (file)
index 0000000..2597dde
--- /dev/null
@@ -0,0 +1,72 @@
+/*\r
+ * Async Treeview 0.1 - Lazy-loading extension for Treeview\r
+ * \r
+ * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/\r
+ *\r
+ * Copyright (c) 2007 Jörn Zaefferer\r
+ *\r
+ * Dual licensed under the MIT and GPL licenses:\r
+ *   http://www.opensource.org/licenses/mit-license.php\r
+ *   http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * Revision: $Id$\r
+ *\r
+ */\r
+\r
+;(function($) {\r
+\r
+function load(settings, root, child, container) {\r
+       $.getJSON(settings.url, {root: root}, function(response) {\r
+               function createNode(parent) {\r
+                       var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);\r
+                       if (this.classes) {\r
+                               current.children("span").addClass(this.classes);\r
+                       }\r
+                       if (this.expanded) {\r
+                               current.addClass("open");\r
+                       }\r
+                       if (this.hasChildren || this.children && this.children.length) {\r
+                               var branch = $("<ul/>").appendTo(current);\r
+                               if (this.hasChildren) {\r
+                                       current.addClass("hasChildren");\r
+                                       createNode.call({\r
+                                               text:"placeholder",\r
+                                               id:"placeholder",\r
+                                               children:[]\r
+                                       }, branch);\r
+                               }\r
+                               if (this.children && this.children.length) {\r
+                                       $.each(this.children, createNode, [branch])\r
+                               }\r
+                       }\r
+               }\r
+               $.each(response, createNode, [child]);\r
+        $(container).treeview({add: child});\r
+    });\r
+}\r
+\r
+var proxied = $.fn.treeview;\r
+$.fn.treeview = function(settings) {\r
+       if (!settings.url) {\r
+               return proxied.apply(this, arguments);\r
+       }\r
+       var container = this;\r
+       load(settings, "source", this, container);\r
+       var userToggle = settings.toggle;\r
+       return proxied.call(this, $.extend({}, settings, {\r
+               collapsed: true,\r
+               toggle: function() {\r
+                       var $this = $(this);\r
+                       if ($this.hasClass("hasChildren")) {\r
+                               var childList = $this.removeClass("hasChildren").find("ul");\r
+                               childList.empty();\r
+                               load(settings, this.id, childList, container);\r
+                       }\r
+                       if (userToggle) {\r
+                               userToggle.apply(this, arguments);\r
+                       }\r
+               }\r
+       }));\r
+};\r
+\r
+})(jQuery);
\ No newline at end of file