Jarvus UI JS (beta)

Accessible, designless JavaScript UI components.

Requires jQuery.

Toggle

Toggles a state class and the proper ARIA roles on a toggle container element with a toggle control and toggle body child elements.

Note: Works well in conjunction with JUI collapse and press-downs CSS objects.

juiToggle();

Use the destroy function to remove all aria roles and unbind events.

juiToggleDestroy();

Settings

Accepts an object of settings for:

container:
Selector string of the toggle container element. Defaults to '.js-toggle'.
control:
Selector string of the toggle control element. Defaults to '.js-toggle__control'.
body:
Selector string of the element to be toggled. Defaults to '.js-toggle__body'.
activeClass:
Class name applied to toggle element when the collapse is not collapsed. Defaults to 'is-active'.
closeOutside:
Boolean value to close the toggle when clicking outside the toggle. Defaults to false.
closeEsc:
Boolean value to close the toggle when clicking the esc key. Defaults to false.
namespace:
Namespace string added to toggle events. Defaults to 'toggle'. Useful managing the events that get added to $(document) when using closeOustside and closeEscape.

Example

HTML

<div class="o-collapse js-toggle">
    <button type="button" class="js-toggle__control">Toggle Content</button>
    <div class="o-collapse__body js-toggle__body">
        <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
    </div>
</div>

JS

juiToggle();

CSS

.o-collapse__body {
    display: none;
}

.is-open > .o-collapse__body,
.no-js .o-collapse__body {
    display: block;
}

Demo

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Tabs

Toggles a state class, adds keyboard navigation, and sets the proper ARIA roles on a tab container element with tab navigation and tab panel child elements.

Requires the tab navigation anchors properly anchor-linked to tab panels.

juiTabs()

Use the destroy function to remove all aria roles and unbind events.

juiTabsDestroy();

Settings

Accepts an object of settings for:

container:
Selector string of the tabs container element. Defaults to '.js-tabs'.
nav:
Selector string of the tabs nav element. Defaults to '.js-tabs__nav'.
panel:
Selector string of tabs panel elements. Defaults to '.js-tabs__panel'.
activeClass:
Class name applied to active tabs nav child and tabs panel. Defaults to 'is-active'.

Example

HTML

<div class="o-tabs js-tabs">
    <ul class="o-tabs__nav js-tabs__nav">
        <li><a href="#tab-1">Tab 1</a></li>
        <li><a href="#tab-2">Tab 2</a></li>
        <li><a href="#tab-3">Tab 3</a></li>
    </ul>
    <div id="tab-1" class="o-tabs__panel js-tabs__panel">
        <p>1. Pellentesque habitant morbi tristique senectus et <a href="#">netus et malesuada</a> fames ac turpis egestas.</p>
    </div>
    <div id="tab-2" class="o-tabs__panel js-tabs__panel">
        <p>2. Pellentesque habitant morbi tristique senectus et <a href="#">netus et malesuada</a> fames ac turpis egestas.</p>
    </div>
    <div id="tab-3" class="o-tabs__panel js-tabs__panel">
        <p>3. Pellentesque habitant morbi tristique senectus et <a href="#">netus et malesuada</a> fames ac turpis egestas.</p>
    </div>
</div>

JS

juiTabs();

CSS

.o-tabs__nav {
    list-style: none;
    margin-left: 0;
}

    .o-tabs__nav > li,
    .o-tabs__nav a {
        display: inline-block;
    }

    .o-tabs__nav a {
        padding: 0.5em;
    }

    .o-tabs__nav .is-active {
        border: 1px solid #ddd;
        border-bottom: 0; 
    }

.js .o-tabs__panel {
    display: none;
}

.o-tabs__panel.is-active {
    display: block;
}

Demo

1. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

2. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

3. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.