Skip to content

Instantly share code, notes, and snippets.

@vzaremba
Created November 13, 2013 10:26
Show Gist options
  • Save vzaremba/7446865 to your computer and use it in GitHub Desktop.
Save vzaremba/7446865 to your computer and use it in GitHub Desktop.
$(function(){
var $all = $('#selectAllButton input[type="radio"]').change(function () {
$sectionchecks.prop('checked', true).trigger('change');
$none.closest('label').removeClass('c_on');
});
var $none = $('#selectNoneButton input[type="radio"]').change(function () {
$sectionchecks.prop('checked', false).trigger('change');
$all.closest('label').removeClass('c_on');
});
$('.section .checkbox input').click(function () {
$(this).closest('.section').find('.subsection input[type="checkbox"]').prop('checked', this.checked).trigger('change')
});
$('.section .subsection input').on('change', function () {
var parent = $(this).closest('.section'),
status = parent.find('.subsection input[type="checkbox"]').not(':checked').length === 0;
parent.find('.optional').prop('checked', status);
}).trigger('change');
var $sectionchecks = $('.section').find('input[type="checkbox"]');
$sectionchecks.add($none).add($all).change(function(){
$(this).closest('label').toggleClass('c_on', this.checked);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment