The CheckAll plugin for MooTools 1.2 makes it easy to create a “Check All” checkbox on a tabled list of items. This feature is a very simple addition to any system needing to manage multiple items at once.
View the demo:
http://nak5.com/demos/checkall
Usage:
It’s as easy as…
window.addEvent('domready', function(){
new CheckAll($$('input.checkones'), $('checkall'));
});
The CheckAll class:
var CheckAll = new Class({
checks: [],
checkall: null,
initialize: function(chks, chka){
this.checks = $$(chks);
this.checkall = $(chka);
if (this.checks.length > 0){
this.checkall.addEvent('click', function(){
this.checks.each(function(el){
el.checked = this.checkall.checked;
}, this);
}.bindWithEvent(this));
this.checks.each(function(el){
el.addEvent('click', function(){
this.checkall.checked = this.checks.every(function(el){
return el.checked;
});
}.bindWithEvent(this));
}, this);
} else this.checkall.disabled = true;
}
});