Skip to content

Instantly share code, notes, and snippets.

@jacksonhoose
Created July 3, 2014 19:10
Show Gist options
  • Save jacksonhoose/7b0cfcf66b490d65626e to your computer and use it in GitHub Desktop.
Save jacksonhoose/7b0cfcf66b490d65626e to your computer and use it in GitHub Desktop.
checkbox toggle
var checkBoxToggle = {
init: function() {
this.checkBoxes = $('#showUnread, #showArchived');
this.tableBodies = $('div.dashboard-table tbody');
this.bindChange();
},
bindChange: function() {
this.checkBoxes.on('change', this.changeEvent.bind(this));
},
changeEvent: function(e) {
var checked = this.checkBoxes.filter(':checked');
var classes = [];
this.tableBodies.show();
if(checked.length) {
$.each(checked, function() {
classes.push('.' + $(this).attr('id').split('show').pop().toLowerCase());
});
this.tableBodies.not($(classes.join(', '))).hide();
}
}
};
checkBoxToggle.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment