I have four tabs, that when each one is clicked will display up a different gallery (Nextgen Pro gallery).
It works, but the performance is terrible, because I currently load EVERYTHING. I want to change it to load only when a tab is clicked so instead of loading up to 200 images in one hit, I will only load up 50 images at a time.
Currently my scripts to achieve this tab and display function is as follows (JavaScript);
jQuery(document).ready(function() {
if (jQuery('.customtabs > br').length) {
jQuery('.customtabs > br').remove();
}
});
function displaycustom_tab(obj) {
var totalSlides = jQuery(obj).parent().find('>div').length / 3;
var tabi = 0;
var slidei = jQuery(obj).index() + 1;
if (slidei > (2 * totalSlides)) {
tabi = slidei - (2 * totalSlides);
} else if (slidei > (totalSlides)) {
tabi = slidei - totalSlides;
} else {
tabi = slidei;
}
tabi--;
jQuery('.customtabs > div').removeClass('activetab');
jQuery('.customtabs > div:eq(' + tabi + ')').addClass('activetab');
jQuery(window).trigger('resize');
}
Each tab has an img class named ".imgslide" and every time I click on one, the tab becomes active (the other 3 are hidden) and it's gallery (".customtabs") is displayed. I'm not even sure if it's an efficient way of doing it.
I created a further script to use AJAX:
jQuery(document).on( 'click', '.img.imgslide', function( event ) {
console.log("ajax call worked");
event.preventDefault();
jQuery.ajax({
url: loadgallery.ajaxurl,
type: 'post',
data: {
action: 'load_gallery'
},
success: function( result ) {
alert( result );
}
})
})
Nothing happens, including the console.log.
I've read these posts, but I am not sure how to go about doing either of them.
https://stackoverflow.com/questions/502391 https://stackoverflow.com/questions/3818063
I got the code source from this wordpress tutorial;
https://premium.wpmudev.org/blog/load-posts-ajax
I appreciate any help I can get.
EDIT 1
I guess the functionality I am after is similar to this.
Edit 2
Thank you @Vel for pointing out the syntax issue. The script loads up - but I am not sure it does anything.
I can see this being very...data heavy unless I can implement a way use the ajax code once per tab.
Even with the AJAX code, all images load on "page load". How can I prevent this?