Compare commits
No commits in common. "main" and "js-01" have entirely different histories.
|
@ -18,8 +18,9 @@
|
||||||
* @package Oficina_de_Suport_theme
|
* @package Oficina_de_Suport_theme
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if( ! function_exists( 'ofisuport_ajuts_filters_form') ) {
|
if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
|
||||||
function ofisuport_ajuts_filters_form() {
|
function ofisuport_ajuts_filters_form() {
|
||||||
?>
|
?>
|
||||||
<div id="archive-filters" class="ofisuport-filters">
|
<div id="archive-filters" class="ofisuport-filters">
|
||||||
|
@ -46,9 +47,8 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form') ) {
|
||||||
|
|
||||||
// check for values in url and get value if available
|
// check for values in url and get value if available
|
||||||
if( isset($_GET[ $fieldname ]) ) {
|
if( isset($_GET[ $fieldname ]) ) {
|
||||||
|
|
||||||
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
$filteredvalues['value'] = explode(',', $_GET[ $fieldname ]);
|
||||||
} else {
|
|
||||||
$filteredvalues['value'] = [];
|
|
||||||
};
|
};
|
||||||
//end check for values in url
|
//end check for values in url
|
||||||
|
|
||||||
|
@ -56,12 +56,17 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form') ) {
|
||||||
if( $fieldname == $fields['name']) {
|
if( $fieldname == $fields['name']) {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<section id="fund-filter fund-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
<section id="fund-filter-<?php echo $fields['name']; ?>" class="<?php echo $fields['name']; ?>">
|
||||||
<h5 class="oficinasuport-titol-opcions"><?php echo $fields['label'];?></h5>
|
<h5><?php echo $fields['label'];?></h5>
|
||||||
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
||||||
|
|
||||||
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
||||||
<input class="ofisuport-filter" type="checkbox" name="<?php echo $fields['name'];?>" <?php if( in_array( $choicevalue, $filteredvalues['value']) ) { echo 'checked'; } ?> value="<?php echo $choicevalue; ?>" />
|
<input
|
||||||
|
class="ofisuport-filter"
|
||||||
|
type="checkbox"
|
||||||
|
<?php if( in_array($choicevalue,$filteredvalues['value']) ) { echo 'checked';}; ?>
|
||||||
|
value="<?php echo $choicevalue ?>"
|
||||||
|
name="<?php echo $fields['name'];?>" />
|
||||||
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -79,94 +84,67 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form') ) {
|
||||||
<?php }; //end if type checkbox ?>
|
<?php }; //end if type checkbox ?>
|
||||||
|
|
||||||
<?php }; //end foreach groupkey field ?>
|
<?php }; //end foreach groupkey field ?>
|
||||||
<?php //echo '<p><span id="filterlink"></span></p>';?>
|
<p><b>Results:</b> <span id="results"></span></p>
|
||||||
<p><a id="submitfilteredlink" name="submit-ajut" class="button button-more" href="">enviar</a> </p>
|
<button type="button" name="submit-ajut" class="button-more">enviar</button>
|
||||||
</form>
|
</form>
|
||||||
<?php //close the form and subit ?>
|
<?php //close the form and subit ?>
|
||||||
|
|
||||||
<?php }; //end if groupkey ?>
|
<?php }; //end if groupkey ?>
|
||||||
<aside id="search-form-ajuts" class="ofisuport-search-ajuts">
|
|
||||||
<?php
|
|
||||||
// search form for custom post type 'oficinasuport-ajut'
|
|
||||||
// <input type="hidden" value="ofisuport-ajut" name="post_type" id="post_type" />
|
|
||||||
// https://developer.wordpress.org/reference/functions/get_search_form/#comment-369
|
|
||||||
// https://wordpress.stackexchange.com/questions/313037/restrict-a-sear ch-to-a-custom-post-type
|
|
||||||
?>
|
|
||||||
<form class="ofisuport-search-form" role="search" method="get" action="/">
|
|
||||||
<label class="screen-reader-text" for="search">Search in ajuts</label>
|
|
||||||
<input type="search" id="search" class="search-field" placeholder="cerca amb paraula clau..." value="<?php the_search_query(); ?>" name="s" />
|
|
||||||
<input type="submit" id="searchsubmit" class="search-submit" value="cerca">
|
|
||||||
<span class="ofisuport-search-submit ofisuport-icon-search"></span>
|
|
||||||
<input type="hidden" value="ofisuport-ajut" name="post_type" id="post_type" />
|
|
||||||
</form>
|
|
||||||
</aside>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
// change
|
// change
|
||||||
$('#archive-filters').on('click', 'input', function(){
|
$('#archive-filters').on('change', 'input[type="checkbox"]', function(){
|
||||||
|
|
||||||
// vars
|
// vars
|
||||||
var url = '<?php echo home_url('ajuts/'); ?>';
|
var url = '<?php echo home_url('ajuts/'); ?>';
|
||||||
args = {};
|
args = {};
|
||||||
var appendtoURL = '';
|
|
||||||
var eachfiltered = '';
|
|
||||||
var valueschecked = '';
|
|
||||||
|
|
||||||
// loop over filters
|
// loop over filters
|
||||||
$('#archive-filters .filter').each(function(){
|
$('#archive-filters .filter').each(function(){
|
||||||
// check if is first appearance of each
|
urldos = url;
|
||||||
if( eachfiltered != $(this).data('filter') ){
|
// vars
|
||||||
// save already calculated field=val01,val02,val03
|
var filteredajuts = $(this).data('filter'),
|
||||||
if( eachfiltered != '' && valueschecked != '' ){
|
vals = [],
|
||||||
// remove last ','
|
allvalueschecked = '';
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
};
|
|
||||||
// start new fieldname filtered
|
|
||||||
eachfiltered = $(this).data('filter');
|
|
||||||
// reset values
|
|
||||||
valueschecked = '';
|
|
||||||
// find checked inputs
|
// find checked inputs
|
||||||
$(this).find('input:checked').each(function(){
|
$(this).find('input:checked').each(function(){
|
||||||
// if not empty save value and ,
|
vals.push( $(this).val() );
|
||||||
if( $(this).val() != '' ){
|
var thisvaluechecked = $(this).val();
|
||||||
valueschecked += $(this).val() + ',';
|
allvalueschecked += thisvaluechecked + ',';
|
||||||
};
|
urldos += filteredajuts;
|
||||||
});
|
alert( urldos +"=" +allvalueschecked);
|
||||||
//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 ','
|
// append to args
|
||||||
valueschecked = valueschecked.slice(0, -1);
|
args[ filteredajuts ] = vals.join(',');
|
||||||
// save last cycled filtered value already calculated field=val01,val02,val03
|
|
||||||
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
|
||||||
|
|
||||||
// remove last &
|
});
|
||||||
appendtoURL = appendtoURL.slice(0, -1);
|
|
||||||
|
|
||||||
// update url
|
// update url
|
||||||
url += '?' +appendtoURL;
|
url += '?';
|
||||||
|
|
||||||
// show or modify the url
|
// loop over args
|
||||||
//alert( url );
|
$.each(args, function( name, value ){
|
||||||
//$('#filterlink').text(url);
|
url += name + '=' + value + '&';
|
||||||
|
});
|
||||||
|
|
||||||
// convert a href url to new value
|
|
||||||
$('#submitfilteredlink').attr('href',url);
|
|
||||||
|
// remove last &
|
||||||
|
url = url.slice(0, -1);
|
||||||
|
|
||||||
|
// reload page
|
||||||
|
$('#archive-filters button').on('click', function () {
|
||||||
|
alert( "estoy en: " +url );
|
||||||
|
//window.location.replace( url );
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -174,6 +152,6 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form') ) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}; //end ofisuport_ajuts_filters_form
|
}; //end ofisuport_display_filters()
|
||||||
}; // end if ! functions_exists
|
endif; // end if ! functionexists
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue