var ElementCheckboxTree = (function () { var checkboxTree = function() { this.initialize.apply(this, arguments); }; checkboxTree.defaultOptions = { elementId: undefined, linksClass: undefined }; checkboxTree.prototype = { initialize: function (options) { var that = this; this.options = $.extend({}, checkboxTree.defaultOptions, options); this.element = $('#' + this.options.elementId); this.links = this.element.find('.' + this.options.linksClass + ':first'); if (this.element.size() && this.links.size()) { this.links.find('li>a').bind('click.checkboxTree', function () { that.onLinkClick.apply(that, arguments); }); } return this; }, onLinkClick: function (e) { var target = $(e.currentTarget); if (target.hasClass('checkAll')) { e.preventDefault(); this.element.find(':checkbox').attr('checked', 'checked'); } else if (target.hasClass('uncheckAll')) { e.preventDefault(); this.element.find(':checkbox').removeAttr('checked'); } return this; } }; return checkboxTree; })();