Components

Accordion

API

Accordion

Parameters

  • element HTMLElement DOM element for component instantiation and scope

  • options Object (optional, default {})

    • options.toggleSelector String Selector for toggling element (optional, default '[data-ecl-accordion-toggle]')
    • options.iconSelector String Selector for icon element (optional, default '[data-ecl-accordion-icon]')
    • options.attachClickListener Boolean Whether or not to bind click events on toggle (optional, default true)
    • options.labelExpanded (optional, default 'data-ecl-label-expanded')
    • options.labelCollapsed (optional, default 'data-ecl-label-collapsed')

init

Initialise component.

destroy

Destroy component.

handleClickOnToggle

Parameters

autoInit

Parameters

  • root HTMLElement DOM element for component instantiation and scope

  • $1 Object (optional, default {})

    • $1.ACCORDION (optional, default {})

Returns Accordion An instance of Accordion.

Setup

There are 2 ways to initialise the component.

Automatic

Add data-ecl-auto-init="Accordion" attribute to component's markup:

<div class="ecl-accordion" data-ecl-accordion data-ecl-auto-init="Accordion">
  ...
</div>

Use the ECL library's autoInit() (ECL.autoInit()) when your page is ready or other custom event you want to hook onto.

Manual

Get target element, create an instance and invoke init().

Given you have 1 element with an attribute data-ecl-accordion on the page:

var elt = document.querySelector('[data-ecl-accordion]');
var accordion = new ECL.Accordion(elt);
accordion.init();