HexagonJS
Edit Page
Toggle
A module for creating toggles
Examples

HTML

<div id="toggle"></div>
<button id="toggle2" class="hx-btn">Toggle Button</button>

JavaScript

var toggle = new hx.Toggle("#toggle")
toggle.on('change', function(value) {
  hx.notify.info("Toggle value set to " + value)
})

new hx.Toggle("#toggle2")
Api
Prototypes
hx.ToggleextendsEventEmitter
Creates a toggle component
Constructors
hx.ToggleselectorString / HTMLElementoptionsObject
Arguments
selectorString / HTMLElement
A css selector or element to use when constructing the toggle
options
The options to use when intialising the toggle
Properties
valueBoolean
The value to initialise the toggle with.
Default: false
Events
change
The event emitted when a toggle is changed.
Methods
disabledvalueBooleanToggle
A method for setting the disabled state of a toggle.
Arguments
valueBoolean
Whether the toggle should be disabled
Returns
Toggle
This toggle
disabledBoolean
A method for getting the disabled state of a toggle.
Returns
Whether the toggle is disabled
valuevalueBooleanToggle
A method for setting the value of a toggle.
Arguments
valueBoolean
The state to give the toggle.
Returns
Toggle
This toggle
valueBoolean
A method for getting the value of a toggle.
Returns
The current state of the toggle
Functions
hx.toggleoptionsObjectSelection
Creates a new Toggle set up on a detached element, wrapped in a selection
Arguments
options
See the options object for constructing a Toggle
Returns
Selection
A selection containing an element with a Toggle initialised on it
Classes
hx-toggle
The class given to a toggle element.