Toggle

Toggle

new Toggle(optionsopt)

Source:
Properties:
Name Type Attributes Default Description
options.toggle Boolean <optional>
true

If true, the button is toggled on click.

options.press Integer <optional>
0

Controls press behavior. If options.toggle is false and this option is 0, the toggle button will toggle until released. If options.toggle is true and this option is a positive integer, it is interpreted as a milliseconds timeout. When pressing a button longer than this timeout, it will be toggled until released, otherwise it will be toggled permanently.

options.delay Integer <optional>
0

Delay all actions for n milliseconds. While actions are delayed, the widget has class .aux-delayed. Use to force users to press the button for a certain amount of time before it actually gets toggled.

options.icon_active String | Boolean <optional>
false

An optional icon which is only displayed when the button toggle state is true. Please note that this option only works if icon is also set.

options.label_active String | Boolean <optional>
false

An optional label which is only displayed when the button toggle state is true. Please note that this option only works if label is also set.

A toggle button. The toggle button can either be pressed (which means that it will switch its state as long as it is pressed) or toggled permanently. Its behavior is controlled by the two options press and toggle.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options.

Extends

Members

element :HTMLDivElement

Source:
Inherited From:

The main DIV element. Has class .aux-button.

Type:
  • HTMLDivElement

icon :Icon

Source:
Inherited From:

The Icon widget.

Type:

label :Label

Source:
Inherited From:

The Label of the button.

Type:

Methods

addChild(child)

Source:
Inherited From:
See:

Registers a widget as a child widget. This method is used to build up the widget tree. It does not modify the DOM tree.

Parameters:
Name Type Description
child Widget

The child to add.

Fires:
  • Widget#event:child_added

addChildren(a)

Source:
Inherited From:

Registers an array of widgets as children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

allChildren()

Source:
Inherited From:

Returns an array of all children.

appendChild(child)

Source:
Inherited From:

Appends child.element to the widget element and registers child as a child widget.

Parameters:
Name Type Description
child Widget

The child widget to append.

appendChildren(children)

Source:
Inherited From:

Calls Widget#appendChild for an array of widgets.

Parameters:
Name Type Description
children Array.<Widget>

The child widgets to append.

destroy()

Source:
Inherited From:

Dispose of this Widget.

destroyAndRemove()

Source:
Inherited From:

Dispose of this Widget and remove it from the DOM.

disableTansitions()

Source:
Inherited From:

Disable CSS transitions.

enableDraw()

Source:
Inherited From:

Schedules this widget for drawing.

Fires:

enableDrawChildren()

Source:
Inherited From:

Enables rendering for all children of this widget.

enableTransitions()

Source:
Inherited From:

Enable CSS transitions.

forceHide()

Source:
Inherited From:

Hide the widget immediately by applying the class aux-hide. Does not call disableDraw().

forceShow()

Source:
Inherited From:

Show the widget immediately by applying the class aux-show. Does not call enableDraw().

getStyle()

Source:
Inherited From:

Returns the computed style of this widget's DOM element.

hidden()

Source:
Inherited From:

Returns the current hidden status.

hide()

Source:
Inherited From:

Hide the widget. This will result in the class aux-hide being applied to this widget in the next rendering step.

invalidate(key)

Source:
Inherited From:

Invalidates an option and triggers a redraw() call.

Parameters:
Name Type Description
key string

invalidateAll()

Source:
Inherited From:

Invalidates all dependencies which will trigger all renderers to rerun.

observeResize(cb)

Source:
Inherited From:

Calls a callback whenever the widget resizes. This method will trigger one resize.

Parameters:
Name Type Description
cb function

removeChild(child)

Source:
Inherited From:

Removes a child widget. Note that this method only modifies the widget tree and does not change the DOM.

Parameters:
Name Type Description
child Widget

The child to remove.

Fires:
  • Widget#event:child_removed

removeChildren(a)

Source:
Inherited From:

Removes an array of children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

set(key, value)

Source:
Inherited From:

Sets an option.

Parameters:
Name Type Description
key string

The option name.

value

The option value.

setStyle()

Source:
Inherited From:

Sets a CSS style property in this widget's DOM element.

show()

Source:
Inherited From:

Make the widget visible. This will apply the class aux-show during the next rendering step.

toggle()

Source:

Toggle the button state.

Fires:
  • Toggle#event:toggled

toggleHidden()

Source:
Inherited From:

Toggle the hidden status. This is equivalent to calling hide() or show(), depending on the current hidden status of this widget.

transitionsDisabled()

Source:
Inherited From:

Returns true if transitions are currently disabled on this widget.

visibleChildren()

Source:
Inherited From:

Returns an array of all visible children.

Events

clicked

Source:
Inherited From:

Is fired if a delay is set, after the pointer is released and the timeout hasn't finished yet. Doesn't fire after the timeout finished.

Parameters:
Name Type Description
event Event

Either the MouseEvent or the TouchEvent.

destroy

Source:
Inherited From:

Is fired when a widget is destroyed.

doubleclick

Source:
Inherited From:

Is fired after a double click appeared. Set dblclick to 0 to disable click event handling.

Parameters:
Name Type Description
event string

The browsers MouseEvent.

GenericDOMEvents

Source:
Inherited From:

Generic DOM events. Please refer to W3Schools for further details.

hide

Source:
Inherited From:

The hide event is emitted when a widget is hidden and is not rendered anymore. This happens both with browser visibility changes and also internally when using layout widgets such as Pager.

initialized

Source:
Inherited From:

Is fired when a widget is initialized.

press_cancel

Source:
Inherited From:

Is fired after press_start or press_delay and before a press_end was fired while the pointer is dragged outside of the button element.

Parameters:
Name Type Description
event Event

Either the MouseEvent or the TouchEvent.

press_delayed

Source:
Inherited From:

Is fired after either a mousedown or a touchstart happened but delay is set so firing press_start will be delayed.

press_end

Source:
Inherited From:

Is fired after either a mouseup or a touchend happened and the pointer didn't leave the button element after press_start or press_delayed was fired.

Parameters:
Name Type Description
event Event

Either the MouseEvent or the TouchEvent.

press_start

Source:
Inherited From:

Is fired after either a mousedown or a touchstart happened and delay is set to 0. If a delay is set, press_delayed is fired instead on mousedown/touchstart and this event gets fired as soon as the delay time is over.

Parameters:
Name Type Description
event Event

Either the MouseEvent or the TouchEvent.

pressed

Source:
Inherited From:

Is fired if delay is set and the timeout has finished.

Parameters:
Name Type Description
event Event

Either the MouseEvent or the TouchEvent.

resize

Source:
Inherited From:

The resize event is emitted whenever a widget is being resized. This event can be used to e.g. measure its new size. Note that some widgets do internal adjustments after the resize event. If that is relevant, the Widget#resized event can be used instead.

resized

Source:
Inherited From:

The resized event is emitted after each rendering frame, which was triggered by a resize event.

set

Source:
Inherited From:

The set event is emitted when an option was set using the Widget#set method. The arguments are the option name and its new value.

Note that this happens both for user interaction and programmatical option changes.

show

Source:
Inherited From:

The show event is emitted when a widget is shown and is being rendered. This is the counterpart to Widget#hide.

visibility

Source:
Inherited From:

Is fired when the visibility state changes. The first argument is the visibility state, which is either true or false.