Javascript API - Public Methods

The public methods below allow you to manipulate the accordion using external controls. There are two ways of calling a public method.

The first way is by calling the accordionSlider plugin and passing the name of the method and additional arguments:

$('#my-accordion').accordionSlider('openPanel', 3);

The first argument represents the name of the method and the second argument represents the value which will be applied. Please note that some methods don't have a second argument. For example:

$('#my-accordion').accordionSlider('nextPanel');

The second way is by getting a reference to the AccordionSlider instance and calling the method on the instance:

// get a reference to the AccordionSlider instance
var accordion = $('#my-accordion').data('accordionSlider');

console.log(accordion.getTotalPanels());

accordion.gotoPage(2);

This way of calling a public method is mandatory when you use public methods that return data: getPanelAt , getCurrentIndex , getTotalPanels , getVisiblePanels , getTotalPages andgetCurrentPage , but it can be used with all the other public methods as well.

Here is the list of available public methods:

getPanelAt(index)

Gets all the data of the panel at the specified index. Returns an object that contains all the data specified for that panel.

getCurrentIndex()

Gets the index of the current panel.

getTotalPanels()

Gets the total number of panels.

nextPanel()

Opens the next panel.

previousPanel()

Opens the previous panel.

openPanel(index)

Opens the panel at the specified index.

closePanels()

Closes all the panels.

getVisiblePanels()

Gets the number of visible panels.

getTotalPages()

Gets the number of pages.

getCurrentPage()

Gets the index of the page currently displayed.

gotoPage(index)

Scrolls to the specified page.

nextPage()

Goes to the next page.

previousPage()

Goes to the previous page.

on(eventType, callback)

Adds an event listener to the accordion. More details about the use of this method will be presented in the 'Callbacks' chapter.

off(eventType)

Removes an event listener from the accordion.

destroy()

Destroys an accordion by removing all the visual elements and functionality added by the plugin. Basically, it leaves the accordion in the state it was before the plugin was instantiated.

update()

This is called by the plugin automatically when a property is changed. You can call this manually in order to refresh the accordion after changing its HTML, like removing or adding panels.

removePanels()

Removes all the panels.

resize()

This is called by the plugin automatically, when the browser window is resized. You can also call it manually if you find it necessary to have the accordion resize itself.

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk