Problem:
When a paginated view is loaded via ajax, pagination does not work because the javascript is run on document ready and the variables needed to initialize the script are loaded through a script echoed via a wp_footer hook.
Working Solution:
For the script to run, wrap the code in a global function and call it on document ready, allowing ajax plugins to execute the pagination script on demand for newly loaded content, possibly taking into account a selector context.
function wpv_pagination(context) {
context = context || document;
// Preload images in paginator initially
jQuery('.wpv-pagination-preload-images', context).css('visibility', 'hidden');
wpv_pagination_init_preload_images();
jQuery('.wpv-pagination-preload-pages', context).each(function(){
var view_number = jQuery(this).attr('id').substring(16);
var max_pages = jQuery('#wpv_paged_max-'+view_number, context).val();
wpv_pagination_preload_pages(view_number, 1, max_pages, false, true);
});
// Move the wpv_view_hash, wpv_paged_max and wpv_widget_view_id from the forms as it's only needed during ajax pagination
jQuery('input[name=wpv_view_hash], input[name=wpv_paged_max], input[name=wpv_widget_view_id]', context).each(function(index) {
jQuery(this).parent().after(this);
});
}
jQuery(document).ready(function(){
wpv_pagination();
}
For the initializing variables, instead of adding a <script> in the footer to initialize these variables, you should use the following code to initialize them in WP_Views->init() right after declaring the pagination script:
wp_localize_script( 'views-pagination-script', 'wpv_admin_ajax_url', admin_url('admin-ajax.php'));
wp_localize_script( 'views-pagination-script', 'wpv_ajax_pagination_url', $ajax_url );
I hope this fix is incorporated in a near WPViews release.
Cheerz.
Dear Ioannis
I was able to reproduce your issue and I forward the information to the developers.
Thank you for a detailed report.
Regards,
Caridad