Class: Switch
Defined in: | vendor/assets/javascripts/styleguide/plugins/tbg-switch.js.coffee |
Overview
SWITCH CLASS DEFINITION
Examples:
How to ensure plugin self initialises on element
<div data-switch="true"> ... </div>
How to group switches and allow them to change state of other switches in that group
<div data-switch-group="[group name]"> ... </div>
How to toggle switch state
<div data-switch-toggle="true"> ... </div>
Instance Method Summary
- - (void) constructor(el) Constructor Construct a new Switch instance Set this.parent, this.target, this.group and this.container elements for this.el; set this.toggle if attribute present
- - (void) click() Click handler - If this.parent isn't active, close group if this.group defined and change state to true; if this.parent is active and this.toggle set then change state to false otherwise return undefined
- - (void) changeStateTo(action, elements) Change active state of target content - add or remove activeClass from content and parent elements
- - (void) _closeGroup() Private Close group - if any content is active, get the target for that element's descendant link element and pass false and elements array [activeContent, activeEl] to switch group
- - (Object) _getContent(el) Private Get target element to do switch on
Constructor Details
- (void) constructor(el)
Construct a new Switch instance
Set this.parent, this.target, this.group and this.container elements for this.el; set this.toggle if attribute present
Instance Method Details
- (void) click()
Click handler - If this.parent isn't active, close group if this.group defined and change state to true; if this.parent is active and this.toggle set then change state to false otherwise return undefined
- (void) changeStateTo(action, elements)
Change active state of target content - add or remove activeClass from content and parent elements
- (void) _closeGroup() (private)
Close group - if any content is active, get the target for that element's descendant link element and pass false and elements array [activeContent, activeEl] to switch group
- (Object) _getContent(el) (private)
Get target element to do switch on