Accordion accordion.js

Accordion extends upon the Collapse widget to associate multiple collapse items in the same container.

Widget Dependencies

Accordion requires the following:

Contents

Examples

Basic Example

A simple accordion.

Collapse Toggle #1

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.

Collapse Toggle #2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.

Collapse Toggle #3

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
<div data-cfw="accordion">
    <h4><a href="#accordion0" data-cfw="collapse" class="open">Collapse Toggle #1</a></h4>
    <div id="accordion0" class="collapse">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
    </div>
    <h4><a href="#accordion1" data-cfw="collapse">Collapse Toggle #2</a></h4>
    <div id="accordion1" class="collapse">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
    </div>
    <h4><a href="#accordion2" data-cfw="collapse">Collapse Toggle #3</a></h4>
    <div id="accordion2" class="collapse">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
    </div>
</div>

Using Cards

Here some cards are used to add a bit of layout.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
<div data-cfw="accordion">
    <div class="card mb-0">
        <div class="card-header">
            <h4 class="mb-0">
                <a href="#card0" data-cfw="collapse" class="open">Collapse Toggle #1</a>
            </h4>
        </div>
        <div id="card0" class="collapse">
            <div class="card-body">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
            </div>
        </div>
    </div>
    <div class="card mb-0">
        <div class="card-header">
            <h4 class="mb-0">
                <a href="#card1" data-cfw="collapse">Collapse Toggle #2</a>
            </h4>
        </div>
        <div id="card1" class="collapse">
            <div class="card-body">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
            </div>
        </div>
    </div>
    <div class="card mb-0">
        <div class="card-header">
            <h4 class="mb-0">
                <a href="#card2" data-cfw="collapse">Collapse Toggle #3</a>
            </h4>
        </div>
        <div id="card2" class="collapse">
            <div class="card-body">
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean non nisi ipsum. Quisque feugiat, arcu in pulvinar varius; risus odio interdum diam; a hendrerit urna sem vitae enim. Aenean fermentum iaculis nibh sodales consectetur.
            </div>
        </div>
    </div>
</div>

Usage

To set up an accordion, all collapse items to be associated must be contained within the same ancestor element that is designated the accordion conatiner.

Via Data Attributes

Add data-cfw="accordion" to the ancestor element that contains all the collapse items to be associated.

Via JavaScript

Call the accordion via JavaScript:

$('#myAccordion').CFW_Accordion();

Methods

.CFW_Accordion()

Activates the element as an accordion listener.

.CFW_Accordion('dispose')

Removes the accordion listener and data from the element. Falls back to non-associated, or individual, collapse controls.

Events

Event callbacks happen on the accordion element.

You can also get the collapse events as indicated in the Collapse widget due to event bubbling.

Event Type Description
init.cfw.accordion This event fires after the accordion item is initialized.