moved jQueries to plugin into files, enqueued inside wordpress

This commit is contained in:
jorge 2024-01-14 20:14:43 +01:00
parent 3b51d6e786
commit 02d003934c
8 changed files with 201 additions and 3 deletions

View File

@ -15,4 +15,10 @@
* css styles
*
*/
/*
.xarxaprod-filtered-funds .os_fund_target .filter,
.xarxaprod-filtered-funds .os_fund_source .filter,
.xarxaprod-filtered-funds .os_fund_field .filter {
display: none;
}
*/

View File

@ -103,8 +103,8 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
</div>
<script type="text/javascript">
(function($) {
// https://stackoverflow.com/a/12025482
// change
$('#archive-filters').on('click', 'input', function(){
@ -173,6 +173,7 @@ if( ! function_exists( 'xarxaprod_ajuts_filters_form') ) {
})(jQuery);
</script>
<?php
}; //end xarxaprod_ajuts_filters_form
}; // end if ! functions_exists

View File

@ -0,0 +1,31 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists('xarxaprod_plugin_scripts') ){
function xarxaprod_plugin_scripts() {
wp_enqueue_script(
'xarxaprod-plugin-title-filter-toggle',
plugins_url( 'includes/xarxaprod-title-filter-toggle.js', dirname( __FILE__ ) ),
array( 'jquery' ),
XARXAPROD_WPPLUGIN_VERSION,
true
);
// wp_enqueue_script(
// 'xarxaprod-plugin-ajut-filter-set',
// plugins_url( 'includes/xarxaprod-ajut-filter-set-form.js', dirname( __FILE__ ) ),
// array( 'jquery' ),
// XARXAPROD_WPPLUGIN_VERSION,
// true
// );
// wp_enqueue_script(
// 'xarxaprod-plugin-scripts',
// plugins_url( 'includes/xarxaprod-plugin-scripts.js', dirname( __FILE__ ) ),
// array( 'jquery' ),
// XARXAPROD_WPPLUGIN_VERSION,
// true
// );
}
add_action( 'wp_enqueue_scripts', 'xarxaprod_plugin_scripts' );
}

View File

@ -0,0 +1,68 @@
// 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);
});
})

View File

@ -0,0 +1,78 @@
// https://stackoverflow.com/a/12025482
// https://stackoverflow.com/a/48314274
jQuery(document).ready(function($) {
$('.fund-filter').ready(function() {
$('.xarxaprod-titol-opcions').click(function() {
$(this).siblings(".filter").toggle();
});
});
//})
// 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);
});
})

View File

@ -0,0 +1,10 @@
// https://stackoverflow.com/a/12025482
// https://stackoverflow.com/a/48314274
jQuery(document).ready(function($) {
$('.fund-filter').ready(function() {
$('.xarxaprod-titol-opcions').click(function() {
$(this).siblings(".filter").toggle();
});
});
})

View File

@ -10,7 +10,7 @@
* Plugin URI: https://git.hangar.org/xarxaprod/xarxaprod-wp-plugin
* Description: Different needs for the Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
* Date: 2023 12 29
* Version: 1.0.0
* Version: 1.1.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
* License: GPL 3.0
@ -40,6 +40,8 @@ if ( ! defined( 'WPINC' ) ) {
*/
define( 'XARXAPROD_WPPLUGIN_VERSION', '1.0.0' );
define( 'XARXAPROD_WPPLUGIN_BUILD_NUMBER', '1' );
/* *
* define Plugin path
* https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-1113
@ -70,3 +72,5 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-post-type-ajuts.php');
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter.php');
include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-ajuts-filter-function-frontend.php');
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');