Boost JS Collapse
A style-free and accessible collapse plugin for jQuery and Boost JS. While other plugins style everything for you, this plugin only handles the functionality, leaving the layout and styling up to you.
Installation
Install with npm:
npm install boost-js-collapse
Install in browser:
Usage
Create Plugin
var boost = ;// var boost = $.fn.boost; (browser install) var collapse = ;// var collapse = $.fn.boost.collapse; (browser install) $fncollapse = ;
Markup Structure
Handle 1 Drawer 1 Handle 2 Drawer 2
Note: data-bind
is used to link the element to the instance, data-role
is used to define the element's role in that instance. See Boost JS for more details.
Instantiate Plugin
;
Options
Name | Default | Description |
---|---|---|
accordian | false |
when true, will only open one drawer at a time |
activeClass | "is-open" |
the class added to handle and drawer when active |
onOpen | null |
a callback function called when any drawer opens |
onClose | null |
a callback function called when any drawer closes |
onInit | null |
a callback function called when plugin is intialized |
Usage
;
- or -
...
API
openDrawer( 'drawerID', callback )
Open a drawer by providing the desired panel's id. Optional callback
function called after opening. If drawer is already open, callback will not be run.
instance;
closeDrawer( 'drawerID', callback )
Close a drawer by providing the desired drawer's id. Optional callback
function called after closing. If drawer is already closed, callback will not be run.
instance;
toggleDrawer( 'drawerID', callback )
Will toggle a given drawer open or close. Optional callback
function called whether opened or closed.
instance;
drawerIsOpen( 'drawerID', callback )
Determine whether a given drawer is open or not.
instance; // true or false
activeDrawers
The ids of the currently active drawers in an array
instance.activeDrawers // [ drawer1, drawer2 ... ]
pairsByDrawer
Each handle and corresponding drawer grouped into a jquery object and organized by drawer id.
instance.pairsByDrawer // { drawer1: $( 0:handle1, 1:drawer1 ), ... }
Running Tests
$ npm install && npm test
License
Copyright © 2016, Mark McCann. Released under the MIT license.