bulmaCollapsible
:
class
constructor
Instanciate the component based on the element provided and register the instance into .bulmaCollapsible
property of the element.
Parameters
Node element (can be a selector string - must target only one node - or a DOM node) on which attach the component
Component options. These options are merged with default options and options set via element data-attribute.
Example
const bulmaCollapsibleElement = new bulmaCollapsible ( ' #to-collapse ' );
// Access to the bulmaCollapsible instance from DOM
const collapsibleElement = document . getElementById ( ' #to-collapse ' );
if ( collapsibleElement ) {
const collapsibleInstance = collapsibleElement . bulmaCollapsible ();
}
attach
:
Array
constructor
Constructor shortcut with possibility to pass a String, a Node or a NodeList as a selector so we can instantciate multiple instances at once. Return an array of all instances. Note that each instance is link to the related DOM node under .bulmaCollapsible property.
Parameters
selector
:
String| Node| NodeList
Default: .is-collapsible
Required
Selector (can be a selector string - can target multiple nodes - or a DOM node or a DOM nodes list) on which attach the component
Component options. These options are merged with default options and options set via element data-attribute.
Example
// Return an array of bulmaCollapsible instances (empty if no DOM node found)
const bulmaCollapsibleInstances = bulmaCollapsible . attach ( ' .is-collapsible ' );
// Loop into instances
bulmaCollapsibleInstances . forEach ( bulmaCollapsibleInstance => {
// Check if current state is collapsed or not
console . log ( bulmaCollapsibleInstance . collapsed ());
});
collapsed
:
Boolean
public
Check if element is collasped or not. Return true
if element is collasped else false
.
Example
// Find DOM node from ID
const bulmaCollapsibleElement = document . getElementById ( ' to-collapse ' );
if ( bulmaCollapsibleElement ) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible ( bulmaCollapsibleElement );
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement . bulmaCollapsible ( ' collapsed ' );
}
expand
public
Open the collapsed element. If allowMultiple option is set to True then collapse all other bulmaCollapsible elements within the same parent node.
Example
// Find DOM node from ID
const bulmaCollapsibleElement = document . getElementById ( ' to-collapse ' );
if ( bulmaCollapsibleElement ) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible ( bulmaCollapsibleElement );
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement . bulmaCollapsible ( ' expand ' );
}
open
public
Shortcut to expand method
collapse
public
Collaspe the element.
Example
// Find DOM node from ID
const bulmaCollapsibleElement = document . getElementById ( ' to-collapse ' );
if ( bulmaCollapsibleElement ) {
// Instanciate bulmaCollapsible component on the node
new bulmaCollapsible ( bulmaCollapsibleElement );
// Call method directly on bulmaCollapsible instance registered on the node
bulmaCollapsibleElement . bulmaCollapsible ( ' collapse ' );
}
close
public
Shortcut to collapse method
_init
inner
Proceed to component initialization and set initial state (expand or collapse) based on the presence of the is-active
class, initialize parent node to limit multiple expanded elements (accordion-like) and will attach triggerClick listener on each trigger linked to the current collapsible element.
onTriggerClick
inner
Called on trigger click to toggle bulmaCollapsible element (expand it if collapsed, collapse it if expanded)
Parameters
DOM Event Object reference