I'm currently using Isotope to filter a directory list with combination filters and multiple selections. I have been using this example as a guideline:
This has been a really great example of exactly what I want to do, except for one thing. When the checkbox's are clicked the "all" checkbox is automatically unchecked. But when all of the checkboxes are unchecked I want the "all" checkbox to become checked again. Basically if no checkbox is checked then no filter is being applied and all of the items are shown. So I'm trying to make sure in all situations that the checkboxes reflect the accurate state of the filter.
In the example above here is how the checkbox checking is handled:
function manageCheckbox( $checkbox ) {
var checkbox = $checkbox[0];
var group = $checkbox.parents('.option-set').attr('data-group');
// create array for filter group, if not there yet
var filterGroup = filters[ group ];
if ( !filterGroup ) {
filterGroup = filters[ group ] = [];
}
var isAll = $checkbox.hasClass('all');
// reset filter group if the all box was checked
if ( isAll ) {
delete filters[ group ];
if ( !checkbox.checked ) {
checkbox.checked = 'checked';
}
}
// index of
var index = $.inArray( checkbox.value, filterGroup );
if ( checkbox.checked ) {
var selector = isAll ? 'input' : 'input.all';
$checkbox.siblings( selector ).removeAttr('checked');
if ( !isAll && index === -1 ) {
// add filter to group
filters[ group ].push( checkbox.value );
}
} else if ( !isAll ) {
// remove filter from group
filters[ group ].splice( index, 1 );
// if unchecked the last box, check the all
if ( !$checkbox.siblings('[checked]').length ) {
$checkbox.siblings('input.all').attr('checked', 'checked');
}
}
}
I need some jquery help here. How could the isAll variable check the data-group to see if nothing is checked and check all as a default?
Aucun commentaire:
Enregistrer un commentaire