Some thoughts:
- Don't continually re-query the DOM. Cache your control and slide elements in a variable your you don't need to spend time re-querying for them.
- You don't need to maintain state around `clickedSlider` condition. Consider using `clearInterval()` instead as more "proper" way to manage interval functionality.
- Consider breaking apart your `autoSlide()` function into it's key parts - one function for managing the current slide index and another for actually performing the action of making slide at given index "active". This gives you more code re-use in giving the to give capability to jump directly to a slide at a given index as is needed in your control click handler.
- Do you really a data properties for your controls and slides? If there is a 1-to-1 relationship between the slides and the controls and their ordering in DOM is the same, you should be able to know the control at index X relates to the slide at index X.
This might give you code more like:
$(document).ready(function(){
var $testimonialSlides = $('.testimonial-slider-slides a');
var $testimonialControls = $('.testimonial-slider-controls a');
var slideCount = $testimonialSlides.length;
var slideIndex = 0;
function activateSlide(idx) {
$testimonialSlides
.removeClass('active')
.eq(idx).addClass('active');
$testimonialControls
.removeClass('active')
.eq(idx).addClass('active');
}
function autoSlide(){
slideIndex++;
if (slideIndex === slideCount) {
slideIndex = 0;
}
activateSlide(slideIndex);
}
var autoslideInterval = window.setInterval(autoslide, 2000);
$testimonialControls.click(function(e){
e.preventDefault();
window.clearInterval(autoslideInterval);
var idx = $testimonialControls.index(this);
activateSlide(idx);
});
});
You may also consider building this as a proper jQuery plug-in or class (though not shown in my example above). This would allow you to better encapsulate state of the slider functionality, such that state would not need to be held in main `$(document).ready()` scope. This also potentially makes this simple functionality re-usable in the future - just pass in config for DOM selectors, and interval time.
Why have superfluous comments? If you code is well-written with meaningful function and variables names (I think you do a good job of this), then should not need such comments.