var accordion = '.js-accordion'
var header = '.js-header'
var activeClass = 'is-active'

var init = function (showFirst) {
  // If not supported, exit out
  if (!document.querySelector || !document.querySelectorAll || !document.body.classList) {
    return
  }

  var i
  var el = document.querySelector(accordion)
  var headers = document.querySelectorAll(header)
  var itemCount = headers.length

  // Add active class to first elements or if there is only one panel
  if (showFirst || itemCount === 1) {
    el.children[0].classList.add(activeClass)
    el.children[1].classList.add(activeClass)
  }

  // Add click listener to headers
  for (i = 0; i < headers.length; i++) {
    headers[i].addEventListener('click', function (e) {
      open(this, el)
    })
  }
}

var open = function (el, context) {
  var i
  var children = context.children

  // Remove active classes in accordion
  for (i = 0; i < children.length; i++) {
    children[i].classList.remove(activeClass)
  }

  // Add active classes for clicked element and the next div
  el.classList.add(activeClass)
  el.nextElementSibling.classList.add(activeClass)
}

module.exports = {
  init: init
}

@@ -800,24 +800,374 @@
 text) %7B%0A
+  // Check to see if clicked header is already active%0A  if (el.classList.contains(activeClass)) %7B%0A    close(el, context)%0A  %7D else %7B%0A    close(el, context)%0A%0A    // Add active classes for clicked element and the next div%0A    el.classList.add(activeClass)%0A    el.nextElementSibling.classList.add(activeClass)%0A  %7D%0A%7D%0A%0Avar close = function (el, context) %7B%0A
   var i%0A
   var ch
@@ -1154,24 +1154,24 @@
 ) %7B%0A  var i%0A
-
   var childr
@@ -1325,156 +1325,11 @@
 ss)%0A
+
   %7D
-%0A%0A  // Add active classes for clicked element and the next div%0A  el.classList.add(activeClass)%0A  el.nextElementSibling.classList.add(activeClass)
 %0A%7D%0A%0A

add support to close already opened accordion