Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1167519

    Hi there,

    I found an old thread with some JS modifications to randomize testimonials upon page load, but it doesn’t seem to be working. The testimonials continue to display in the same order that they were loaded.

    Can you see if this code is still valid and diagnose what I may be doing wrong, please?

    This is my JS code, which I modified enfold/config-templatebuilder/avia-shortcodes/testimonials/testimonials.js:

    (function($)
    { 
    	"use strict";
    	
    	// -------------------------------------------------------------------------------------------
    	// testimonial shortcode javascript
    	// -------------------------------------------------------------------------------------------
    	$.fn.shuffle = function() {
    
    	var allElems = this.get(),
    		getRandom = function(max) {
    			return Math.floor(Math.random() * max);
    		},
    		shuffled = $.map(allElems, function(){
    			var random = getRandom(allElems.length),
    				randEl = $(allElems[random]).clone(true)[0];
    			allElems.splice(random, 1);
    			return randEl;
    	   });
    
    	this.each(function(i){
    		$(this).replaceWith($(shuffled[i]));
    	});
    
    	return $(shuffled);
    
    };
    	
    	$.fn.avia_sc_testimonial = function(options)
    	{
    		return this.each(function()
    		{
    			var container = $(this), elements = container.find('.avia-testimonial');
    			$('.avia-testimonial').shuffle();
    
    	
    	
    			//trigger displaying of thumbnails
    			container.on('avia_start_animation', function()
    			{
    				elements.each(function(i)
    				{
    					var element = $(this);
    					setTimeout(function(){ element.addClass('avia_start_animation') }, (i * 150));
    				});
    			});
    		});
    	}
    	
    }(jQuery));
    
    #1167529

    Hi all,

    Looks like this is working now. Feel free to close the thread. Thank you!

    #1167633

    Hi,

    If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Randomize testimonials’ is closed to new replies.