--- layout : 'default' css : 'side' title : 'Sidebar' description : 'A sidebar is a menu hidden beside page content' type : 'UI Module' --- <%- @partial('header') %>

Initializing

Any content can be used as a sidebar by adding the class ui sidebar and initializing the menu in javascript.

Fixed Position Snafoos
Fixed position content may have issues changing it's position when a sidebar appears. There are two solutions
$('.ui.sidebar') .sidebar() ;

Usage

Showing a sidebar

A sidebar can be shown, hidden, or toggled. In the following examples sidebar is used in conjunction with ui menu to display a vertical menu as a sidebar.

$('.demo.sidebar') .sidebar('toggle') ;

Triggering show/hide with other content

For convenience calling attach events will allow you to bind events. By default this will toggle the sidebar in and out of view on click

$('.demo.sidebar') .sidebar('attach events', '.toggle.button') ; $('.toggle.button') .removeClass('disabled') ;
Trigger Sidebar

Triggering custom action with other content

You can also however specify what action should occur when the element is clicked

$('.demo.sidebar') .sidebar('attach events', '.open.button', 'show') ; $('.open.button') .removeClass('disabled') ;
Open Sidebar

Variations

Floating

A sidebar can appear floating above content

$('.demo.sidebar') .addClass('floating') .sidebar('toggle') ;

Direction

A sidebar can appear on any side of content

$('.direction.button') .on('click', function() { $('.sidebar') .filter('.' + $(this).data('direction') ) .sidebar('toggle') ; }) ; $('.direction.button') .removeClass('disabled') ;
Top
Right
Bottom

Overlay

A sidebar can overlay page content instead of pushing it to the side

$('.demo.sidebar') .sidebar('setting', 'overlay', true) .sidebar('toggle') .sidebar('setting', 'overlay', false) ;

Behavior

All the following behaviors can be called using the syntax $('.foo').sidebar('behavior name', argumentOne, argumentTwo)
attach events(selector, event) Attaches sidebar action to given selector. Default event if none specified is toggle
show Shows sidebar
hide Hides sidebar
toggle Toggles visibility of sidebar
is open Returns whether sidebar is open
is closed Returns whether sidebar is closed
push page Pushes page content to be visible alongside sidebar
get direction Returns direction of current sidebar
pull page Returns page content to original position
add body css Adds stylesheet to page head to trigger sidebar animations
remove body css Removes any inline stylesheets for sidebar animation
get transition event Returns vendor prefixed transition end event

Settings

Transition Settings
Form settings modify the transition behavior

Setting Default Description
overlay false Whether sidebar should overlay page instead of pushing page to the side
useCSS true Whether to use css animations or fallback javascript animations
duration 300 Duration of side bar animation

DOM Settings
DOM settings specify how this module should interface with the DOM

Setting Default Description
namespace sidebar Event namespace. Makes sure module teardown does not effect other events attached to an element.
className
className: { active : 'active', pushed : 'pushed', top : 'top', left : 'left', right : 'right', bottom : 'bottom' }
Class names used to attach style to state

Debug Settings
Debug settings controls debug output to the console

Setting Default Description
name Sidebar Name used in debug logs
debug True Provides standard debug output to console
performance True Provides standard debug output to console
verbose True Provides ancillary debug output to console
errors
error : { method : 'The method you called is not defined.', notFound : 'There were no elements that matched the specified selector' }