Tiggles ツ
1/31/2018 - 10:31 PM

Long accordion fix

when user puts too much content in accordions, and scroll issues happen.

$(document).ready(function() {

/* ==========================================================================
close the accordions by default
========================================================================== */


  $(function() {
    $( ".sw-accordion" ).accordion({
      header: "h3",
      active: false,
      autoHeight: false,
      collapsible: true,
      heightStyle: "content",
      alwaysOpen: false
    });
    $('.accordion-expand-all').click(function(e){
      $('.ui-accordion-header.ui-state-active').next().slideDown();
      e.preventDefault(); 
    });
  
    function clearActiveClasses() {
      if ($(".ui-state-active").size() >= 1) {
        clearInterval(activeInterval);
        $("h3").removeClass("ui-state-active");
      }
    }
  
    var activeInterval = setInterval(clearActiveClasses, 100);
  
  });
  
  $('.sw-accordion .tabbedcontent-header').click(function(){
      var target = $(this);
      setTimeout(function() { 
      $('html, body').animate({
            scrollTop: $(target).offset().top - 150
        }, 500);
    }, 500);
  });

}); //end doc ready