// Screen-width breakpoint var tc_breakpoint = 767; jQuery(document).ready(function() { "use strict"; // Switch tabs and update panels classes - Adjust container height jQuery(".vertab-container .vertab-menu .list-group a").click(function(e) { var index = jQuery(this).index(); var container = jQuery(this).parents('.vertab-container'); var accordion = container.find('.vertab-accordion'); var contents = accordion.find(".vertab-content"); e.preventDefault(); jQuery(this).addClass("active"); jQuery(this).siblings('a.active').removeClass("active"); contents.removeClass("active"); contents.eq(index).addClass("active"); container.data('current',index); //Adjust container height jQuery(this).parents('.vertab-menu').css('min-height',jQuery(container).children('.vertab-accordion').height() + 20); }); // Collapse accordion panels (except the one the user just opened) and add "active" class to the panel heading jQuery('.vertab-accordion').on('show.bs.collapse','.collapse', function() { var accordion, container, current, index; accordion = jQuery(this).parents('.vertab-accordion'); container = accordion.parents('.vertab-container'); accordion.find('.collapse.in').each(function() { jQuery(this).collapse('hide'); }); jQuery(this).siblings('.panel-heading').addClass('active'); current = accordion.find('.panel-heading.active'); index = accordion.find('.panel-heading').index(current); container.data('current',index); }); // Remove "active" class from heading when collapsing the current panel jQuery('.vertab-accordion .panel-collapse').on('hide.bs.collapse', function () { jQuery(this).siblings('.panel-heading').removeClass('active'); }); // Manage resize / rotation events jQuery( window ).on( "resize orientationchange", function( ) { resize_vertical_accordions(); }); // Scroll accordion to show the current panel jQuery(".vertab-accordion .panel-heading").click(function () { var el = this; setTimeout(function(){jQuery("html, body").animate({scrollTop: jQuery(el).offset().top - 10 }, 1000);},500); return true; }); //Initial Panels setup resize_vertical_accordions( ); }); function resize_vertical_accordions( ) { "use strict"; jQuery('.vertab-container').each(function(i, e) { var index, menu, contents; var container = jQuery(this); // Setup current tab/panel (default to first tab/panel) index = jQuery(this).data('current'); if(index === undefined) { jQuery(this).data('index',0); index = 0; } // If using a desktop-size screen, manage as tabbed panels if( jQuery( window ).width() > tc_breakpoint) { // Reset panels heights (Bootstrap's accordions sets heights to zero) jQuery(this).find('.panel-collapse.collapse').css('height','auto'); // Clean tab-navigation styles menu = jQuery(this).find('.vertab-menu .list-group a'); menu.removeClass("active"); // Clean tab-panels styles contents = jQuery(this).find(".vertab-accordion .vertab-content"); contents.removeClass("active"); // Update tab navigation and panels styles menu.eq(index).addClass('active'); contents.eq(index).addClass("active"); // Update tab navigation's height to match current tab jQuery(this).children('.vertab-menu').css('min-height',jQuery(this).children('.vertab-accordion').height() + 20); } else // If using a mobile device (phone + tablets), manage as accordion { // Close all panels jQuery(this).find('.vertab-content .panel-collapse.collapse').collapse('hide'); // Clean styles from headings jQuery(this).find('.vertab-content .panel-heading').removeClass('active'); // Wait until all panels have collapsed and mark the one the user selected as active. setTimeout(function() { jQuery(container).find('.vertab-content .panel-heading').eq(index).addClass("active"); jQuery(container).find('.vertab-content .panel-collapse.collapse').eq(index).collapse('show'); },1000); } }); }