forked from jlbruno/jQuery-Tristate-Checkbox-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.tristate.min.js
4 lines (4 loc) · 1.25 KB
/
jquery.tristate.min.js
1
2
3
4
/*! jQuery Tristate Checkbox - v1.0.1 - 2012-12-04
* http://jlbruno.github.com/jQuery-Tristate-Checkbox-plugin/
* Copyright (c) 2012 Jeff Leombruno; Licensed MIT, GPLv2 */
(function(b){b.fn.tristate=function(h){var a={selector:b(this).selector,checked:null,container:null,siblings:null,wrappers:[]};b.extend(a,h);return this.each(function(){var d=b(this),e={init:function(){b('input[type="checkbox"]',d).change(function(){a.checked=b(this).prop("checked");a.container=b(this).closest("li");a.siblings=a.container.siblings();a.container.find('input[type="checkbox"]').prop({indeterminate:!1,checked:a.checked});e.checkSiblings(a.container)});b("input[type=checkbox]:checked", d).trigger("change")},checkSiblings:function(d){var c=d.parent().parent(),g=!0,f=function(d){var c=d;b.each(a.wrappers,function(a,b){c=c.children(b)});return c.children('input[type="checkbox"]')};d.siblings().each(function(){return g=f(b(this)).prop("checked")===a.checked});g&&a.checked?(f(c).prop({indeterminate:!1,checked:a.checked}),e.checkSiblings(c)):g&&!a.checked?(f(c).prop("checked",a.checked),f(c).prop("indeterminate",0<c.find('input[type="checkbox"]:checked').length),e.checkSiblings(c)):f(d.parents("li")).prop({indeterminate:!0, checked:!1})}};e.init();e.checkSiblings(d)})}})(jQuery);