69 lines
2.4 KiB
JavaScript
69 lines
2.4 KiB
JavaScript
|
// https://stackoverflow.com/a/12025482
|
||
|
jQuery(document).ready(function($) {
|
||
|
// change
|
||
|
$('#archive-filters').on('click', 'input', function(){
|
||
|
|
||
|
// vars
|
||
|
var url = '<?php echo home_url('ajuts/'); ?>';
|
||
|
args = {};
|
||
|
var appendtoURL = '';
|
||
|
var eachfiltered = '';
|
||
|
var valueschecked = '';
|
||
|
|
||
|
// loop over filters
|
||
|
$('#archive-filters .filter').each(function(){
|
||
|
// check if is first appearance of each
|
||
|
if( eachfiltered != $(this).data('filter') ){
|
||
|
// save already calculated field=val01,val02,val03
|
||
|
if( eachfiltered != '' && valueschecked != '' ){
|
||
|
// remove last ','
|
||
|
valueschecked = valueschecked.slice(0, -1);
|
||
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||
|
};
|
||
|
// start new fieldname filtered
|
||
|
eachfiltered = $(this).data('filter');
|
||
|
// reset values
|
||
|
valueschecked = '';
|
||
|
// find checked inputs
|
||
|
$(this).find('input:checked').each(function(){
|
||
|
// if not empty save value and ,
|
||
|
if( $(this).val() != '' ){
|
||
|
valueschecked += $(this).val() + ',';
|
||
|
};
|
||
|
});
|
||
|
//alert( appendtoURL +":" +eachfiltered +"=" +valuescheked);
|
||
|
} else {
|
||
|
// we have previous values checked
|
||
|
// find checked inputs
|
||
|
//if( $(this).val() != '' ){
|
||
|
// if not empty append value and ,
|
||
|
$(this).find('input:checked').each(function(){
|
||
|
valueschecked += $(this).val() + ',';
|
||
|
});
|
||
|
//alert( appendtoURL +":not:" +eachfiltered +"=" +valuescheked);
|
||
|
//};
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// remove last ','
|
||
|
valueschecked = valueschecked.slice(0, -1);
|
||
|
// save last cycled filtered value already calculated field=val01,val02,val03
|
||
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||
|
|
||
|
// remove last &
|
||
|
appendtoURL = appendtoURL.slice(0, -1);
|
||
|
|
||
|
// update url
|
||
|
url += '?' +appendtoURL;
|
||
|
|
||
|
// show or modify the url
|
||
|
//alert( url );
|
||
|
//$('#filterlink').text(url);
|
||
|
|
||
|
// convert a href url to new value
|
||
|
$('#submitfilteredlink').attr('href',url);
|
||
|
|
||
|
});
|
||
|
|
||
|
})
|