neilgee
7/27/2016 - 6:14 AM

Using Tabslet for Tabs

Using Tabslet for Tabs


jQuery(document).ready(function($){
// Options ~> http://vdw.github.io/Tabslet/
  $('.tabs').tabslet({
    //active     :2,
    // mouseevent: 'click',
    // attribute  : 'href',
    // animation  : true
  });

});
<?php

add_shortcode( 'tab_content', 'themeprefix_tabbed_content' ); //Position the content with a shortcode [tab_content]

function themeprefix_tabbed_content() {
ob_start();

// My ACF Fields for reference
// tabs - field group
// tab_link - sub-field tab link
// tab_content - sub-field tab content
// check if the repeater field has rows of data

 	// loop through the rows of data
        // display a sub field value
echo '<div class="tabs">
        <ul class="horizontal">';
if( have_rows('tabs') ):
        $i = 1;
        while ( have_rows('tabs' ) ) : the_row();
echo '<li><a href="#tab-' . $i . '">' . get_sub_field( "tab_link" ) . '</a></li>';
        $i++;
        endwhile;
echo '</ul>';
        $i = 1;
        while ( have_rows('tabs') ) : the_row();
echo '<div id="tab-' . $i . '">' . get_sub_field( "tab_content" ) . '</div>';
        $i++;
        endwhile;
echo '</div>';
else :
    // no rows found
endif;

return ob_get_clean();
}
/**
 * Tabslet | tabs jQuery plugin
 *
 * @copyright Copyright 2015, Dimitris Krestos
 * @license   Apache License, Version 2.0 (http://www.opensource.org/licenses/apache2.0.php)
 * @link      http://vdw.staytuned.gr
 * @version   v1.7.2
 */

  /* Sample html structure

  <div class='tabs'>
    <ul class='horizontal'>
      <li><a href="#tab-1">Tab 1</a></li>
      <li><a href="#tab-2">Tab 2</a></li>
      <li><a href="#tab-3">Tab 3</a></li>
    </ul>
    <div id='tab-1'></div>
    <div id='tab-2'></div>
    <div id='tab-3'></div>
  </div>

  OR

  <div class='tabs'>
    <ul class='horizontal'>
      <li><a href="#tab-1">Tab 1</a></li>
      <li><a href="#tab-2">Tab 2</a></li>
      <li><a href="#tab-3">Tab 3</a></li>
    </ul>
  </div>
  <div id='tabs_container'>
    <div id='tab-1'></div>
    <div id='tab-2'></div>
    <div id='tab-3'></div>
  </div>

  */

!function($,window,undefined){"use strict";$.fn.tabslet=function(options){var defaults={mouseevent:"click",activeclass:"active",attribute:"href",animation:!1,autorotate:!1,deeplinking:!1,pauseonhover:!0,delay:2e3,active:1,container:!1,controls:{prev:".prev",next:".next"}},options=$.extend(defaults,options);return this.each(function(){function deep_link(){var t=[];elements.find("a").each(function(){t.push($(this).attr($this.opts.attribute))});var e=$.inArray(location.hash,t);return e>-1?e+1:$this.data("active")||options.active}var $this=$(this),_cache_li=[],_cache_div=[],_container=options.container?$(options.container):$this,_tabs=_container.find("> div");_tabs.each(function(){_cache_div.push($(this).css("display"))});var elements=$this.find("> ul > li"),i=options.active-1;if(!$this.data("tabslet-init")){$this.data("tabslet-init",!0),$this.opts=[],$.map(["mouseevent","activeclass","attribute","animation","autorotate","deeplinking","pauseonhover","delay","container"],function(t){$this.opts[t]=$this.data(t)||options[t]}),$this.opts.active=$this.opts.deeplinking?deep_link():$this.data("active")||options.active,_tabs.hide(),$this.opts.active&&(_tabs.eq($this.opts.active-1).show(),elements.eq($this.opts.active-1).addClass(options.activeclass));var fn=eval(function(t,e){var s=e?elements.find("a["+$this.opts.attribute+"="+e+"]").parent():$(this);s.trigger("_before"),elements.removeClass(options.activeclass),s.addClass(options.activeclass),_tabs.hide(),i=elements.index(s);var o=e||s.find("a").attr($this.opts.attribute);return $this.opts.deeplinking&&(location.hash=o),$this.opts.animation?_container.find(o).animate({opacity:"show"},"slow",function(){s.trigger("_after")}):(_container.find(o).show(),s.trigger("_after")),!1}),init=eval("elements."+$this.opts.mouseevent+"(fn)"),t,forward=function(){i=++i%elements.length,"hover"==$this.opts.mouseevent?elements.eq(i).trigger("mouseover"):elements.eq(i).click(),$this.opts.autorotate&&(clearTimeout(t),t=setTimeout(forward,$this.opts.delay),$this.mouseover(function(){$this.opts.pauseonhover&&clearTimeout(t)}))};$this.opts.autorotate&&(t=setTimeout(forward,$this.opts.delay),$this.hover(function(){$this.opts.pauseonhover&&clearTimeout(t)},function(){t=setTimeout(forward,$this.opts.delay)}),$this.opts.pauseonhover&&$this.on("mouseleave",function(){clearTimeout(t),t=setTimeout(forward,$this.opts.delay)}));var move=function(t){"forward"==t&&(i=++i%elements.length),"backward"==t&&(i=--i%elements.length),elements.eq(i).click()};$this.find(options.controls.next).click(function(){move("forward")}),$this.find(options.controls.prev).click(function(){move("backward")}),$this.on("show",function(t,e){fn(t,e)}),$this.on("next",function(){move("forward")}),$this.on("prev",function(){move("backward")}),$this.on("destroy",function(){$(this).removeData().find("> ul li").each(function(){$(this).removeClass(options.activeclass)}),_tabs.each(function(t){$(this).removeAttr("style").css("display",_cache_div[t])})})}})},$(document).ready(function(){$('[data-toggle="tabslet"]').tabslet()})}(jQuery);
<div class="tabs">
<ul class="horizontal">
 	<li><a href="#tab-1">Tab 1</a></li>
 	<li><a href="#tab-2">Tab 2</a></li>
 	<li><a href="#tab-3">Tab 3</a></li>
</ul>
<div id="tab-1">Lorem 1 ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div id="tab-2">Lorem 2 ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div id="tab-3">Lorem 3 ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
add_action( 'wp_enqueue_scripts', 'themeprefix_tab_scripts' ); 
/**
 * Script-tac-ulous -> tab scripts.
 */
function themeprefix_tab_scripts() {
	wp_enqueue_script( 'tabs' , get_template_directory_uri()  . '/js/jquery.tabslet.min.js', array( 'jquery' ), '1', true );
	wp_enqueue_script( 'tabs-init' , get_template_directory_uri()  . '/js/tabs-init.js', array( 'tabs' ), '1', true );

}