Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-cannon/5833678 to your computer and use it in GitHub Desktop.
Save michael-cannon/5833678 to your computer and use it in GitHub Desktop.
Filter testimonials_widget_testimonials_js example
add_filter( 'testimonials_widget_testimonials_js', array( &$this, 'next_testimonial' ), 10, 4 );
public function next_testimonial( $scripts, $testimonials, $atts, $widget_number ) {
$next_button = $atts['next_button'];
$refresh_interval = $atts['refresh_interval'];
if ( $next_button ) {
$id = Testimonials_Widget::ID;
$id_base = $id . $widget_number;
$key = "nextTestimonial{$widget_number}";
$javascript = <<<EOF
<script type="text/javascript">
function nextTestimonial{$widget_number}ignoreHover() {
var active = jQuery('.{$id_base} .active');
var next = (jQuery('.{$id_base} .active').next().length > 0) ? jQuery('.{$id_base} .active').next() : jQuery('.{$id_base} .testimonials-widget-testimonial:first');
active.fadeOut(1250, function(){
active.removeClass('active');
next.fadeIn(500);
next.removeClass('display-none');
next.addClass('active');
});
}
jQuery(document).ready( function(){
jQuery('.next{$widget_number}').click( function() {
nextTestimonial{$widget_number}ignoreHover();
clearInterval( nextTestimonial{$widget_number}interval );
nextTestimonial{$widget_number}interval = setInterval('nextTestimonial{$widget_number}()', {$refresh_interval} * 1000);
})
});
</script>
EOF;
$scripts[ $key ] = $javascript;
}
return $scripts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment