Skip Navigation

[Resolved] jquery after pagination is completed – too slow

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by Juan 6 years, 4 months ago.

Assisted by: Juan.

Author
Posts
#945871

I've built a custom posts view, with a button for a popup for each item in the view.
it all worked fine until i tried to turn the view into a slider.

this is the JS:

jQuery(document).ready(function( $ ){

  //this is for making the modal widow draggable//
  
  $( function() {
    $( ".modal-content" ).draggable();
  });

  //this is for making single radio inputs vertically aligned properly (vs. double radio inputs) - in two different places//
  
  $('.productdetails .alg_variations_table').each(function() {
    if($(this).find('tr').length < 2) {
        $(this).css("margin-top", "10px");
    }
});
  
    $('.relatedproducts .productdetails .alg_variations_table').each(function() {
    if($(this).find('tr').length < 2) {
        $(this).css("margin-top", "6px");
    }
});


//this if for popping up the modal//
      
$("a[data-toggle=modal]").click(function() {
  $(this).parent().find('.modal').toggleClass('seemodal');
  });
  

//this is for closing the modal by pressing the close button//

$(".iziModal-button-close").click(function() {
  $(this).closest('.modal').toggleClass('seemodal');
  }); 
  

//this is for closing the popup when pressing esc//

$(document).keydown(function(e){

        if(e.keyCode == 27) {
            $('.modal').removeClass('seemodal');
        }
  });
            

//basically each item has either 1 image or two images. 2 images are swapped on hover. this is to make sure when there's only 1 image, there want be an attempt to swap//

  $(".col-sm-4 .vgw-item-i").mouseover(function() {
      function isEmpty( el ){
      return !$.trim(el.html())
  }
    if (isEmpty($(this).find(".second"))) {
    $(this).find(".primary_image").css({"opacity": "1", "animation": "none"});
    $(this).find(".second img").css({"opacity": "0", "transition": "none", "-o-transition": "none", "-moz-transition": "none"});
    $(this).find(".second").css("opacity", "0");
  }
}); 

});

I tried cloning this code and putting it ALSO between:

jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
});

It does the job, but WAY too slowly. and sometimes it gets stuck.

you can see here:

hidden link

any ideas on how i'm making this flow more easily?

thanks!
ido

#948096

as a temp solution i built a jquery slider from scratch to allow me to implement two such sliders in one page.
but i still need to figure out how to do it with toolset - it seems like 2 paginated views in 1 page isn't that great.

here's the slider code if anyone needs. customize as you wish:

jQuery(document).ready(function( $ ){
  
  var sliderwidth = $(".desktop .wpb_wrapper .idoslider").width();
  $(".desktop .wpb_wrapper .idoslider .idoslideritem").css("width", sliderwidth/3);
  var firstpos = sliderwidth*2;
  $(".desktop .wpb_wrapper .idoslider .sliderin").css({ "width": sliderwidth*3, "left": -firstpos });
  
                                                      
  
  $(".desktop .wpb_wrapper .idopagination .nexter").click(function() {
    
    var movewidth = sliderwidth/3;
    var leftend = movewidth*6-1;
 
       $(this).parent().parent().find(".js-wpv-view-layout .sliderin").animate({ "left": "+=" + movewidth }, "slow", function() {
        var pos = $(this).position();
    if(pos.left > -movewidth) {
      $(this).parent().parent().parent().find(".nexter").css("pointer-events", "none")
      $(this).parent().parent().parent().find(".nexter img").css("filter", "grayscale(100%)")
    }
        else {
          $(this).parent().parent().parent().find(".nexter").css("pointer-events", "initial")
          $(this).parent().parent().parent().find(".nexter img").css("filter", "none")
        }
      if(pos.left < -leftend) {
      $(this).parent().parent().parent().find(".prever").css("pointer-events", "none")
        $(this).parent().parent().parent().find(".prever img").css("filter", "grayscale(100%)")
    }
        else {
          $(this).parent().parent().parent().find(".prever").css("pointer-events", "initial")
          $(this).parent().parent().parent().find(".prever img").css("filter", "none")
        }

  });
});

      $(".desktop .wpb_wrapper .idopagination .prever").click(function() {
        
            var movewidth = sliderwidth/3;
            var leftend = movewidth*6-1;
        
     $(this).parent().parent().find(".js-wpv-view-layout .sliderin").animate({ "left": "-=" + movewidth }, "slow", function() {
                var posp = $(this).position();
    if(posp.left > -movewidth) {
      $(this).parent().parent().parent().find(".nexter").css("pointer-events", "none")
      $(this).parent().parent().parent().find(".nexter img").css("filter", "grayscale(100%)")
    }
        else {
          $(this).parent().parent().parent().find(".nexter").css("pointer-events", "initial")
          $(this).parent().parent().parent().find(".nexter img").css("filter", "none")
        }
     if(posp.left < -leftend) {
      $(this).parent().parent().parent().find(".prever").css("pointer-events", "none")
       $(this).parent().parent().parent().find(".prever img").css("filter", "grayscale(100%)")
    }
        else {
          $(this).parent().parent().parent().find(".prever").css("pointer-events", "initial")
          $(this).parent().parent().parent().find(".prever img").css("filter", "none")
        }

  });
  });
   
  });
#948216

Juan
Supporter

Timezone: Europe/Madrid (GMT+01:00)

Hi Ido

Thanks for the feedback.

Mmmm I do nto see any reason why your initial code should take that much to be executed after the Views AJAX pagination has completed. I mean, it is applyign the same as in your first pageload.

However, I see that we can have some room for improvements. In your initial code, you are attaching some calbacks to some events triggered over some elements. When the View paginates, those elements are removed and replaced by new items, hence you seem to need to re-enable those event calbacks on them. Well, you do not really need to, if you attach the events callbacks a little differently. That would at least allow you to avoid the click and mouseover callbacks re-addition:
https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements

Now, we can not avoid the part about initializing the draggable thing (which will probably be the most expensive operation in all the code) or the CSS adjustments, but at least avoid some expensive operations.

Hope it helps.

Regards.