var App_Product_Tree = qs.createObject(); App_Product_Tree.prototype = { _defOptions : { collapsed: false, animated: "medium", control: "#sidetreecontrol", persist: "location" }, _options: null, initialize: function (options) { this._options = $.extend(this._defOptions, {}, options); this.build(); }, build: function () { $("#tree").treeview(this._options); this.initControls(); }, initControls: function () { var that = this; var links = $(this._options.control + ' [data-tree-action]'); if (links.size()) { $(links).bind('click.checkboxTree', function () { that.onLinkClick.apply(that, arguments); }); } }, onLinkClick: function (e) { e.preventDefault(); var target = $(e.currentTarget); var action = $(target).data('tree-action'); var tree = $('#tree'); switch (action) { case 'expandAll': $(tree).data('toggler').apply( $('div.hitarea', tree).filter(function() { return $(this).parent('.expandable').length; }) ); break; case 'collapseAll': $(tree).data('toggler').apply( $('div.hitarea', tree).filter(function() { return $(this).parent('.collapsable').length; }) ); break; } } };