API Docs for: 1.0.0
Show:

Accordion Class

An accordion can be constructed from existing markup or from strings containing HTML. Existing markup can be provided either by setting contentBox or by specifying CSS selectors. See the titles and sections attributes.

When constructing from existing markup via contentBox, use an unordered list (<ul>). Each item must contain two <div>'s. The first one is used as the section title, and the second one is used as the section content.

Animation is optional. If the anim module is not available, animation is automatically turned off.

When using a horizontal accordion:

  • The widget's container must have a height.
  • Each title must have both a width and height.
  • Each section must have a width.

IE doesn't accept zero height divs, so we use 1px height and zero opacity. IE6 doesn't always render correctly with opacity set, so if animation is turned off, we don't use opacity at all.

Constructor

Accordion

(
  • config
)

Parameters:

  • config Object

    Widget configuration

Methods

_getClip

(
  • index
)
Node protected

Parameters:

  • index Int

    the section index

Returns:

Node:

the clipping container for the section content

allSectionsClosed

() Boolean

Returns:

Boolean:

true if all sections are closed

allSectionsOpen

() Boolean

Returns:

Boolean:

true if all sections are open

appendSection

(
  • title
  • content
)

Appends the section to the accordion.

Parameters:

  • title String | Node

    the section title content

  • content String | Node

    the section content

closeAllSections

()

Close all sections, if possible.

closeSection

(
  • index
)

Close the specified section.

Parameters:

  • index Int

    the section index

findSection

(
  • any
)
Int

Parameters:

  • any String | Node

    element inside the section or title

Returns:

Int:

the index of the containing section, or -1 if not found

getSection

(
  • index
)
Node

Parameters:

  • index Int

    the section index

Returns:

Node:

the container for the section content

getSectionCount

() Int

Returns:

Int:

total number of sections

getTitle

(
  • index
)
Node

Parameters:

  • index Int

    the section index

Returns:

Node:

the container for the section title

insertSection

(
  • index
  • title
  • content
)

Inserts the section into the accordion at the specified location.

Parameters:

  • index Int

    the insertion index

  • title String | Node

    the section title content

  • content String | Node

    the section content

isSectionOpen

() Boolean

Returns:

Boolean:

true if the section is open

openAllSections

()

Open all sections, if possible.

openSection

(
  • index
)

Open the specified section.

Parameters:

  • index Int

    the section index

prependSection

(
  • title
  • content
)

Prepends the section to the accordion.

Parameters:

  • title String | Node

    the section title content

  • content String | Node

    the section content

removeSection

(
  • index
)

Removes the specified section.

Parameters:

  • index Int

    the section index

setSection

(
  • index
  • content
)

Sets the contents of the specified section.

Parameters:

  • index Int

    the section index

  • content String | Node

    the section content

setTitle

(
  • index
  • title
)

Sets the contents of the specified section title.

Parameters:

  • index Int

    the section index

  • title String | Node

    the title content

toggleSection

(
  • index
)

Show/hide the section content.

Parameters:

  • index Int

    the section index

Attributes

allowAllClosed

Boolean

Whether or not to allow all sections to be closed at the same time. If not, at least one section will always be open.

Default: false

allowMultipleOpen

Boolean

Whether or not to allow multiple sections to be open at the same time. If not, at most one section at a time will be open.

Default: false

animateDuration

Int

Duration of all animations.

Default: whatever Y.Anim default is

animateEasing

Function

Easing applied to all animations.

Default: whatever Y.Anim default is

animateInsertRemove

Boolean

Whether or not to animate insertion and removal of sections.

Default: true

animateOpenClose

Boolean

Whether or not to animate opening and closing of sections.

Default: true

animateRender

Boolean

Whether or not to animate the initial rendering of the widget.

Default: false

horizontal

Boolean

Whether or not the accordion is horizontal.

Default: false

replaceSectionContainer

Boolean

Whether or not to replace the default section container node, when the supplied title is a node. (If the supplied content is markup, it is always inserted inside the default section container.)

Default: true

replaceTitleContainer

Boolean

Whether or not to replace the default title container node, when the supplied title is a node. (If the supplied title is markup, it is always inserted inside the default title container.)

Default: true

sections

String | Array

A CSS selector for locating nodes, an array of nodes, or an array of strings containing markup. This is used to define the initial set of section contents.

titles

String | Array

A CSS selector for locating nodes, an array of nodes, or an array of strings containing markup. This is used to define the initial set of section titles.

Events

beforeClose

Fires before a section is closed.

Event Payload:

  • index Int

    the section index

beforeInsert

Fires before a section is inserted.

Event Payload:

  • index Int

    the insertion index

beforeOpen

Fires before a section is opened.

Event Payload:

  • index Int

    the section index

beforeRemove

Fires before a section is removed.

Event Payload:

  • index Int

    the section index

close

Fires after a section is closed.

Event Payload:

  • index Int

    the section index

insert

Fires after a section is inserted.

Event Payload:

  • index Int

    the insertion index

  • size Int

    the final size of the section title, after animation (if any)

open

Fires after a section is opened.

Event Payload:

  • index Int

    the section index

remove

Fires after a section is removed.

Event Payload:

  • index Int

    the section index